This work is aimed to give a detailed description of how the LoPy4 quadruple bearer board and the DHT11 sensor can be used to monitor temperature and humidity and display these environmental factors on a Pybytes dashboard. To transfer the data a WiFi connection will be used. This methodology can be applied to other projects where similar sensors are used. The aim is to describe the setup of the LoPy4 and the sensor, how the data is collected and packaged, and how the data is displayed for the end user.
To do this project it should roughly take about eight hours from start to finish.
This project was chosen because IoT solutions are very usable in hard-to-reach places, for example the foundation of a house. The idea for the device is to be used in a crawl-space foundation where moisture is a commonly occurring problem and therefore the humidity is of interest.
The purpose of this device is to monitor the temperature and relative humidity using the DHT11 sensor. The temperature is logged as well because to sensor has the ability to do so, but will not serve any other purpose than merely an informative one. Since both the temperature and relative humidity is logged one can observe the phenomenon that if the temperature decreases, the relative humidity increases since the air does not need as much moisture to become saturated. These kinds of fluctuations are expected and unavoidable and should be relatively small. If the relative humidity would increase a lot, something unwanted might have happened, there could be water standing the crawl space for example. If this following scenario was to occur, the user will be notified:
This value was suggested as a general rule regarding crawl space foundations but is arbitrary in terms of how the project is executed. This project will hopefully lead to insights into how IoT solutions can be used to monitor sensor data and automate otherwise tedious tasks such as measuring the humidity and temperature in a house foundation to avoid moisture-related problems.
Since the hardware used in this project were bought in a bundle, individual prices for the different products can not be stated. The following prices were estimated using listed prices, (from the Pycom webshop and RS Components Sweden), for the products themselves without taking shipping into consideration. The hardware below is what is required to make this project.
Component | Function | Retail price [SEK] |
---|---|---|
Pycom LoPy4 | Microcontroller | 367 |
Expansion board | Enables multiple physical connections to LoPy4 | 168 |
DHT11 sensor | Temperature and realtive humidity measuring | 52 |
Breadboard and jumper wires | Connection between expansion board and DHT11 | 69 |
Sum: | 706 | |
All hardware for this project was purchased at www.electrokit.com/, at a total cost of 1339 SEK, but this bundle included several components which are not necessary for this project. |
Since an open LoRa network was not in range where this project was carried out, a simpler microcontroller than the LoPy4 could have been used, for example the WiPy3 from Pycom as well. This device does not feature the ability to connect to LoRa but is cheaper and choosing this would have reduced the total price to approximately 547 SEK instead of the previously stated 706 SEK. The LoRa antenna is added as a safety precaution but is not necessary in this project, therefore it is not included in the table of components. An image of all the components in shown below in section Results and discussion.
Operating system: macOS
IDE: Atom with Pymakr plugin
Development board LoPy4
Expansion board version 3.0
This chapter aims to describe the software setup for this specific setup. Some steps are different if the expansion board is an older version, or another operating system is used. In these cases the Pycom documentation
is highly recommended. This guide aims to summarize the essential steps to get started for this particular setup.
At this stage three arrows should be showing (>>>) indicating that the Pycom device is connected and up and running. The next step is now to write and upload code to the device. This is done by creating a project in Atom and writing a Python file and pressing upload to the device in the Pymakr interface.
The sensor was connected according to the following scheme:
Where the left pin on the sensor is the signal out (S), middle is the voltage in (+) and right is the ground (-). The image was constructed taking images from the Pycom website, and a free to use image of the DHT11 licensed under the public domain.
Since this sensor features a built in 1 k pull up resistor no other resistor has to be added. This is used because the DHT11 sends digital signals and this resistor helps define the high/low state. According to the data sheet supplied with the sensors, the sensor can operate at a current from 3.3 V to 5.5 V. Since the voltage output on the pin used (3V3) is on the lower end of the spectrum, long cable lengths are to be avoided to avoid risking line voltage drops potentially leading to errors in measurement. Currently the device is powered through a USB cable. This setup is only to be used for development and would not be suited to be used in production for multiple reasons. The components are quite expensive, the setup takes a bit of time and the device is not in any way shielded.
During this project the Pybytes platform was used because the integration was very simple and it was available without cost since the development board was bought from Pycom. Few lines of code had to be added and the data steamed seemingly without errors. This platform simply shows the temperature and humidity values plotted over time. In the future a more developed platform could be used, for example Google cloud, which is free up to a 250 MB/month data limit. For users familiar with MATLAB, their platform Thingspeak might be an interesting alternative. This platform should make it fairly simple to analyze data, and is also free up to a data limit of 8200 messages per day.
Based on: https://github.com/iot-lnu/applied-iot-20/tree/master/sensor-examples/DHT11-22
The code is built mainly using the code found at the Github repository with some minor changes to signal if the humidity exceeds the threshold value. Basically, it import the modules stated in code row 1-3, where the dht module is used to read the sensor in question and output the readings as integer values that can be uploaded to Pybytes. The loop from row 8-18 implements this functionality of the module and sends the data using the function described in the following chapter. The device then sleeps for five seconds before restarting the loop. This value could be set much higher for the application but works well in development purposes.
Data update rate: Every five seconds
Wireless protocol: WiFi
Transport protocol: None, however the terminal writes the following:
Connected to MQTT mqtt.pybytes.pycom.io
when connecting the LoPy4, suggesting that MQTT is used by the pybytes.send-function described below, which seems reasonable since it is a lightweight connectivity protocol, commonly used in IoT applications.
The data is transmitted to Pybytes using the following function
which is part of the Pybytes library and is used to send data values labeled with a signal number. Since the data is transferred over WiFi, the data does not need to be manipulated in any way which would be the case if for example LoRa was used. WiFi was chosen because no open LoRa network, for example TTN was in range. If a LoRa network would have been in range this would have probably been the wireless protocol of choice, since it is less power consuming to use than WiFi.
Dashboard: Pybytes built in.
Data save rate: Same rate as the data is uploaded, every five seconds.
Data preservation time: One month.
Image of the dashboard:
The dashboard was built following the Visualise data from your device-guide in the Pycom documentation, where the main steps are:
The first two signals are self-explanatory, but the third signal is used to signal the user if the threshold value of 55% relative humidity has been exceeded (the value 1 is sent out). There are so called alert functions on the Pybytes site under construction and these could perhaps be used in the future to notify the user instead of using a third signal.
This image shows what the final set up looks like for this project. The different components are built into a cardboard box just to keep everything in place and make the unit somewhat transportable.
The objective of this project was to monitor the temperature and relative humidity using the DHT11 sensor, and notify the user if the relative humidity exceeds a threshold value of 55%. This purpose is fulfilled and for this the Pybytes website works well. The setup is relatively easy when using Pybytes which is an advantage over other platforms.
Since all the components have not been delivered when this report is being written there are some steps that have not been able to be done yet. These are the following:
If the project was to be done again some changes would have been done: