What if you wanted to measure and display information from various places in your house or apartment? This blog post shows you how to attach a DHT22 temperature/humidity sensor either directly to the WeatherStation (in case you want to measure it where the WeatherStation is) or how to collect and display data from another room over WiFi.
Requirements & Preparation
For this tutorial I assume that you already have a working WeatherStation and a DHT22 breakout board ready.
|Product||Where to buy?|
|The ESP8266 WeatherStation||Amazon (US) |
Squix Shop (World wide)
|DHT22 Humidity/ Temperature Sensor||Banggood|
Attaching the DHT22 to the ESP8266 directly to the WeatherStation
|ESP8266 WeatherStation with locally attached
DHT22 sensor to measure temperature and humidity
Next you need to import the DHT22 library. This is easiest by using the library Manager:
Sketch > Include Library… > Manage Libraries…
Let’s discuss the changes:
- Line 37: I have added the DHT library
- Lines 77-83: configuration options for the DHT library. If you are using a DHT11 or DHT21 here you can change it. Also adapt the used pin. If you are not using the NodeMCU board D6 will give you a compile error
- Lines 104/105: two new variables for humidity and temperature. If this was a new WeatherStation module you would keep the variable in the new classes and not here, in a “global” scope…
- Lines 110-119: The prototypes help the compiler/linker to use functions which will only be used afterwards
- Lines 119/124: I added a new drawIndoor method and increased the number of frames to 6. Now the framework knows which method to call in order to draw the indoor information
- Lines 231-233: In this tutorial we update the temperature und humidity only once every 10 minutes. Updating the values only costs about 250ms but it might still be too much to do it in the hot (main) loop. But you could do it there every once in a while
- Lines 271-277: This draws the indoor frame. You might see a strong similarity to the drawThingspeak method. This is not coincidental since they draw similar data. In a perfect world we could extract this to an extra method to share the code
|The result of successfully following this tutorial|
Did you like this post? Consider supporting me with a virtual coffee or beer.