Handy for home automation projects, this wireless temperature sensor reports the current temperature and humidity to an MQTT broker of your liking every 5 seconds.
- 3.3V power supply
- DHT11 temperature and humidity sensor
- ESP8266 + breakout board
- A 4.7k resistor
- And of course a breadboard and some jumper leads.
- If you don't already have an FTDI cable and your Arduino IDE set up to go, check out this guide.
Make the following connections:
- GND on power supply to:
- GND on ESP8266
- GND (pin 4) on DHT11
- +3.3V on power supply to:
- CHPD on ESP8266
- VCC on ESP8266
- Pin 1 on DHT11 (leftmost)
- Connect a 4.7k resistor between pin 1 and 2 of the DHT11.
- Connect pin 2 on the DHT11 to GP2 on the ESP8266.
The following pins should remain unconnected: DHT11 pin 3, ESP8266 GP0, RXD, TXD and RST.
Programming the ESP8266
While we're not going to go into a detailed guide on how to program the ESP8266, here is a sample sketch that should get you up and running. Please note the following:
- This can get tricky so see our handy guide on how to prepare your Arduino environment for programming ESP8266 boards. If you don't have an FTDI adapter cable, we sell those too.
- You'll need the PubSubClient and SimpleDHT libraries installed to compile this sketch.
- Remember to change the YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD values in the code to match your own wireless SSID and password.
- The code uses test.mosquitto.org, a public MQTT broker, as an example. Depending on your use you probably want to install your own MQTT server and use that instead of a public one. We recommend Mosquitto as a great MQTT broker. MQTTLens is a great MQTT client for Windows.
When everything is up and running, you should see the following topics being published approximately every 5 seconds:
Where 24 is the temperature, in degrees Celsius, and 54 is the relative humidity (percentage).
The final product