In a previous paper I explored the Internet of Things (IOT), using a NodeMCU ESP8266 microcontroller board equipped with a single temperature sensing device. Data started flowing in and made this project so rewarding that a more ambitious project was considered almost immediately: building a complete weather station around this microcontroller platform. The station should monitor several sensors and, at regular intervals, transmit data to a server on the Internet to make it possible to access any time with my smartphone actual and logged information about the environmental conditions around my home. Local storage of logged data should be possible. The design should be flexible and expandable. These conditions are visually presented in the diagram of figure 1.
Figure 1. Components of the weather station; information flow. Sensors are indicated in orange.
Typically a weather station keeps track of temperature, atmospheric pressure, relative humidity, precipitation and wind direction/speed. The basic functions that I am interested in for the time being (living in a city) are temperature inside and outside the home, atmospheric pressure, and relative humidity inside the home. Sensors that detect temperature and relative humidity should preferably be positioned outside the protecting box that contains the NodeMCU and the supplemental board on which the NodeMCU is mounted. As the NodeMCU ESP8266 is compatible with the Arduino one can select suitable sensors from the arsenal of sensors on the marketplace available to serve Arduino purposes.
Outside temperature: Dallas DS18B20 sensor. The DS18B20 is a versatile device based on one-wire technology. One big advantage of these sensors is that they can be mounted far away from the microprocessor board, up to at least 20 meters. This feature is vital since the NodeMCU board has to stay within Wifi range of my router. While the latter is installed close to the front door, on the sunny side of my home, outside temperature measurements are most realistic and stable, and bst accessible on the shady side, first floor of my home. This practical geographic constraint requires a long wire between the outside temperature sensor and the NodeMCU.
The DS18B20 has an accuray of 0.5oC. It is a small device (fig. 2; bare sensor). To protect the sensor from moist, rain and dirt it is mounted inside a protective copper tube. This assembly is further called the ‘outside temperature probe’.
Barometer: BMP280. A useful, economical and accurate air pressure sensor is the BMP280 (fig.3). This sensor measures both atmospheric pressure and temperature. Note that the BMP280 is accurate and fast enough to use it as an altimeter. The accuracy of the temperature readings is in the same order of magnitude as that of the DS18B20. Arduino compatible BMP280 breakout boards for the Arduino are typically I2C-serviced devices. I2C communication is fast and reliable but requires a short distance between the sensor and the microcontroller board. As the BMP280 is therefore ‘obligatory’ mounted close to the microprocessor and inside the protecting box there might be a slightly higher temperature reported by the device due to accumulated heat dissipated by the electronics inside the box.
Temperature inside the box: BMP280. It follows from the above that the BMP280 is the only sensor that is mounted inside the protective box. For that matter I am using he BMP280 temperature readings as an indication for ‘box inside temperature’.
Figure 3. The I2C BMP280 breakout board used in this project.
The mounting of the BMP280 inside the protecting box has a consequence, notably that there must be perforations or openings in the box to allow unhampered equalization of atmospheric pressure inside and outside of the box. The I2C protocol requires the connection between sensor and microcontroller to consist of four wires: power (3.3V), GND, SCL and SDA. On an Arduino SCL is connected to pin A4 while the NodeMCU has pin D1 for this purpose. SDA on the Arduino is supported by pin A5 while on the NodeMCU pin D2 supports this function. Note that the NodeMCU is a 3.3V platform. I am not aware of the influence of temperature of a BMP280 on the reported atmospheric pressure, a kind of interdependence similar to that of temperature and relative humidity. device.
Relative humidity: DHT11. The DHT11 is a cheap, simple, but otherwise rather inaccurate sensor that senses relative humidity together with temperature. The advantage of this particular sensor is that it can be mounted in a suitable place some distance away from the microprocessor. A satisfactory location for a relative humidity probe is any spot on the outside of the protecting box. As the relatIve humidity of an air mass depends on the temperature of that air mass, we can use both parameters as indicators for environmental conditions inside the home. A disadvantage of the DHT11 is that the measurements are rather inaccurate. I attacked this problem by applying two DHT11’s and averaging their output.
Figure 4. Two DHT11 sensors soldered onto a PCB and protected by placing them in an acrylic vial: the ‘double-DHT11 pod’. The bottom of the vial is open to allow [humid] air to enter the pod
Two DHT11 devices were mounted back to back inside an acrylic vial (further called the ‘double-DHT11 pod’) on a small PCB cut out from a larger board. Figure 4 shows the components and the assembled pod. Four wires lead from the pod to the weather station’s board: power (3V), GND and from each DHT11 a data wire. The cap of he pod is attached with two tiny screws to the side of the protecting box, and the pod is snapped onto its cap.
As DHT11s typically measure relative humidity and temperature, the averaged temperature reading from the pair of DHT11s is further considered to represent the temperature inside the home.
Although it is possible and economic to solder a NodeMCU and sensors directly onto a soldering board, I decided to construct a ‘base board’ with pin headers, wires and resistors such that for final assembly all major components of the weather station are simply plugged in: microcontroller board, sensors. The advantage of a ‘base board’ is that failing parts can be replaced immediately, without de- and resoldering.
1x Lua NodeMCU ESP8266 microcontroller board, 1x BMP280 breakout board, 1x Dallas DS18B20 temperature sensor, 2x DHT11 relative humidity sensor, 1x 8×6 cm soldering board (the ‘base board’), 2x 10 kΩ resistor (pullup for DHT11), 3x 4.7 kΩ resistor (pullup for the DS18B20, and pullup for the SDA and SXL wires of the BMP260), female pin headers, plastic box with acrylic lid (the protecting box), Dupont pin header wires, 5V micro usb power supply for the NodeMCU, acrylic vial with plastic cap.
Assemblage of the weather station
Figure 5 shows the design for the wiring of the weather station, the NodeMCU pins assigned to the various sensors, the pullup resistors and the positions of the pin headers. Because the pins of the BMP280 breakout board stick into a female pin header soldered on the base board the entire beakout board is positioned in figure 5 on the board. The actual assembled base board is shown in figure 6.
Figure 5. Wiring diagram of the weather station
The pins of the NodeMCU board stick into two parallel female 15-pin headers soldered onto a 80×60 mm soldering board: the ‘base board’ (fig.6). An alternative to this home-made motherboard is the more luxurious ready-to-use, commercially available NodeMCU base (which then needs a small adaptation to accommodate the BMP280). On the base board are soldered the 4.7 kΩ pullup resistors for the ‘receiver end’ SDA and SCL lines for the BMP280, the 10 kΩ pullup resistors for the DHT11s and the 4.7 kΩ pullup resistor to be connected with the data wire of the DS18B20. Without proper pullup resistors the I2C protocol will not reliably work and data from the BMP280 sensor will not be received properly by the NodeMCU board.
The base board with the NodeMCU on it is mounted on a plywood base inside a plastic box that has a transparent acrylic cover (see figure 8).
After testing, developing and uploading the proper sketch the weather station box was mounted in a proper place inside the home, within range of the wifi router. The external temperature probe was mounted on a suitable spot outside the home. Connection between the external temperature probe and the weather station is provided by a 5-meter long Category-5 LAN cable. Finally a 5V power supply was attached via the NodeMCU’s usb port. Weather station ready for operation!
Figure 6. ‘Base board’ with pin header ‘socket’ for the NodeMCU and the pin headers for the sensors soldered. Painted colors are added to indicate 3V (red), GND (black) and data (white).
Figure 7. NodeMCU and sensors positioned/ connected to the base board
Figure 8. Completely assembled weather station
ThingSpeak is a service offered on the internet by MathWorks. According to its developers, “ThingSpeak is an open source IOT application with an API (application programming interface). ThingSpeak encompasses the creation of sensor logging applications, location tracking applications, and a social network of things with status updates” (source: wikipedia – search term <ThingSpeak>). In order to use ThingSpeak, one has to register to obtain an API key / password combination. Next, channels can be named and configured at thingspeak.com to receive and display data. In this example, data are exported from the NodeMCU board to a channel at ThingSpeak named ‘Weather Station’ (figure 9).
The instructions in the sketch consist of three groups:
Testing: After assembling the weather station into a finished and fully operational device the first step was to determine the difference between box temperature and the temperature registered by the DHT11s outside the box. This test was run with the box initially open. Two hours before the test the cover was taken off the box, and the box was placed in the test room to equilibrate the temperatures of all components. Power was plugged in at moment t=0. After one hour and a half the cover was secured in place while the measurements continued. The logged temperatures (figures 9 and 10) show how the temperature inside the box (BMP280 temperature) develops over operation time compared with the temperature outside the box (the double-DHT11 probe temperature). Amazingly, even with the lid open the temperature inside the box increases and becomes stable at approximately 2 degrees Celsius higher than the temperature outside the box. With the box closed the difference becomes even higher (2.5 degrees Celsius), and this remains so during operation. It thus can be conclude that the electronics inside the box contribute to a temperature rise.
Figure 9. Test run of the weather station beginning with a cold start. Comparison of temperature logged outside and inside the box, duing a period with open box and next with closed box. The temperature inside the box becomes 2.5 oC elevated compared with the outside.
Figure 10. ThingSpeak graphic display after a night of test run. The box was placed in the living room. A. temperature outside the box, B, temperature inside the box (BMP280). The central heating system in my home is programmed at 09:00 GMT (local 08:00) to elevate room air temperature from 17 to 18 degrees Celsius. The temperature inside the box is consistently 2.5 degrees Celsius higher than the temperature outside the box.
Weather station in full operation: After the testing the box was positioned in its final spot, the external temperature probe mounted, wires installed from the temperature probe to the box, private channel on https://thingspeak.com configured, and logging was started. Figure 11 shows two ways of representation of data in ThingSpeak: charting and plotting. ‘Field 2 Chart’ in figure 11A is the plotting of the data points while figure 11B is the same data collection, plotted in a longer time frame to have a better visualization of the development of the air temperature outside my home )data collection February 8, 2017).
Figure 11. ThingSpeak graphic display of outside temperature measurements A.Stahdard representation of data points over a specified period, B. It is possible in ThingSpeak to plot data oover any defined time period, here between 07:30 and 17:30 local time.
screwed in place an open boxout the outside the I have now collected an uninterrupted data stream over a period of two months. Via my smartphone, tablet or desktop computer I can see in a private channel at the ThingSpeak website the actual environmental data in moving graphs. Data can be analyzed on line, while the user interface allows data to be downloaded in comma delimited (csv) format. A sample spreadsheet graph of a week in which the barometer went up and deep down vey fast is presented in Figure 12.
The construction of a device that features sensors inside and outside a box that contains a NodeMCU was successful. The wifi signal has to pass the acrylic box cover and the inside glass pane in order to connect to the wifi router which is situated one floor below. Signal strength of the wifi router at the position of the weather station is -63dB, and signal strength of the weather station wifi router at the position of the wifi router is also -63 dB. Wifi communication of the ESP8266 works amazingly well, without problems.
With one datastream every five minutes of five sensors to the ThingSpeak server, every 24h period will produce 24 x 12 x 5 = 1,440 data points. In one month, 1,440 x 31 = 44,640 data points will have been accumulated. One year of uninterrupted data collection will result in 525,600 data points. To prevent the accumulation of data into unmanageable amounts it is recommendable to download data regularly, say once every month and then remove redundant data from the server. Another approach is to reduce the number of readings to, say, one transmission every 10 minutes. Such a reduction results in a 50% saving on accumulated data points.
Downloadable sketch: ESP8266_weather_station.zip