2018年5月9日 星期三

PIR Interfacing with NodeMCU


NodeMCU
NodeMCU is an open-source IOT platform. It refers to an Lua based firmware developed for ESP8266 Wi-Fi Soc (System on chip) from Espressif Systems that help to develop IoT applications. It is an open-source development board with ESP8266-12 chips uses Lua scripting language.

PIR Interfacing with NodeMCU


Introduction

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


Supporting Files
Source Code


沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...