Motion sensor alarm system
What you will learn here about motion sensor alarm system
- Motion sensor alarm system
The motion sensor alarm system turns ON buzzer ( as an alarm) on movement detection and turns buzzer OFF when movement is not detected. Here we will see how to implement the motion sensor alarm system with esp8266.
Hardware requirements:
- PIR sensor
- ESP8266
- USB to power ESP8266
- Buzzer
- Resistor (Limit sound of buzzer)
- Connecting wires
Motion sensor alarm system
Simple motion sensor alarmĀ system using ESP8266 is shown below
Hardware connection
- Connect VCC pin of PIR to 3.3v or Vin of ESP8266
- Connect the output of PIR to GPIO14 i.e D5 of ESp8266
- Connect GND of PIR to GND of ESP8266
- Connect GPIO13 i.e D7 to one end of resistor
- Connect another end of resistor to Positive terminal of Buzzer
- Connect GND of ESP8266 to GND of the Buzzer
ESP8266 Code
Please upload the following code in ESP8266.
int value = 0; int past=0; void setup() { // Motion sensor is connected to D5 pin of ESP8266 pinMode(14,INPUT); //COnfigured as input //Buzzer is connected to D7 pin of ESP8266 pinMode(13,OUTPUT); //Configured as ouput Serial.begin(115200); Serial.println("please connect sensor to D5 pin of ESP8266"); Serial.println("please connect D7 pin of ESP8266 to resistor"); } void loop() { value=digitalRead(02); //reads movement data from pir sensor if(value==1 && past==0) { Serial.println("present"); digitalWrite(13,HIGH); //Turn on buzzer } if(value==0 && past==1) { Serial.println("Absent"); digitalWrite(13,LOW); //Turn off buzzer } past=value; }