PIR Interfacing with NodeMCU
Introduction
PIR Sensor
PIR sensor is used for detecting infrared heat radiations. This makes them useful in the detection of moving living objects that emit infrared heat radiations.
The output (in terms of voltage) of PIR sensor is high when it senses motion; whereas it is low when there is no motion (stationary object or no object).
PIR sensors are used in many applications like for room light control using human detection, human motion detection for security purpose at home, etc.
For more information on PIR sensor and how to use it, refer the topic PIR Sensor in the sensors and modules section.
Interfacing Diagram
PIR Interface with NodeMCU
Example
Let’s interface PIR sensor with NodeMCU. When motion is detected, PIR output goes HIGH which will be read by NodeMCU. So, we will turn on LED when motion is detected by PIR sensor. LED is connected to D4 pin.
Here we are writing Arduino Sketch as well as Lua script for NodeMCU. To know more about NodeMCU development using Arduino sketch or Lua script refer Getting started with NodeMCU using Arduino IDE and Getting started with NodeMCU using ESPlorer IDE
Lua Script for PIR
PIRpin = 1
LEDpin = 4
gpio.mode(PIRpin, gpio.INPUT)
gpio.mode(LEDpin, gpio.OUTPUT)
while true do
gpio.write(LEDpin, gpio.read(PIRpin))
tmr.delay(10000)
end
Arduino Sketch for PIR
int LED = D4;
intPIR_Input = D1;
void setup(){
pinMode(PIR_Input,INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
digitalWrite(LED, digitalRead(PIR_Input));
delay(10);
}
No comments:
Post a Comment