【DFRobot Bluno试用体验】光敏电阻控制LED
准备工具:电脑;DFRobot Bluno开发板;面包板;光敏电阻;10K电阻;USB线一根;杜邦线
若干
光敏电阻部分原理图:
硬件连接图(在这我用了云智易开发板上的光敏电阻模块):
程序代码:
// the setup routine runs once when you press reset: void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); if(sensorValue>250){ digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) }else{ digitalWrite(13, LOW); // turn the LED off by making the voltage LOW } }下载效果:
有光照:
无光照: