NodeMCU based MQTT multi-sensor with OLED display

Have you tired to block your 3.3V with additional caps to get it more stable? Also add a cap at the analog in. I think your signal is anywys changing slow.
In addition you can implement a SW filter, sample several times and use a running average, this helps also to get stable A/D values.



Holger - all very good ideas! I did try the caps, but didn’t get to doing a software filter yet…Alll that said, the real problem I have is with resolution. The sensor I have has a range from -8…8 in/h2o, and all I’m really concerned with is the 0…0.5 range. In a 10-bit resolution, that works out to something like 0.09 in/h2o per bit, so not very good for monitoring the system (and even more prone to voltage fluctuations changing the reading). I figure with a dedicated 12 bit ADC, with a full 0-5V range, I can get that down to ~0.02 error.

If your analog range is only 0.5V, then it would be the best to put a OP-Amp in the row with a analog amplification of x10. Then you reach the full A/D Range and get better resolution.

Interesting solution as well, but I’d still be amplifying the noise of the NodeMCU 5V power supply, wouldn’t I? Also, I’m trying to stay within the current enclosure, if I can. I think with an external ADC board like this one, I can still tuck it inside the box (and if it works, I can likely just add the few ADC components onto my existing NodeMCU carrier board). Bonus of having 4 16-bit analog inputs vs 1 10-bit and an onboard PGA (so I can focus the measurement range to the 0-0.5Vdc, per your suggestion). Thanks!

He Bartus,
These are really great device to hook op to OpenHAB. Like them a lot so far. It helped me a lot to understand and to work better with Openhab.
I only have a little thing that I would like to change but don’t know exactly where to do what.
The thing is that the sensor sometimes send a -1.00. Probably because of the DHT (it seems to be a little slow sometimes) or maybe a bad WiFi signal or whatever. The value -1.00 gets to the broker and OpenHAB shows it. The software does what it has to do, but the value -1.00 gives a weird chart display.
I guess that this little problem can be solved at both sides! Make a rule in Openhab or something so a -1.00 value is false or… Or change the sketch for the ESP8266 a little so that the value -1.00 will never be send.
What would be the best solution in your opinion if I may ask?
Any way, thanks for developing this great device.

Thank you - I’m glad my project is helping you learn openHAB (making it helped me, as well!).

The code will set an output value of -1 when either the temperature or humidity readings become invalid. The only time I’ve seen that was when I was using either a breadboard (testing), or using a proto-board setup, with the DHT22 sensor inserted into pin headers. I’m pretty sure it’s due to an intermittent connection issue. With all of the sensors I’ve put on my PCB I’ve never had any issues. I don’t think it’s your Wifi signal either, because then you’ll just get a non-changing value (openHAB item/MQTT topic will not get an update).

You could disable the logic in the Arduino IDE (just comment out the line that sets the sensor value to “-1” when the value is not a valid number). Then, the value you get over MQTT will just remain steady (stale) until the connection to the sensor is reestablished. That’s much easier to do than handling it in openHAB (though you could do it with a JS transform, I guess).Clearly the best solution is to make sure your sensor connection is solid (those Dupont connectors/headers don’t always work well).

Enjoy your adventure with openHAB!

Excited to say I’ve got the Kube working with ESPEasy this weekend! I uploaded the firmware, and after getting familiar with the interface/config options, it was really easy (imagine that!) to get it working almost exactly like it works with my dedicated software (even better in many ways!!).

Here’s a sample:

The best part is, all of the sensors I’ve wanted to add (and most of the ones I’ve had requests for) are already supported by ESPEasy (e.g. ADS1115, TSL2561, BMP280, etc…) so I can now focus on the hardware interface and not worry about keeping my dedicated project up to date…Moving forward, I’ll “sunset” the Github project, keeping only a Readme for conversion to ESPEasy and some sample config files. I’ll work on an update video for the changes, one of which requires moving the OLED SCL/SDA I2C pins from D9/D10 over to D3/D4 (my mistake in the first place to use the serial channel pins).

1 Like

Hey Bartus,

I am having some trouble with flashing the Arduino I am getting the following error message.

Arduino: 1.8.6 (Mac OS X), Board: “NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

NodeMCU-Home-Automation-Sensor_edit:48:26: error: PubSubClient.h: No such file or directory
#include <PubSubClient.h>
compilation terminated.
exit status 1
PubSubClient.h: No such file or directory

Let me know if you have any idea what I may be doing wrong.

@tinkernut - do you have the PubSubClient library installed in Arduino?

Also - see my post above - I’m switching the project over to ESPEasy. It makes the setup much easier, and allows the use of more sensors than what I was able to support with my code.

Thanks Bartus,

I managed to get Espeasy up and running but need the exact settings you used for the Lines/GPIO Pins. Can you send me screen shots of your set up since I bought one of your devices off Tindie? Thanks for your help. Looking forward to getting this operational.

@tinkernut - Sure thing (and thanks! :slight_smile: ) - but, since I sent that box to you before I made the switch to ESPEasy, and because I used D9/D10 as the OLED I2C pins, you’ll have to go through a few more steps to disable the serial port so that the OLED works.

First, open up the “Tools” tab and click on “Advanced Settings”. Scroll down to “Enable Serial Port” and UNCHECK that box, then hit “Submit”. This will open up the GPIO pins used by the serial port, and enable them for the OLED I2C data.

Next, open the “Hardware” tab, and under the “I2C Interface” select “GPIO 3 (D9)” for the “GPIO<->SDA” setting and “GPIO 1 (D10)” for the “GPIO<-> SCL” setting. Again, hit Submit, but also reset the device (power cycle it) so the settings take effect.

After you reset, go to “Tools” again, and click on “I2C Scan”. Now, you should see something like this:

If you don’t see any devices, stop and get in touch with me via PM…If you do, you’re ready to start setting up the OLED/DHT sensors.

Click on Devices, and edit a new task. For the DHT sensor, your entries should look like this:

(The formulas on the bottom do conversion, but also allow you to put in offsets, like the ones I talk about in my Configuration/Calibration video).

After that, add an “OLED Framed” device, and make the settings look like below:

That’s pretty much it - let me know if that works, or if you run across any other issues. We’ll get this thing up and running!

Thank you so much for all your advice! I was able to get it up and running now!

1 Like

Hi @bartus I got everything up and running hab-panel! I am using the sensor in my Cigar Humidor I would like to create a rule to alert me when the humidity goes below a certain percentage via text message.
Here are the values I am thinking:
If the temperature goes over 75 degrees and the Humidity drops below 62% humidity.

Do you know what the Rule would look like? Thanks for your help.

@tinkernut - I think you best option would be to use the Mail action (, because I don’t really see a way to send SMS messages easily (though, I guess you could send a message to your phone number @ your provider if they allow that).

I see you already have the sensor sending via MQTT (i.e. you have Temperature and Humidity items you update and display on your Habpanel) so the rule would be very simple:

rule "Send Email"
    Temperature > 75 or Humidity < 62
    sendMail("", "Alarm", "Humidor Alarm.")

Of course, you’ll need to make sure your Mail action is configured correctly (smtp server, user/password settings in the services/mail.cfg configuration file.

Thanks I will give that a try and let you know how it goes.

Dear Sir,

I am working on the same project. Could you please help me in the sitemaps and binding files as well.
I need that.

@Neelam_Rani - the only binding you should need for this is the MQTT binding (I still use version 1).

For the sitemap, you only need to add the Number item to your sitemap - the easiest is to add it using a Text element:

Text item=Temperature_Kitchen
Text item=Humidity_Kitchen

All your formatting is taken care of at the Item level, so it should display just the way you want it this way…

Hi BK,

Thank you for your help.I had done that. Its showing the right Temp and Hum values. But I am facing the problem in graphs.Can you please help in to the sitemaps and bindings file for the graphs?

Thanks and Regards

Its showing the empty graphs.Don’t know where i am doing mistake.

Make sure you’re using the correct persistence service (I’ve been using rrd4j, which can store a series of values over time) and not something like mapDB persistence (which can only save a single point - the last value).

Also, make sure you add the chart group to your Temp/Humidity item definitions, so they’re actually tied to the Chart element.