ESP8266 NodeMCU Multiple PIR Sensors?

Also just tried MySensors platform - that’s really great platform. For me the most advantages are possibility of using external interrupts to wake the sensor up. That means with binary sensors (up to 2) your device can sleep all the time, with minimal power consumption.
The only disadvantage is to have 1 extra radio module for communication. Unfortunately I didn’t find Arduinos with NRF24/RFM69 modules builtin on AliExpress. I’m aware of openhadware.io and Monteinos, but they’re a bit pricey

Buying one of the designed boards on the MySensors website would get rid of any problems connecting the radio to the microcontroller. However, I just use some ordinary board and connect it all with wires. Its not difficult the fourth time.

Yes, I also connect generic Arduino mini with sensors with wires. It’s just like not so convenient: with NodeMCU/Wemos you have MCU and radio on one tiny board for ~$4, while arduino with built in radio costs ~$14. 2 boards (arduino mini + nrf24) costs ~$3…

My mains powered sensors use Wemos or NodeMCU, but for battery power these won’t last long enough so I use MySensors, with a ATMega328p rather than an arduino. Basically this design, but without using the pcb.

Hi all, how are you guys mounting your PIR sensors? Do you put it in an enclosure? Is it wall mounted? I’m using USB powered D1 mini with PIR sensor and I am now looking for a cheap and easy way to make it more presentable.

I’ve seen posts on 3D printing your own custom case but I am hoping there’s something more readily available.

Thanks.

There was another thread about PIR enclosures recently. Search Aliexpress for ‘plastic electronics enclosures’ and you will find alot of good options.

1 Like

For my powered units, I use a box as Dwalt suggested, and they sit on shelves. For my battery powered sensors I was inspired by the MySensors project in my previous link, and used some 40x16 electrical trunking I had around. The effect is reasonably unobtrusive.

1 Like

Hi experts,

Any luck setting the PIR sensors with ESP and HASS ? I am facing some elementary issues about automation in Home Assistant along with the reliable operation of the PIR sensors.

How did you guys configure the component in Home Assistant for the motion sensor ? I am bit confused about the setup as I see there are at least 3 possibilities are there (MQTT sensor, binary_sensor or switch). Let me explain a bit about my setup first.

My ESP is connected to 3 sensors (Lux, DHT and PIR) which are sending MQTT message and then decoded by Home Assistant. As I picked the MQTT message, the format is like below:

/esp1/livingroom/Lux x.x
/esp1/livingroom/Temperature x.x
/esp1/livingroom/Humidity x.x
/esp1/livingroom/Motion 1 or 0

As you figured out, the output from the motion sensor is not different from the others so I first configured a regular sensor and hoped to retrieve the value 1 or 0. But to my surprise, I found the sensor value in HA is actually True or False rather 1 or 0. And I tried to use those ‘True’ and ‘False’ value to do some automation later. It didn’t work!!
Then I changed the component as a MQTT switch which gave me the similar result as MQTT sensor. Finally I tried with binary_sensor which shows the value as ‘on’ or ‘off’ Still the automation didn’t work.

First please suggest which component would be better suited for this purpose. In fact, my original goal is to trigger a light based on the motion trigger. So the Automation was like this …

- alias: Turn on kitchen light when there is movement
  trigger:
    platform: state
    entity_id: sensor.livingroom_motion
    state: 'True'
  action:
    service: light.turn_on
    entity_id: light.kitchen_spotlight

- alias: Turn off kitchen light 10 minutes after last movement
  trigger:
    platform: state
    entity_id: sensor.livingroom_motion
    state: 'False'
    for:
      minutes: 10
  action:
    service: light.turn_off
    entity_id: light.kitchen_spotlight

Apart from the above setup I also used few conditions to check if we are home, time is after sunset etc.

Another concern is about the reliable operation of the motion sensor. I found the particular model HC-SR501 is difficult to work as I am not sure about the settings(Jumper settings, Delay and sensitivity tuning) which should give best results . Can anyone suggest a recommended settings ?

By the way, for the sake of completeness, here is my binary_sensor config below:

binary_sensor:
  - platform: mqtt
    state_topic: /esp1/livingroom/Motion
    name: "Livingroom Motion"
    qos: 0
    payload_on: "1"
    payload_off: "0"

And here is the config of Switch (of the same component )…

switch:
  - platform: mqtt
    name: "Livingroom Motion"
    state_topic: "/esp1/livingroom/Motion"
    payload_on: "1"
    payload_off: "0"

The sensor has two states (motion, no motion) so the logical sensor type is a binary_sensor.

I think the state of binary sensors is always ‘on’ or ‘off’’

I use this page to remember which setting is which. I have the jumper from the auto-reset to the middle pin, which turns sets the pin high when motion is detected, and then low some time after no motion is detected. The time is determined by the ‘delay’ pot. I usually set this to maximum, which gives about 9 minutes for the blue ones I have, but only 2 minutes for some green ones (that are generally inferior all around).

I usually leave the sensitivity in the middle setting, but I don’t have very big rooms.

Thanks a lot man for your thoughtful answer.

Actually now my Home Assitant setup works fine(with either sensor or binary_sensor component), the culprit was the PIR sensor. After spending quite long hours, I found that both sensors are not working simultaneously, I changed GPIO pins, PIR sensors, changed jumper, played with the sensitivity and delay… Almost everything humanly possible. End result! My ESP chip is dead now :frowning:

So, I quite with ESP and now focusing on my spare pi Zero. Right now creating a script that will utilize Paho MQTT and send the triggers the way I want. So far, its promising… Everything is going as planned so far. Once done, will share the final outcome.

From tinkering with both ESP and Pi, my possible findings are as below:

Vin pin of NodeMCU never reaches 5v (in my case it was 4.3v after connecting 2 PIRs, 1 Lux and 1 DHT sensor and a big Capacitor in parallel to reduce voltage drop) whereas pi zero 5v pin provides accurate 5v.
Playing and configuring ESPEasy on ESP is damn easy and the quickest way to start. But python code with pi is a slow and comparetively difficult to setup with but result is much satisfactory. On top of that, there is a real pleasure of doing something very own :slight_smile:

However, I will give my other ESP another shot when I would have my mini PIR sensors in hand suggested by Ben (@brusc) in his video. He indeed warned about HC-SR501 sensor with ESP but I had to believe that in the hard way.

Thanks

I’ve played with the HC-SR501 sensor and what I’ve found is they are very susceptible to varying voltages and will give lots of false positives if the voltage is not rock steady, I power them seperately from one of my nodemcu 3.3v power pins with my other sensors using one of the other 3.3v pins and that works very well. I found that any other sensors on the same power output causes the HC-SR501 sensor to basically repeatedly trigger every few seconds, but once on a separate power pin they work perfectly.

I have found that the 433MHz receiver that I use with the NodeMCU does interfere with the PIR, giving false triggers, if it is too close to it physically. Currently the PIR has to sit outside the case, until I have the time to put it together again in a better layout.

Another problem I have had is one that was pointing West would not signal no motion in the afternoon, when the sun was pointing in through the window. So I had to reposition the sensor.

Other than they are all working fine now.

But I have never tried all the sensors you have at once on one NodeMCU. I do intend adding a light sensor to both of them, so I will look out for making sure the Vin is ok. How are you powering the NodeMCU?

I don’t understand this. I thought the HC-501 needed at least 4.5V?

Supposedly yes it only works at 4.5v but mine all work fine at 3.3v. I have 1 HC-501 on a separate 3.3v power pin and I have a switch, Pressure/Temp/Humidity sensor, RGB LED, a relay and a Smoke sensor attached on another 3.3v power pin on the NodeMCU, all working fine :slight_smile:

hello, could you please show me how to physically connect different sensors to the same nodemcu? for example I would like to connect to a nodemcu placed in a box two pir sensors, a dht22 and a gas sensor. it’s possible?

Just attach the various pins to the different GPIO pins and voltages you need. Which PIR and gas sensor?

gas sensor: MQ2 and MQ9

PIR: https://www.aliexpress.com/item/Free-Shipping-HC-SR501-Adjust-Infrared-IR-Pyroelectric-Infrared-PIR-module-Motion-Sensor-Detector-Module-We/32713378646.html?spm=a2g0s.9042311.0.0.5e2e4c4dahwHai

in practice I would like to place the nodemcu in a point and then connect the various sensors with wires passing through the channels to the various rooms

I apologize but I’m very inexperienced