Skill Level: Any Skill Level

Need some knowledge on Arduino programming and eletronics

This tutorial is about visualizing with LED lights the result of sentiment analysis performed on unread emails by NodeRED in IBM Watson IoT. LED are controlled by an Arduino MKR1000 board,which retrieves sentiment score and changes light accordingly.


  • Arduino MKR1000 (https://www.arduino.cc/en/Main/ArduinoMKR1000)
  • 1x RGB LED Light Strip (AglaiaLT-S2)
  • LED strip connection with Arduino:
    • 1 breadboard
    • 3x 100ohm resistors
    • 3x TIP122 NPN transistors
    • 1x power jack
    • Spare cables
    • 3x 100ohm resistors
  • IBM Watson IoT account


  1. LED connection with Arduino MKR1000

    Connect Arduino MKR1000 with a strip LED lights as visualized in the schematic.


  2. Register MKR1000 to IBM Watson IoT

    In order to register your Arduino MKR1000 board to IBM Watson IoT, you can read the following step-by-step guide:

    Once finished, note down credentials for the registered device (org-id, device-type, device-id), the API-key and Authentication token.

  3. Import NodeRed application


  4. Configure and start NodeRED application

    • The NodeRED application is composed by two flows (see picture below).
    • First flow performs sentiment analysis and sends result to Arduino board
      • Input node of first flow¬†connects to an email account periodically and fetches the last unread emails; configuration of the input node depends on email account selected (i.e. gmail). Each email received is sent to a sentiment analysis node, which returns a score (less or above 0) based on negative/positive content of the text analyzed (see this link https://github.com/thisandagain/sentiment/blob/develop/README.md¬†for more details).
      • Sentiment score is sent to a simple function node which calculates the average of the last data received and pushes the result to the next node.
      • Finally the last node sends a message containing the value of the sentiment score to the connected Arduino device using MQTT protocol; this block needs to be configured with the credentials generated during device registration process in step 2.
    • The second flow is used for testing purposes to visualize the status of the Arduino board
      • Input node receives device status from Arduino board and pushes it to IBM quickstart web page where it can¬†be visualized¬†(https://quickstart.internetofthings.ibmcloud.com/).
      • Status messages contains the sentiment score and the RGB combination for LED currently used in Arduino board.
    • Click deploy button to activate the flow
    • nodered
  5. Configure Arduino sketch

    • Download the sketch available in https://github.com/EmbeddedIoT/ConnectedMug/blob/master/Arduino/ConnectedMug.ino.¬†This sketch requires the following libraries:
    • Open the sketch with Arduino IDE (https://www.arduino.cc/en/main/software)
    • 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)
      • (…) : callback called upon reception of messages with sentiment score from Watson IoT application.
    • The sentiment score is mapped to RGB values (negative: red; positive: green). Configure the code based on credentials generated during the device registration procedure described in step 2 (org-id, device-type, device-id)
      • 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
    • Connect the Arduino board to the PC, compile and flash the board in Arduino IDE as shown below


  6. Launch the solution

    • Power up the Arduino board and the LED strip lights. See connections in step 1.
    • At start the Arduino application connects to the WiFi AccessPoint and later to the MQTT end point configured in the code.
    • Once received the sentiment analysis score from IBM Watson IoT, the Arduino board will change the light of the LED accordingly (green for emails with positive messages, red for negative messages).
    • It is possible to check in the IBM Quickstart web page the status in real time of the Arduino application (RGB code being displayed and the sentiment score received); open the web browser at page https://quickstart.internetofthings.ibmcloud.com and insert the device id to visualize the status for your device
    • See more on this project here:¬†https://sites.google.com/view/make-iot/connectedmug¬†


Join The Discussion