Arduino入门实践(三):人体红外感应模块

硬件:HC-SR501 人体红外感应模块,Arduinouno,杜邦线、led灯

连接:Arduino入门实践(三):人体红外感应模块

效果:有人灯亮,没人灯灭

代码:

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);
}

 

上一篇:CF1444A


下一篇:【优先队列】Function