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


沒有留言:

張貼留言

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站 (ESP32 + DHT22 + 1602 LCD)

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站(溫度 濕度) (ESP32 + DHT22 + 1602 LCD) 想學物聯網(IoT)與 ESP32 電子實作,卻擔心接線與電壓規範搞砸嗎?透過強大的線上模擬器 Wokwi ,我們不需要花費任何硬體費用,打開瀏覽器...