DIY: Cheap wifi-based temperature/humidity sensor based on ESP8266 & DHT22

Just finished the protoboard version of the DS18S20 temperature sensor:

Since the sensor is more compact I opted for a smaller board: its just 5x2.5 cm.

UPDATE: Making the board as small as possible seemed to be a good idea, but in fact it destroyed the accuracy of the sensor. It was too close to the ESP8266 and picking up the waste heat of it. I extended the board again and moved the sensor away from the ESP8266. I also added long supply traces that can dissipate the heat better. Now I’m happy with the accuracy, although I want to run a long-term test before final judgement.

Hi @gonium,

Thanks, I’ve ordered a couple of the wroom version as well. It does seem to be the best option.
I’ll make a test PCB in the next couple of weeks an let you know how I get on with the low power version. :smile:


I’m pretty busy these days, but I managed to record some sensor data for the long-term test of my sensors. The data looks like this:

The top (green) line shows a DS18S20-based sensor, the lower (red) line shows the DHT22 temperature measurement. The DHT22 sensor sits 80cm above my floor, the DS18S20 sensor about 3,5m - so the temperature offset between the two is expected.

BUT: The individual measurements of the DHT22 are not stable enough. I will rewrite the firmware to use a low-pass filter for the measurements, but this will have to wait until I return home.

Universal FW for esp8266 -
I use it for door sensors, power and gas counter. It support many sensors “out the box”:
LM75, INA219, DS1621, DHT 11/22, BMP 085/180, BH1750, AM2321, 1-wire DS18B20, BME280, SHT21/SI7021.
Pro version only $2, but it save a lot of time. No need to program esp, all settings in web ui.
And you can ask author to add something what you need.

For OpenHAB i use MQTT module.
You just check firmware modules and create firmware you need.
If you need many functions use esp12 with 1024k flash.

This is openhab, oled and esp12 and that firmware-

Info page in russian -

I did just that, the new code is in the github repository. The result is clearly visible in this graph:

I uploaded the new firmware around 22:00. Currently, I am averaging the last six measurements. Between measurements there is a 10s delay. I could probably tune these parameters a little in order to make the plotted line more smooth, but the DHT22 is not a very stable sensor and I prefer not to interfere with the measurements too much. For a room temperature sensor, getting the average of the last minute seems adequate: it is not changing that quickly.

Hi @martiniman,

this indeed looks interesting. My only critique is that it is not open source - I would like to have a look at the code before I integrate it in my network. Do you know whether the source code is available somewhere?


Here IRC chat (#esp8266 on, MaksMS firmware author, you can freely talk with him.
Web version:

I played around with many temperature/humidity sensors and i was unsatisfied with the DTH11 and DTH22 sensors releated to humidty (+/- 20%) values.
I’ve decided to use Sensirion modules like SHT10. More reliable than the DTH sensors but also more expensive.

This should only be an information to the quality of this sensor.

@csowada: Yes, that is sound advice. I used the HYT321 in a commercial project – it performs much better than the DHT22. But it is also way more expensive. If you need really exact values the DHT22 is the wrong sensor.

The DS18S20 allows for multiple sensor on the same wire. Have you tried this configuration?
I will build your board next month, once I get back my electronic play space. This design is really neat.

You’re lucky :wink: I implemented this in the last four commits.

The code works like this: At compile time you define how many DS18S20 you have on your bus (I tested up to four). During startup, the appropriate number of REST endpoints is created, i.e. /temperature/0 maps on the first sensor, /temperature/1 on the second and so on. During runtime the measurement routine just enumerates the devices on the bus.

I wanted to add a 304 redirect for the old /temperature endpoint to the first sensor before announcing it here, but if you keep in mind that the current master has a different semantic than described previously the functionality should already be there.


I finally had some soldering time available and created a breakout board for the ESP-WROOM-02 modules. They are meant to be soldered directly onto a PCB, but for prototyping I prefer a more modular approach. This is what I came up with:

As with my ESP-01 prototyping setup I have a development board that I can use to connect a breadboard to the ESP module. The ESP modules themselves have 50mil connectors, so I had to create a little adaptor for them. Turns out its rather easy to solder this if you stick to a sequence that reduces the heat during soldering. I thought I would share my approach. I’m soldering the final 3V3 connector in the sequence below:

(0) Hotglue the ESP-WROOM-02 upside down to a piece of perfboard and solder pinheaders on both sides. This is a closeup of the finished module:

(1) Add some solder to the pinheader.

(2) Connect the silver-plated copper wire to the pinheader just by adding some heat with the soldering iron.

(3) Then solder the wire to the ESP board. Make sure to leave the wire uncut! It acts as a heat sink, otherwise the pinheader joint heats up too fast and the wire comes loose. After everything is soldered cut off the excess wire. The result should look like this:

Leaving as much wire as possible to act as a heat sink was the key to produce these little boards :wink: My sensor code is already running on this setup, hopefully I will be able to finish a multi-sensor onewire installation tomorrow.

Quick update: my new board with three DS18S20 sensors is up and running. It is currently monitoring my heating system:

I think there is some optimization to be done :sunglasses:

The documentation of my hardware along with the new code for dealing with more than one DS18S20 is now on github. I also added the ESP-WROOM-02 to the schematic:

This is a nice little board that I will use in the future. It is basically a drop-in replacement for the ESP-1 that offers more pins. It is also slightly more compact. Maybe I will manufacture a proper PCB for this setup.


Amazing project! I’ll try it as soon as I get some spare time. Which sensor gives better accuracy? DS18S20 or DHT22? Thanks.

If you mean temperature measurements: The DS18S20 is rather exact, the DHT22 not so much :wink:

I am interested in making a similar project. I have 6 heating sones in my flat, currently I have a relay connected to openhab which is running on my rpi. This switches on this thermostat at 6 am and off at midnight. However i would rather like to make my own thermostat. So my idea is to take these sensor:

esp8266 - wifi main CPU
DHT22 temperature sensor air sensor
1 wire temperature sensor for under floor
10A relay (230V*10A=2300W)
CO2 sensor(optional)
Power supply
Light sensor(optional)

The problem is that all need to fit inside this junction box.

Would anyone do it this way? The CO2 sensor are to controll the ventilation and the light sensor to control lights.

Thanks! And how many days has the circuit been running continuously for? I mean I’d like to know how reliable is the board with your code, not talking about measures which is clear to me.

I think I deployed the first sensor a few days before writing the first post - so 10th of september would be a fair estimate. No problems so far.

Thanks, you totally deserve my star on github.

@skatun: As I mentioned above I use external wall-wart power supplies. My PCB is around 5x5cm. If you choose a compact power supply it should be possible to squeeze everything in. BUT: If you’re measuring temperature you want to ensure good ventilation of the measurement area - which I doubt is possible within this enclosure. I would recommend to put the sensors on wires and expose them directly to fresh air.