Raspberry Pi as a $21 Edge Environment Monitoring System
I have written a few articles about the Raspberry Pi Zero 2 W (RPi Zero 2 W). Another article showed how I installed the Raspberry OS on it. It was very simple. Another time, I used it for creating an edge device to capture time-lapse photographs. I will be using it to make another edge device that monitors the temperature and humidity at a remote location.
The Zero 2 W truly is a marvel of engineering. It comes with a 1GHz 64-bit ARM CortexA53 CPU, GPU and 512MB RAM. You also get Wi-Fi 4 (with BLE support) and Bluetooth 4.2 (with BLE support). This device was originally designed for educational purposes and includes 40 General-Purpose I/O (GPIO) holes. These holes allow it to connect with sensors to monitor them.
Assembling an Edge Environment Monitor Solution
To create an edge monitoring solution, first attach a DHT22 sensors to the RPi.
The Zero is a minimalistic, low-cost device that doesn’t even have header pins to connect to the GPIO.
I was able buy the header pins for less than two dollars. Despite my limited soldering skills, the soldering of the pins was done in less than 10 minutes.
Many low-cost temperature and humidity sensors can be used in conjunction with the RPi. The DHT22 sensor and DHT11 are the most popular. Both sensors can transmit data using just three wires, and they can be used up to 20m from each other. The DHT11 is cheaper and more accurate than the DHT22. However, it can transmit data every one second, while the DHT22 cannot transmit data every two seconds.
Below are the specifications for DHT22/DHT11:
Temperature range | Humidity Range | Accuracy in Temperature | Humidity Accuracy | Speed | |
DHT11 | 0-50 C | 20-90% RH | + – 2C | + – 5% RH | 1 |
DHT22 | -40 to 80 C | 0-100% HR | + – 2C | + – 2 to 5% RH | 2 S |
The DHT22 is the sensor I chose to use. I purchased two packs of them for $12. They included cables, the DHT22 mounted to a PCB and a case.
The pins on GPIO are numbered from 1 to 40. Pin 1 is the closest pin to the SSD card, while pin 2 is directly above it.
I connected the yellow wire from GPIO pin 1 to 3.3 VDC, the green wire to pin 6, and the blue wire at pin 7 to GPIO4.
I connected the yellow wire to (+), and the blue to second (out), while the green was connected to third pin (-), on the DHT22
Use the Sensor
RPis come with a wide range of programming tools that allow them to collect information from the sensors they have.
After powering up the RPi I installed the DHT22 Library and then received a sample code from Adafruit.
sudo pip3 install adafruit-circuitpython-dht
In the dht_simpletest.pyfile, I commented lines 6 and 27, uncommented line 11, changed D18 to D4, and deleted line 11. Enter:
python3 dht_simpletest.py
I got the temperature, humidity, and an error message every two seconds.
To prevent the error message being displayed, I commented out line 29, print(error.args).[0](in the code). I was unable to see the errors when I reran code.
I changed the code to take only one reading and write the output every time the code was executed.
Use Third-Party Monitoring Software
I was most interested in how easy a third party monitoring tool could be integrated with the RPi. There are many tools available that can monitor and manage IoT devices and edge devices. ControlUp is my employer so I thought it would be fun to see if it could also monitor this. ControlUp is primarily used to monitor VDI implementations and endpoint devices. However, its SaaS cloud-based Edge DX product features an Arm32 Linux Agent and transmits data via the http port. I thought it would make a great IoT monitoring tool because the device can be found anywhere in the world that has Wi-Fi and monitored from one central location.
After downloading and installing the agent I was surprised to see my Edge DX dashboard show the device. This showed the OS, hardware, CPU activity and memory as well as networking activity.
I could see the active applications and processes on the device.
If needed, I could also run commands on the device and restart it from the dashboard.
Conclusion
I continue to be impressed by the Raspberry Pi Zero 2 W. I was able set up a remote temperature/humidity monitoring device in less than an hour. It cost me less than $22. The device was extremely affordable and the flexibility it offers is amazing. It has a quad-core Arm processor with 512MB RAM. As I wrote previously about the remote time lapse technology, I think it is unlikely that large companies would bother to assemble and deploy these devices at the edge. However, individual business units within large businesses or small businesses might see the benefits of using devices like these.
The DHt22 is only one of the many sensors that can work with a RPi. It can also be used as a barometer, moisture, and motion sensor. GPS modules, gyroscope, and compasses can all be integrated with RPis. The biggest lesson I have learned from my Zero project is that we will continue seeing more edge devices for remote monitoring, due to the low-cost and flexibility of SoC.
About the Author
Tom Fenton is an IT veteran with extensive hands-on experience. He has worked in a variety technologies over the past 25+ years, with the last 15 years being focused on virtualization. He is currently the Technical Marketing Manager for ControlUp. He was previously a senior course developer, solutions engineer, and in the competitive marketing group at VMware. He was also a Senior Validation engineer with The Taneja Group. He headed the Validation Service Lab, and was instrumental in the establishment of its vSphere Virtual Volumes program. He can be found on Twitter at @vDoppler