Arduino入门一:人体红外传感器

#define PIN_1 2
#define PIN_2 4
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(PIN_1,INPUT);
  pinMode(PIN_2,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(PIN_1)==HIGH){  
    Serial.println("Someone here!"); 
    digitalWrite(PIN_2,HIGH);
  }     
  else {  
    Serial.println("Nobody");
    digitalWrite(PIN_2,LOW);
  }  
  delay(1000);
}


无人经过时,LED灯不亮,串口监视器输出nobody

有人经过时,LED灯亮,串口监视器输出somebody here



猜你喜欢

转载自blog.csdn.net/b__t__t/article/details/79297369