Introduction: Connected Mug

About: Design and build prototypes for IoT

Sometimes in the morning while sipping my coffee before going to office, I'd like to a have glimpse of what it is expecting me in my email inbox. i.e. the number and tone of emails received....wether the project I just finished the day before is working or not and if there are positive or negative comments about it. On the other hand I don't really mind to open the email client application with my mobile and start reading emails during breakfast.

From these considerations comes the idea of this project; it uses a coffee mug enhanced with LED lights which change their colors based on the result of sentiment analysis performed on the last unread emails received in my email account. Just plug the mug and LED lights will turn to green color if last recevied emails have positive messages, red color for the opposite.

The sentiment analysis of unread emails is performed by IBM Watson IoT services. An Arduino MKR1000 board is used to control the LED strip and to connect with IBM Watson IoT services over WiFi using MQTT protocol.

Step 1: Hardware Components

Hardware development board :

Hardware BOM

  • 3x 100ohm resistors
  • 3x TIP122 NPN transistors
  • 1x power jack
  • 1x RGB LED Light Strip (AglaiaLT-S2)
  • Spare cables

The wiring to control LED strip with Arduino MKR1000 is based on this tutorial: https://www.instructables.com/id/ARDUINO-CONTROLLED...

Step 2: Create an Account on IBM Watson IoT and Register Your Device

In order to create a cloud application able to perform sentiment analysis of unread emails with IBM Watson IoT, it is necessary first to sign for a free trial account (http://www.ibm.com/internet-of-things/trial/). Second step is to create an application for Watson IoT platform and register your Arduino MKR1000 board; this is now a standard procedure to connect Hardware platforms with IBM Watson IoT, and it is well documented in IBM quickstart guides:

https://console.ng.bluemix.net/docs/services/IoT/i...

IBM also provides boilerplate templates for IoT which speed up these steps by bounding the services and runtimes needed to launch your IoT application. IoT for Electronics Starter Boilerplate was the one used for this project.

Step by step device registration guide is provided here:

https://console.ng.bluemix.net/docs/services/IoT/i...

Note down your org-id, credential, device-id, and device-type, once completed the device registration procedure, since these will be needed to configure Arduino sketch and the NodeRED application.

Step 3: Develop the Node-RED Application for Sentiment Analysis

NodeRED is a visual tool which can be used in IBM Watson IoT platform to create applications wiring devices and Cloud services (nodered.org).

The NodeRED application developed is very simple and composed by two flows, one for sentiment analysis of emails, and another one for logging the status of Arduino MKR1000 (sentiment score received by device and RGB combination for the LED being displayed).

The first flow connects to an email account periodically and fetch the last unread emails; configuration depends on you emails account. Each email received is sent to sentiment analysis box, which returns a score (less or above 0) based on negative/positive content of the text analyzed (see information https://github.com/thisandagain/sentiment/blob/mas... for more details). Sentiment score is sent to a simple function box which calculates the average of the last data received and push the result to the next node. Finally the last block sends a message containing the value of the sentiment score to the connected device using MQTT protocol; this block needs to be configured with the credentials generated during device registration process.

The second flow is used for testing purposes to visualize the status of the Arduino board;
it connects an input IoT node for your Arduino board to IBM quickstart web page for data visualization (https://quickstart.internetofthings.ibmcloud.com/). The input IoT node is configured as above to receive status messages from Arduino Board using the MQTT protocols. Status messages contains the sentiment score and the RGB combination for LED currently used in Arduino.

Node-RED application was exported to clipbord and attached here as .txt file.

Step 4: Arduino Sketch

Arduino sketch is based on MQTT client library by Gilberto Conti (https://github.com/256dpi/arduino-mqtt) which was modified to connect with IBM Watson IoT. The code is composed by three parts:

  • setup() : connect with WiFi AP and IBM MQTT broker; register a callback for messages received from IBM Watson IoT
  • loop() : set RGB pin to control LED lights; send to IBM Watson IoT the status of the device (RGB and sentiment score)
  • messageReceived(...) : callback called upon reception of messages with sentiment score from Watson IoT application. The score is mapped to RGB value (negative: red; positive: green).

Configure the code as follow, based on credentials generated during the device registration procedure (org-id, device-type, device-id):

  • MQTT_MODE = IBM_API_KEY
  • char *client_id = "d:your-org-id:your-device-type:your-device-id";
  • char *user_id = "use-token-auth";
  • char *pwd = "your-pwd";
  • char *ibm_hostname = "your-org-id.messaging.internetofthings.ibmcloud.com";

The application subscribes to topic iot-2/cmd/+/fmt/string and messageReceived callback parses messages for command type sentiment.

Status messages are published to topic: iot-2/evt/status/fmt/json

Note: remember to update SSL certificate for MKR1000; follow instructions here: https://github.com/arduino-libraries/WiFi101-Firm... and insert your ibm_hostname to download and install in MKR1000 the root certificates.

Arduino sketch attached.

Step 5: Connect Your Mug.

It would have been nice to do some more integration of electronics and LEDs in the mug, but for this project I simply attached the adesive LED strip around the mug as shown in the picture.

Then I connect the LED strip to the breadboard circuit, power the LED and the Arduino MKR1000 and wait to receive messages with sentiment score from NodeRED application. In the picture for example I tested by sending to my account emails containing text like "Great work!, Your project is wonderful!" etc.

It is also possible to check in the public IBM Quickstart web page (https://quickstart.internetofthings.ibmcloud.com) the status in real time of the Arduino application (RGB code being displayed and the sentiment score received);just need to enter device id. .

Now I can finally enjoy my coffe in a connected mug.

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Make it Glow Contest 2016

Participated in the
Make it Glow Contest 2016