Arduino to ThingSpeak Channel

1. Description

A previous IoT article (MQTT Node with Arduino Uno and W5100 Ethernet Shield) presented a basic system monitoring sensor data in local area network environments, using a locally installed MQTT broker (server). This tutorial presents the possibility of using an open-source cloud-based server (ThingSpeak) that could offer the advantage of remote accessing the collected data, graphical representations and analytics.

Difficulty level: intermediate.

ThingSpeak offer a free web service that allows collecting and storing sensor data in the cloud in order to develop IoT applications. It uses channels to store data sent from apps or devices. Data could be written to channels in two different ways:

– using HTTP calls from the REST API:

o channel data writing (updating) through GET or POST requests;
o channel data reading through GET requests;

– using MQTT publishing:

o channel data writing (updating) through MQTT Publish method;
o channel data reading through MQTT subscribe method.

Channels could be accessed publicly and/or privately and could be visualized in real-time using charts. Data analytics could be done through MATLAB functions.
For additional information please consult the online documentation at https://thingspeak.com/.

2. Parts

– 1 x Arduino Uno R3;
– 1 x Arduino Ethernet shield (W5100);
– 1 x DHT11 temperature and humidity sensor;
– 1 x BMP180 barometric pressure sensor;
– Breadboard + wires.

3. Schematics

(click to enlarge)

4. Assembly (breadboard)

(click to enlarge)

5. Code

5.1. Update channel data using HTTP (POST) calls from the REST API

arduinoToThingSpeakREST.ino – to be uploaded to Arduino:

5.2. Update channel data using MQTT publishing

arduinoToThingSpeakMQTT.ino – to be uploaded to Arduino:

5.3. Graphical view of channel data

The image below shows a capture screen of the channel data graphical representation; part of the data has been sent through REST API, part of it using MQTT publishing.

(click to enlarge)

6. Additional resources

Libraries:
– Adafruit Unified Sensor Driver:
https://github.com/adafruit/Adafruit_Sensor
– DHT-sensor-library:
https://github.com/adafruit/DHT-sensor-library
– Barometric Pressure Sensor Breakout – BMP180:
https://github.com/sparkfun/BMP180_Breakout
– SPI, Ethernet and SD standard libraries (included with the Arduino IDE)
– Arduino Client for MQTT: https://github.com/knolleary/pubsubclient

References:
– DHT11 datasheet: https://cdn-learn.adafruit.com/downloads/pdf/dht.pdf
– BMP180 datasheet: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
– Arduino Ethernet shield (WT5100) datasheet: http://www.mouser.com/catalog/specsheets/A000056_DATASHEET.pdf
– ThingSpeak REST API: https://www.mathworks.com/help/thingspeak/rest-api.html
– ThingSpeak REST API: https://www.mathworks.com/help/thingspeak/mqtt-api.html

Leave a Reply