The HTU21D on an ESP8266-01, with MQTT and graphics

Limited as the ESP8266-01 might seem regarding the number of pins, it is still a very capable little device that is sometimes wrongfully underrated.

It is perfect however for projects that demand little I/O, such as reading a single sensor.

I am using the HTU21D temperature and humidity sensor. The ESP01 needs constructing a small board that contains the connectors and a small 1117-33 voltage regulator (soldered on the bottom) so the circuit can be fed with 5 Volt. As I am using an ESP8266-01S -that already has 10k pullups on GPIO0 and GPIO2, I do not have to add resistors for an undisturbed startup and use of I2C. If you are using the ‘old’  ESP8266-01, you have to add 4k7 -10k pullups to GPIO0 and GPIO2. If your HTU21 module already contains pullups, those will function as proper startup resistors as well.

The software (download here) is not too complicated, it first connects to your LAN, but it chooses the strongest of two LANs if available.

It then connects to an MQTT server and sends the sensor readings via MQTT every minute.

I also find it convenient when the software tells me what program it is, so I have added that too.

Finally, as in future I may want to include some time dependent signaling, I included a clock that is being synchronized through the internet.

Should you check your DHCP list, the device identifies as “HTU21”

MQTT Output:

Update
If you like a graphical presentation of your data, I have made another file that will exactly do that. It is based on code by Rui and Sara Santos from (randomnerdtutorials) that I discussed in an earlier  post. It will work with a 512k/32k SPIFFS setting as well as with a 1M/64k setting.
Beware though that many ESP8266-01 (and especially the ESP8266-01S) modules now come with a PUYA memory chip that has been causing some issues when using SPIFFS. The userdata.h file contains 2 defines that need to be set or commented out depending on whether you have or do not have the PUYA chip (2 defines to cover different cores). If you are still on the 2.4.1 core, you will need a patch. That you will have to put here: C:/Users/your.name/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.4.1/cores/esp8266.

6 thoughts on “The HTU21D on an ESP8266-01, with MQTT and graphics”

  1. I love utilising the ESP8266-01 boards for small projects that only need one or two GPIOs.
    I have even stopped making my own regulator boards as there are shields available so cheaply now that these plug straight into that have VCC, GND TX and RX pins and it’s pretty easy to solder onto the other 2 GPIOs as needed.
    You are right that this is a capable board. It is still an ESP8266 afterall.

    1. Very true, the only boards I came across are the ones that already have a sensor attached, usually the dht11. These usually only have gpio0 exposed. If you have a link to a more versatile one I’d be happy to see that. Oh wait, maybe you mean those shields that are meant to use the esp01 as wifishield for an arduino, or do you have another in mind?
      In this case it was a bit of a deliberation, soending a few euros and wIt a few weeks, or put it all together in an afternoon with stuff I had.
      The esp01 is truly a versatile SoC, I am currently testing one that is filled to the brink with code: reading a hoist of sensors (7xds18b20, a bh1750, various other i2c sensors, switching a motor) and publishing results via mqtt, putting it on a webpage and storing it in Google sheet, just to see if it can.

      1. Yes, those are the ones I was referring to. 🙂 I have some projects that use GPIO1, GPIO2 and GPIO3 because I am using the ESP8266-01 standalone and not needing the serial uart and the work really well while leaving GPIO 0 free so as to not interfere with the boot process. As the boards already have pull up resistors and the chip enable already linked, it just makes it so easy to use these little boards in so many projects. I have even got a couple running as controllers for LED Strips running E131 / xLights and they don’t lag at all, even at 40fps.

      2. I dont think I ever used the UART, other than for testing. If you use tx and rx as regular i/o, it is best to tell them that with pinMode FUNCTION_3 and remove all references to Serial.print.
        Gpio0 is in fact perfect for sensors that require a pull up. Not so much to trigger relays that require a pull down. That in fact is the problem with one of the ubiquitous esp01 relay boards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.