ESP8266 Weather Station: Measuring Inside and Outside Temperature – Part 1

The code you get with the WeatherStation (https://github.com/squix78/esp8266-weather-station) is meant as a starting point for beginners and enthusiasts to display information. So far there are modules to get correct time from the internet as well as current and future weather conditions. Now let’s get a bit more local.
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. If you are missing a component buy it from BanggoodΒ or from my own little shop:

Attaching the DHT22 to the ESP8266 directly to the WeatherStation

To measure temperature and humidity in the room where you are running the WeatherStation you can attach the DHT22 breakout board as shown in the schema bellow
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…

And now search for the DHT library:

Now that you have the library you can start extending the demo. In order for this to work I assume that you have already done everything to get a working WeatherStation. Save your existing sketch under a new name. Here are the necessary changes:

Related:  ESP8266: Weather Station V2 Code published

 

Let’s discuss the changes:

  • Line 37: I have added the DHT library
  • Lines 74-80: 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 98/99: I added a new drawFrame6 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 106/107: 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 203-206: 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 279-286: This draws the indoor frame. You might see a strong similarity to the drawFrame5 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
That’s it! Apply these changes to your code, compile it and flash your ESP8266 with the changes after you set up the wiring.
The result of successfully following this tutorial
Part two of this tutorial will show you how to read the information from another ESP8266 through the cloud…
Now a beer! Did you like this post? It often takes me several hours of my free time to write one. If I was your neighbour would you offer me a beer for the hard work I did for you? The beauty is: beers can be teletransported with a painless donation using Paypal. A beer in a Swiss bar costs about USD $4.80. Or use this affiliate link if you order something on Banggood and I'll get a small kickback. Thank you!
Related:  ESP8266: Internet connected baby nightlight for less than $10