NodeMCU based MQTT multi-sensor with OLED display

sensor
mqtt
dht22
Tags: #<Tag:0x00007fd3142af7f8> #<Tag:0x00007fd3142af5c8> #<Tag:0x00007fd3142af460>

(B K) #1

Earlier this year, I published a project I was working on, a general purpose NodeMCU breakout board (Multi-purpose NodeMCU breakout PCB). I designed this board to securely carry a NodeMCU board, a 4-channel level shifter, a DHT22 sensor, and breakout headers for every pin on the NodeMCU, on a self-contained PCB.

Since then, I’ve been using these boards as remote temperature/humidity sensors all over my house, as well as LED controllers for kitchen under-cabinet lighting.


Remote temperature sensor boards (MQTT)


WS2812 Remote LED controller (MQTT)

The sensors allow me to chart temperatures throughout the house, and adjust heating/cooling registers in each room to try to equalize the system.

Needless to say, raw PCBs were not exactly well received by the missus, and I also wanted to have local temperature display, so after spending some time over the last week or so, I created this:

The enclosure is designed in Fusion360, printed on my Prusa i3. I added an OLED screen to locally show temperature and humidity, while the NodeMCU carrier board/temp sensor is fully enclosed behind it. Sensor is read once a minute, and sent to the local screen and my MQTT topic in openHAB.

My topic in openHAB is set up like this:

Number Temperature_Ensuite "Ensuite Temp [%.1f F]" <temperature> (SF_Ensuite,Temp_Chart_2) {mqtt="<[broker:home/Ensuite/temperature:state:default]"}
Number Humidity_Ensuite "Ensuite Hum [%.1f %%]" <humidity> (SF_Ensuite,Hum_Chart) {mqtt="<[broker:home/Ensuite/humidity:state:default]"}

I can then use the items in a sitemap, or view the chart with the tracked temp/humidity.

For anyone interested in making their own, I’ve published the design on Thingiverse, and published my version of the NodeMCU ESP8266 code on Github.

I’ve also created how-to videos on my YT channel:

I continue working on the design, making different iterations of the enclosure, e.g.:

  • (DONE) WS2812 LED controller (smaller, no OLED screen/DHT, with JST connector)
  • (DONE) PIR motion sensor
  • Differential Pressure sensor (for HVAC system flow monitoring)
  • Sound sensor (for presence detection)
  • Air quality sensor
  • …?

I am also working to clean up the code, added things like OTA update, and a web-based remote config utility.

Hopefully, someone else finds this as useful as I have!


How to build a WS2812B LED strip with ESP8266 NodeMCU?
Nodemcu project box?
Controll Panel esp8266
Who here builds their own sensors (CHAT)
(Tony Jobson) #2

Very nice. Be careful of burn in on the OLED screens with static or infrequently changing chars. To protect it I use the invert function of the library to invert white on the black to black on white for text every X minutes.


(B K) #3

Thank you! That is a great suggestion. I was also thinking that for the model with a PIR sensor (haven’t decided whether it’ll be built-in or external), I could turn the display on only when motion is detected and automatically turn off after a period of time.


(B K) #4

Small update - modified the 3d model to:
-add some louvers for the DHT sensor (to improve airflow/sensing)
-add an opening for an external sensor connector.

https://www.thingiverse.com/thing:2539897

Also, modified the Eagle CAD for the PCB board to:
-use same board for both NodeMCU 0.9/1.0 (v2/v3?) boards
-add EXT “servo” style connector (Signal/3.3V/Gnd) for use with external motion/etc sensors

https://www.pcbway.com/project/shareproject/NodeMCU_DHT_Sensor_LED_Controller_Breakout_Board_v_1_1.html


(B K) #5

Quick update - I’ve received/tested the new version of my board, and it appears to work well! Link to the newest rev (including some better annotations as I’ve learned to work with Eagle)

I still need to make a minor change to the enclosure model, as the NodeMCU v2’s RESET/FLASH buttons are closer to the edge of the board, so I need to remove the interference on the internal wall of the enclosure, near the USB connector hole.

I also tested the EXT connector, to connect an external Motion sensor. Works like a charm! When I get a chance, I want to design an enclosure for the HC-SR504 motion sensor I’m using, so I can mount it on the wall near the main sensor, but adjust its angle, as required.


(B K) #6

Another update to the OSHPark board - this one is mostly cosmetic (prettied up the soldermask around the board, and filled in the ground plane). Looks great, I think!

I’ve also started working on a lower profile enclosure, for the board/NodeMCU only (no DHT sensor and no OLED), which I’m planning to use to enclose my MQTT LED strip controllers around the house (and for Christmas lights). I’ll post that design/STL to Thingiverse once I get a chance to test the model.


(B K) #7

Based on some other projects I’ve been working on, i made another small update to the PCB board, this time to add a jumper, which allows sending either 3.3V or 5V out to the EXT sensor connector.

I’ve also made a new revision of the 3d printed enclosure, low-profile, removing the DHT sensor and OLED cutout, to be used as an enclosure for only the NodeMCU and PCB board. https://www.thingiverse.com/thing:2690563 I specifically use this version as an LED strip controller, for under-cabinet lighting in my kitchen, and also as a Christmas lights display. All of my controllers (each window/door) are synchronized using a single MQTT topic to which I post the FX/brightness/color/speed settings.


(B K) #8

Found a much cheaper supplier for the PCB boards (PCBWay, at < $1 per board). Placed an order to try them out - we’ll see how long delivery takes and whether the boards work/look as well as the ones from OSHPark. In the meantime, if anyone wants to order from them, here’s the link to the preloaded Gerbers I put there: https://goo.gl/U2fY7y


(Lucky) #9

Still expensive. Just for ‘logging’ your temp, I’d suggest a single esp8266-01, dht22, and a pullup resistor. Total should be less than $5 for the entire thing.


(B K) #10

Expensive? Not really, you can get a NodeMCU for $3/piece these days, not much more than a bare ESP8266-01, and it handles the power and USB/serial conversion for you, as well as breaking out all the pins of the ESP. That, and it looks a heck of a lot better put together than a ESP-01 with wires/sensors thrown in a corner.

If you forego the OLED (which really is a nice addition to be able to quickly see the local temp/humidity), and print my LED controller enclosure option (https://www.thingiverse.com/thing:2690563 - smaller, no OLED cutout), the BOM/price list looks like:

Box - ~$1 worth of plastic
PCB - $1
NodeMCU - $3 (no headers,direct solder to the breakout)
DHT22 - $3 (no pullup needed, I’ve found)

= ~$8 / pop for remote logging, +$4 for local OLED display…


(Lucky) #11

well, you’re not comparing apples to apples. Functional bare setup vs functional bare setup, a single esp8266-01 will do the logging you are looking for. That was my point. Of course, adding all the stuff you wanted will increase the price. A NodeMCU uses the same ESP8266 chip. I drive my wifi alarm pin pad with a single esp8266-01, complete with a 20x4 display, a pn532, 2 buttons, and a buzzer. Yeah, i ‘dev’ on a dev board. I prefer the wemos d1. I use a dev board when ‘developing.’ Final products are not on dev boards. Again, SAME chips. If you want to cut down cost, purchase the bare chip, and deploy your products not on a chip soldered on a dev board :wink:

Since you like breaking costs down:
ESP8266-01 - $1.50
DHT22 - $2.30
10K resistor - 100pcs for 50cents, basically free.
Total - $3.80

half the price of your setup to do the same thing. Which means for the total cost for you, I could do it in twice the number of rooms. But I guess, I must apologize. The term ‘expensive’ is so subjective. So, let me rephrase ‘expensive’ to “I can suggest a less expensive route.” But then again, it’s your project :wink: Nice job though. Which CAD software do you use? If you graduated here in the US, get AutoDesk Inventor (free for students, well, not really, you just need a .edu email. Easily worth $2000), so again, another savings :slight_smile:


(B K) #12

Haha, no need to apologize, cost is definitely an important consideration, especially for us DIY’ers who do everything on a tight hobby budget :slight_smile: The dev board solution was a bit more versatile and “turnkey” for me (I also use these for 5V PIR sensors and LED strips, so the integrated power circuitry is worth the extra few bucks to me). Also, I’d still have to design a board to hold the ESP-01, at least to convert 5V to 3.3V the ESP/DHT require and box it all up to meet the WAF (Wife Approval Factor) in my house :wink:

I’ve gone through several 3d modelling tools, (Sketchup, Inventor, even openSCAD <- ugh), but finally settled on Fusion 360. It’s free for makers and students, and is just as powerful as Inventor for my use cases. Better yet, since Autodesk took over Eagle, they’ve added some great integration, like the ability to automatically generate a 3D model of the PCB you’re designing in Eagle and import it as a component into your Fusion 360 models (allowing me to easily ensure my board fit into the enclosure before printing).

Anyway, thanks for the input and hope you have a great New Year!


(B K) #13

P.S. I’m interested in your wifi alarm pin board design, especially the button setup, as I’d like to possibly incorporate some local control into my LED strips. Do you have a schematic or write up posted anywhere?


(Lucky) #14

which button are you looking for? The alarm pinpad I havedoes not have a literal keypad (sorry for the confusion). User input uses only 2 buttons and a pn532. A pn532 is an nfc card reader. Basically the two buttons do 1 thing: they send a command to my openhab via the REST api to an item to run a rule. The rule then sends a command to my alarmdecoder module through the alarm decoder binding. So button 1 sends Arm Away, button 2 sends Arm Stay. Output to user is an audible tone (beep) using a piezo buzzer from an old PC (im cheap lol) and a 20x4 lcd, which shows the actual text as if you’re in front of the main alarm keypad.

To disarm the alarm (Vista 20p) i simply tap an nfc, which then again updates an item in openhab to disarm the system. The authorization is in the esp8266 itself, based on the ID of the tapped NFC card, combined with a shared secret for some type of security. The shared secret is actually an algorithm to simulate rolling code so attackers cant just replay the transmission.

like this:
nfc tapped -> esp8266 uses the nfc card id to generate the hash. The hash generation is the algorithmic security both my openhab instance and the esp8266 share. So every nfc tap generates a unique code.

nfc tap -> esp8266 creates hash-> validated by openhab->openhab sends command to alarmdecoder binding->sends to my Vista20p

I usually don’t offer advises for home security since that’s somewhat a very critical/sensitive topic, but it seems you have done quite a create deal in automation already. The Vista20p has a Rs232 interface if you don’t wanna buy an alarmdecoder hardware. I interfaced with it successfully but I bought the alarmdecoder hardware anyway for peace of mind since it’s one of the most mature hardware interfaces for the vista 20p panels.


(Kees Van Gelder) #15

coz of your post I checked out PCBWay and they are certainly interesting.
their price structure sometimes a bit odd as I was quoted 20 USD for 20 copies of a specific print, while 15 copies was 5 USD. Nevertheless still cheaper than OSH. I think I will give them a try


(B K) #16

I noticed that too, but there’s nice scaling in pricing when you order larger quantities. I ordered 30 for $30, but I could have gotten 50 for I think like $40.

Anyway, ordered on 12/25, and I just got an email this morning that the boards have already shipped, so production is quick, all that remains now is to wait for that 2-3 week delivery time :wink:


(Kees Van Gelder) #17

Correct. I think in the past I did some comparison of various site and generally for a small number of small sized PCB’s OSH is the cheapes, but as soon as you want more than 3 PCBś and of bigger size OSH is getting more expensive than PCBWay or DirtyPCB’s


(B K) #18

Just to close the loop - PCBWay boards delivered today (1/18), so 24 days from order to delivery (not bad, considering OSH isn’t that much quicker and is more expensive)…


(scott dee) #19

I’m doing something similar with nodemcus and d1 minis all running espeasy. The temp reporters are run from a 18650 that goes about a month between charges reporting every 3 minutes. Each vent/register has an esp with a l293d actuating the motor of a vent miser (ebay). Then i have an esp hooked up to the furnace. I can interrupt the blower speed and choose whatever speed and either stage heating via an 8 channel relay. The d1 minis run under cabinet lighting and one has a lux sensor on it to determine on/off.

As I’m not much for coding all my 8266s run espeasy which allowed my to focus on my rules and the actual automation.


(Kees Van Gelder) #20

both the NodeMCU as well as the Wemos D1 mini have some GPIO pins with a pull-up. Those are perfect for a DHT22, but even a spare resistor would only add pennies