Making a Cheap WiFi Thermometer With ESP-01S and AHT21B

by topdng in Circuits > Electronics

76 Views, 1 Favorites, 0 Comments

Making a Cheap WiFi Thermometer With ESP-01S and AHT21B

Screenshot 2024-11-29 at 5.47.59 PM.png

This is a DIY IoT Temperature Sensor which connects directly to your home Wi-Fi and sends data to Home Assistant via MQTT. I made this because I needed a cheap WiFi thermometer and I didn't like the options available on the market.


YouTube video here: https://www.youtube.com/watch?v=1Bsn6xnnoIs

Supplies

ESP-01S - https://amzn.to/3Zgj9Bx

FTDI USB to UART 3.3V Cable - https://amzn.to/4i9SkYh

Jumper Wires/Hookup Wires - https://amzn.to/4idGWdP

AHT21 Temperature (and Humidity) Sensor - https://amzn.to/4ibdwNs

5v to 3.3v Regulator - https://amzn.to/4fS2J9u

USB Power Cable - https://amzn.to/4eSvIsC

Preparing the IDE for Programming

To program the module you will need to install the Arduino IDE on your machine, and add the ESP8266 library.


In the Settings menu, make sure you add the following link to the "Additional boards manager URLs:" field

http://arduino.esp8266.com/stable/package_esp8266com_index.json


Then, in the boards manager type "esp8266" and install the package.


After that, activate the Generic ESP8266 Module in the Board menu under the esp8266 sub-menu.


Now you should see new Example sketches in the File menu.


From the Tools menu, select the right serial port under Port for your FTDI UART cable.


You will also need to install this Library: https://github.com/enjoyneering/AHTxx


You can download the code as a Zip file and then Import this as a Library into Arduino under Sketch > Include Library > Add .ZIP Library...

Wiring It All Up

Untitled-2.png
Untitled-1.png

Connect everything together as shown. When you want to program the device, you need to jump IO0 to GND (shown in the white wire) before powering on the ESP. When you want to run the application you just programmed, you remove this jumper and then start the ESP by applying power.

Programming the Code

Screenshot 2024-11-29 at 5.37.03 PM.png

The Arduino code is attached below. You will need to update all of the credentials, and also make sure you have an MQTT server running on your home assistant.


If you want to use the deep-sleep mode between measurement updates to enable battery-powered operation, you need to solder the shown pin to RST GPIO on the ESP-01S board. With a 5 minute measurement update interval, the average power consumption is around 5mW which should last a long time on an 18650 battery (around 3 months). If you want longer battery life, just increase the interval.