Week 2: Sending Sensor Data Using MQTT Protocol

I’m excited to follow up Understanding Networks with Device to Database and learn more about the world of IoT by building my own connected devices to capture, send, save, process, and represent data. We’ve been learning about MQTT, a lightweight and secure messaging protocol for efficient use with low-power devices with little RAM, like my Arduino microcontrollers. With MQTT, devices do not connect with one another directly. Instead, data is relayed through a central server known as a broker. Devices send or publish data to a topic on the broker and can also subscribe to topics to retrieve information. Connected devices or web apps can use the data on the broker in a variety of ways, such as (very simply) representing it graphically or using it to remotely trigger changes in physical outputs (such as toggling lights off and on). As long as a devices can publish and subscribe, then they do not have to be compatible nor in sync with one another and nor do they have know other devices’ network addresses or ports. All of this flexibility makes scaling IoT systems relatively easy.

This week we learned how to send data from a temperature and humidity sensor (DHT22) connected to a MKR1000 to a broker that Don set up for us on a server created for the class. Building off our exercises in class, I added TCS34725 Color Sensor to my setup. I used this sensor as part of my physical computing midterm project, a Color Sound Pen, which I wrote about here and here. With this sensor’s RGB and clear light sensing elements, I can pick up red, green, and blue as individual values or combine those into one hexadecimal color and also note color temperature or lux ("the perceived brightness of visible light” as noted in the paper linked in my blog post). The sensor performs best when directly touching the object it’s sensing, but I was curious about the ambient values it measures when sitting uncovered in a room. If I can send those values to a server and represent them digitally, it is possible to create a durational color portrait of remote space?

1 Arduino MKR1000
1 RGB Color Sensor with IR filter and White LED - TCS34725
1 Digital Temperature And Humidity Sensor - DHTT22/AM2302
1 220 Ohm Resistor
1 Breadboard
22 & 24-Gauge Solid-Core Wires

Part 1: Adding the TCS34725 Color Sensor
Thank goodness for my blog! It was quick to review the sensor and remember that Adafruit provides two sketches to sense color temperature and lux (tcs34725.ino) and also converted-for—human-perception RGB color information (colorview.ino). Right now, I’m interested in the RGB color values, so I modified and incorporated the code into the TemperatureHumidty sketch.

Here’s a screenshot of my Arduino serial monitor showing the new sensor data:

Screen Shot 2019-02-07 at 7.07.05 AM.png

Part 2: Publishing New Color Data to a MQTT Topic
Using the subscribe example from class, I logged into see the read out of the new sensor data from the broker. Here’s a screenshot:

Screen Shot 2019-02-07 at 7.16.34 AM.png

A different way to visualize the color sensor data would be to display a swatch of color on the screen and perhaps chart the individual corresponding RGB values, which I’ll do if I have time!

Code on GitHub