Skip to content

pezinek/pir_sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

WiFi PIR Sensor/Luxmeter for ESP8266

This is firmware for simple wireless PIR sensor and luxmeter controlled over MQTT. It uses the Homie MQTT convention and is based on Homie implementation for ESP8266 by Marvin Roger, benefiting from all the features this library provides, like: captive web portal for initial configuration, OTA updates over MQTT, WiFi reconfiguration over MQTT etc.

Parts

  • Wemos D1 Mini
  • PIR module HC-SR501 (actually this module triggers randomly when WiFI is on, I'm actually planning to replace it with AM312 )
  • Photocell GL5528
  • 15K Resistor (or whatever other you like)

... or something similar :-)

Wiring

  • photocell goes to A0
  • PIR sensor goes to D5

wiring

Setup

Import this code into platformio, then run build target "PlatformIO: Upload SPIFFS Image".

Adjust the photocell type, and resistor value in the code in src/main.cpp to match whatever you have. (You may need to follow the instructions for the Arduino Light Dependent Resistor Library if your photocell is not supported by the library directly)

Then you could compile and upload the sketch to your board as usual.

Once you upload the sketch, you have to configure the node as described in Homie Getting Started Tutorial (this is where you device gets device id assigned)

Interface

  • The device will report the status from PIR sensor to MQTT topic homie/<deviceid>/pir/motion
$ mosquitto_sub -h 192.168.1.50 -v -t "homie/a020a61590a1/pir/motion"
homie/a020a61590a1/pir/motion NO
homie/a020a61590a1/pir/motion YES
homie/a020a61590a1/pir/motion NO
  • The device will report light intensity (in lx) from photocell to MQTT topic homie/<deviceid>/photocell/lux
$ mosquitto_sub -h 192.168.1.50 -v -t "homie/a020a61590a1/photocell/lux"
homie/a020a61590a1/photocell/lux 118.61

to adjust the interval how often is the light intensity reported publish the new value to "homie//photocell/interval/set" (in seconds)

$ mosquitto_pub -h 192.168.1.50 -t "homie/a020a61590a1/photocell/interval/set" -m "5"
  • similarly you could control the built-in LED by publishing to following topics
homie/<deviceid>/led/brightness/set <0..1023>
homie/<deviceid>/led/status/set  <ON|OFF>

About

PIR Sensor for ESP8266

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages