Previously, I’ve written about MQTT’s role in the Internet of Things. As a next step, my goal for this blog is to create a temperature and humidity monitor which pushes updates via MQTT. To create a temperature and humidity monitor, we need to create an electronic circuit that monitors temperature and humidity as well as connects to the internet to push the updates. To meet this objective, we are going to use Arduino prototyping platform, with a temperature and humidity sensor called DHT22 and an Ethernet shield that can be used to connect the prototype to the internet.
What is Arduino?
Arduino is simple open source prototyping hardware and software used to build simple circuits for proof of concept and hobbyist causes. It is used in the academic setup since it’s cheap to build simple circuits for scientific experiments. The board has a 16 Mhz Amtel processor with 32Kb of Eprom. The programming language used is C++, but most of the code can be implemented with minimal basic knowledge without the need to go into advanced concepts like pointers and memory manipulation. The programs are called sketches. The IDE comes with lots of goodies, which include libraries and add-ons such as sensors, Ethernet shields, and MQTT as well. This makes it really simple for hobbyists to play around and spend most of the time around the actual cause than figuring out the drivers or hardware level functions.
The following links will get any hobbyist out there a quick start into the world of Arduino.
Temperature Humidity Circuit
The following sketch is an improvement over the circuit listed from Adafruit examples.
Components Required:
- Arduino UNO – The prototyping computer module that is used to publish data.
- Arduino Ethernet Shield – For connecting to the internet
- DHT22 – Temperature and humidity sensor
- 10K Ohm Resistor – For pullup
The below circuit sketch (figure 1.1) is used to build the device. This circuit has an additional shield that can be used to connect to the internet for publishing and subscribing messages to the internet. Figure 2.2 is a reference diagram used to explain the goal of the device. The IoT device will publish to an MQTT broker topic (test.mosquitto.org), which then sends the message to all the subscribers of the topic.
Mailbox Location | Lync/Skype account location | Preparation Required |
---|---|---|
Online | Online | Yes |
On-premises | Online | Yes |
Online | On-premises | Yes |
On-premises | On-premises | No* |
The following snippet shows fragments of the code related to connecting to the broker. Full source is available at Arduino MQTT demo.
Monitor using MQTT Client
There are many MQTT mobile clients available on iOS and Android. MQTT client libraries are easy to access if any one wants to build a custom application too. For the purposes of the demo MyMQTT android client is chosen. Once installed, the following need to be entered in the configuration:
- MQTT broker host and port
- Subscribe to the topic (demo/arduino/airquality).
Once the set up is done, the updates should be posted and streamed on the application.
Note: Source code for running the circuit can be downloaded from the following github location.