WeMos (b7) PIR (Passive infrared sensor)

PIR (Passive infrared sensor)は、以前RPiで利用したが、WeMosにも試す。

動きがあったら、とりあえずLED 点灯する。

#define ESP8266_LED BUILTIN_LED
int pirPin = D7;
int val;

void setup() 
{
  Serial.begin(9600);
  pinMode(ESP8266_LED, OUTPUT);
  digitalWrite(ESP8266_LED, HIGH);
}
void loop() 
{
  val = digitalRead(pirPin);
  Serial.print(val);
  //low = no motion, high = motion
  if (val == LOW)
  {
    digitalWrite(ESP8266_LED, HIGH);
    Serial.println(" No motion");
  }
  else
  {
    digitalWrite(ESP8266_LED, LOW);
    Serial.println(" Motion detected  ALARM");
  }
 
  delay(1000);  
}

結線図

参考:

  • http://www.esp8266learning.com/wemos-mini-pir-sensor-example.php

Leave a Reply

Your email address will not be published. Required fields are marked *