# 光敏模組

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbiZkxAlfN_2PH6u%2Flinkit7697_light_00.jpg?generation=1568715211088451\&alt=media)

## LinkIt 7697 專案說明

使用「LinkIt 7697 NANO Breakout」連接「光敏模組」， 每0.5秒讀取光敏模組數值。

此**光敏模組**包含於「[**洞洞么教學材料包**](https://www.robotkingdom.com.tw/product/rk-education-kit-001/) 」內。

### LinkIt 7697 電路圖

* [LinkIt 7697](https://www.robotkingdom.com.tw/product/linkit-7697/)
* LinkIt 7697 NANO Breakout
* 光敏模組

**光敏模組**是**類比訊號**輸入， 可以接「A0 \~ A3」的 LinkIt 7697 NANO Breakout訊號端上，「A0 \~ A3」腳位在程式碼中以「14 \~ 17」表示。 本範例連接到「**A0**」，程式碼中為「**14**」。

![光感測器](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-MQjSa6f3HaVpLoPGwQ-%2F-MQpONlfMORrky3Fh_jV%2Fimage.png?alt=media\&token=f17b6eed-b393-4b3b-abb2-4ee9b896f3d6)

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbidyEHwTlc6t76U%2Flinkit7697_light_01.png?generation=1568715214978609\&alt=media)

### BlocklyDuino 積木畫布

每0.5秒鐘會讀取光敏模組一次， 並顯示在序列埠監控視窗上。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbigCWG7kfJBaahB%2Flinkit7697_light_02.png?generation=1568715215482507\&alt=media)

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-LoyhZ7TGT0i8ZxuGcbY%2F-LoyhbiiLsmspWeGUayq%2Flinkit7697_light_03.png?generation=1568715212642090\&alt=media)

### Arduino 程式

```c
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println(analogRead(14));
  delay(500);
}
```

## micro:bit 專案說明

使用「micro:bit搭配科易KEYES micro:bit 感測器擴充板 V2」連接「光敏模組」，讀取光敏模組的數值變化 。

此**光敏模組**包含於「[**洞洞么教學材料包**](https://www.robotkingdom.com.tw/product/rk-education-kit-001/) 」內。

### micro:bit電路圖

* [BBC micro:bit 微控制板  ](https://www.robotkingdom.com.tw/product/bbc-microbit-1/)
* [科易KEYES micro:bit 感測器擴充板 V2  ](https://www.robotkingdom.com.tw/product/keyes-microbit-sensor-breakout-v2/)
* 光敏模組

**光敏模組**是**類比訊號**輸入，可以接「0、1、2、3、4、10」的 micro:bit訊號端上，建議使用的是0、1、2腳位，因為3、4、10腳位有使用到LED控制腳位所以當顯示LED時會不穩定。本範例連接到「P0」。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-M-NE68ymTBMS7mq9bJq%2F-M-NEse1Oq0gtc3dH3_s%2F01.jpg?alt=media\&token=9f13934e-93a7-4748-a8be-27dbc496c71c)

### Microsoft MakeCode積木畫布

每1秒鐘會讀光敏模組的電位一次，並可透過micro:bit顯示指示燈看到光敏模組的電位數值。

![](https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LaZQFBYOS3O0ksiEmR1%2F-M-NE68ymTBMS7mq9bJq%2F-M-NEytk2yTNEYCF1Qno%2F02.jpg?alt=media\&token=00bd033c-5fd4-458a-a214-75f1a902d1ca)

### JavaScript 程式

```javascript
basic.forever(function () {
    basic.showNumber(pins.analogReadPin(AnalogPin.P0))
    basic.pause(1000)
})
```

## Raspberry Pi Pico 專案說明

使用「Raspberry Pi Pico」連接「光敏模組」, 讀取按鈕模組按下或放開的狀態。此**光敏模組**包含於「[洞洞么教學材料包](https://robotkingdom.com.tw/product/rk-education-kit-001/)」內。

### 光敏模組電路圖

* [Raspberry Pi Pico](https://robotkingdom.com.tw/product/raspberry-pi-pico/)[  ](https://www.robotkingdom.com.tw/product/bbc-microbit-1/)
* [Raspberry Pi Pico擴充板](https://robotkingdom.com.tw/product/pipico-education-kit-001/)[  ](https://www.robotkingdom.com.tw/product/keyes-microbit-sensor-breakout-v2/)
* 光敏模組

> **光敏模組**是**類比訊號**輸入， 可以接「A0\~ A2」的Raspberry Pi Pico擴充板訊號端上。 本範例連接到「A0」。

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2F1vV4JZoBLCH02uhKDvsh%2Fimage.png?alt=media&#x26;token=4f025e18-77e6-489a-8679-75252b03afb3" alt=""><figcaption></figcaption></figure>

### Arduino IDE程式

> 每0.5秒鐘會讀取光敏模組一次， 並顯示在序列埠監控視窗上。

Arduino 程式(Photoresistor.ino)如下:

```arduino
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println(analogRead(A0));
  delay(500);
}
```

&#x20;

### **程式執行結果**

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FGuZLT7DluLzBxssWWAwV%2Fimage.png?alt=media&#x26;token=338c74f9-413f-4e35-927f-3a3ed38e8508" alt=""><figcaption></figcaption></figure>
