硬件:HC-SR501 人体红外感应模块,Arduinouno,杜邦线、led灯
连接:
效果:有人灯亮,没人灯灭
代码:
int PRI_sensor = 8; int LED = 13;void setup() { pinMode(PRI_sensor,INPUT); pinMode(LED,OUTPUT); Serial.begin(9600); } void loop() { if(digitalRead(PRI_sensor) == HIGH) { Serial.println("someone here!"); digitalWrite(LED,HIGH); } else { Serial.println("Nobody!"); digitalWrite(LED,LOW); } delay(1000); }