|
1、实验材料:
ESPDUINO模块,光敏电阻模块,杜邦线3根;
2,实验原理:
光敏电阻感光时信号脚输出低电平,通过读取与信号脚相连接的IO口的电平值判断是否接收到光线,从而控制灯的亮灭把结果显示出来。
3,硬件连接:
vcc接3.3v电源,GND接地, DO脚接ESPDUINO板上的IO脚4;
4,例程源码:
- #include<Ticker.h>
- Ticker timer;
- #define pho 4
- #define LED 16
- int val=1;
- void tick_Photoresistance_control()
- {
- val=digitalRead(pho);
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(LED, OUTPUT);
- pinMode(pho, INPUT);
- digitalWrite(LED, HIGH);
- timer.attach(0.1, tick_Photoresistance_control);
- }
- void loop()
- {
- if(val==0)
- {
- digitalWrite(LED, LOW);
- Serial.print("Photoresistance: ");
- Serial.println(val);
- }
- else
- {
- digitalWrite(LED, HIGH);
- Serial.print("Photoresistance: ");
- Serial.println(val);
- }
- delay(100);
- }
复制代码 5,实物连接与实验效果图:
|
-
11.jpg
(107.64 KB, 下载次数: 1782)
-
22.jpg
(60.25 KB, 下载次数: 2143)
|