arduino人体感应灯(继电器模块和数字传感器)
所需材料:arduino控制板、继电器模块、人体热释电模块、杜邦线若干
int PIRpin=2;int RELAYpin=3;void setup(){Serial.begin(9600);pinMode(PIRpin,INPUT);pinMode(RELAYpin,OUTPUT);}void loop(){while(!digitalRead(PIRpin)){}Serial.println("turn on");digitalWrite(RELAYpin,HIGH);delay(10000);digitalWrite(RELAYpin,LOW);Serial.println("turn off");}
程序上传完成后,打开串口显示器,若感应到人,会显示turn on,10s后显示turn off。也可在继电器上连接小灯泡,通过小灯泡亮暗来显示。