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 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中

  一個典型的 IoT(物聯網)與工業自動化系統整合(SCADA/機台連線) 的架構圖。它透過 Node-RED 作為核心資料網關,將前端 ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中。 1. 各模組功能拆解...