After receiving the hardware from Element 14 for the IOT Holiday lights challenge, i have completed the touch enabled minion ornaments for my christmas tree to go along with the minion sound generation i described in the earlier blog post.




Components used:


1. Arduino Yun

2. Adafruit 12-key capacitive touch sensor breakout - MPR121

3. Eclipse Paho MQTT Library

4. Home made minion ornaments

5. Conductive Thread for wrapping around any christmas ornament


Here is a high level diagram of how it all works.




1. Home made Minion ornaments ready to be tested. I couldn't find the minion ornaments in the local stores. So I just used aluminum foil from the kitchen to wrap around piece of cardboard. And stuck the minion stickers on them.

Notice the last christmas ornament. This is wrapped around with conductive thread. This is what i originally intended to do if i get the actual minion ornaments. This works well too.



2. Wiring:

Arduino Yun is connected to the Adafruit MPR121 touch sensor break out. Since this is a temporary arrangement i didn't solder the fires to the break out. The break out speaks I2C. On Yun the SDA and SCL are on the digital pins 2 and 3.



3. Yun connected to tree. (Officially becoming a WiFi Tree)

The small breadboard had a 3m sticker on the back. So i was able to peel it off and attach it to the base of the tree. So this tree is going to be a bread boarded tree forever. In the years to come i hope this bread board gets used for other projects. I just kept the Yun in one of the shipment boxes for now. Later when other parts of the WiFi christmas tree project is done i will plan for an enclosure.


4. Minion Ornaments on the Tree

I was really happy once it all worked on as planned and the look on my 5 year old son's face was priceless when he touched one of the minions for the first time and it went "whaaaaaaaaaaaaat"



The Code:

I have used the code from Adafruit for Capactive touch and the MQTT example from the MQTT C library linked by kartben in an earlier blog post on MQTT. I have modified both code to suit my purposes.


This sketch contains three files. I abstracted away the MQTT functionality in to a MQTTHelper class in the arduino coding style to keep my main arduino sketch cleaner. This mqtt helper class just contains a MQTT Publish functionality only. I will add the subscribe functionality later as i continue to work on other parts of the project.


ToucheMinions Arduino Sketch

//Created By: Mohan Palanisamy for Holiday Lights IoT project at Element 14
//Thanks to Adafruit, Benjamin Cabe, Eclipse Paho for their sample code and Libraries
//You can find them here:
//Adafruit MPR121 Library:
//Benjamin Cabe:ún
#include <Wire.h>
#include <SPI.h>
#include <YunClient.h>
#include <IPStack.h>
#include <Countdown.h>
#include <MQTTClient.h>
#include "MQTTHelper.h"
#include "Adafruit_MPR121.h"

char* mqttBroker =""; //mqtt broker running on windows pc
int port = 1883;
char* topic = "WiFiTree/FromController/MinionSound";

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

MQTTHelper mqttHelper=MQTTHelper();
Adafruit_MPR121 minionSensor = Adafruit_MPR121();

void setup() {



void loop() {

  currtouched = minionSensor.touched();

  for (uint8_t i=0; i<12; i++) {
      if ((currtouched & (1 << i)) && !(lasttouched & (1 << i)) ) {
            char msgbuf[2];
            mqttHelper.sendMessage(topic,(char *) msgbuf);

  lasttouched = currtouched;




//Created By: Mohan Palanisamy for Holiday Lights IoT project at Element 14
//Uses source from Benjamin Cabe of eclipse foundation.

#include "MQTTHelper.h"

YunClient c;
  IPStack ipstack(c);
MQTT::Client<IPStack, Countdown> client=MQTT::Client<IPStack, Countdown>(ipstack);

MQTTHelper::MQTTHelper() {

void MQTTHelper::begin(char* hostname, int port) {

//MQTT client setup
  ipstack.connect(hostname, port);
  MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
  data.MQTTVersion = 3;
  data.clientID.cstring = (char*)"wifitree-555";

  Serial.println("MQTT connected");

void MQTTHelper::sendMessage(char* topic, char* msgbuf)
  MQTT::Message message;

  if (!client.isConnected())

  message.qos = MQTT::QOS0;
  message.retained = false;
  message.dup = false;
  message.payload = (void*)msgbuf;
  message.payloadlen = strlen(msgbuf)+1;
  client.publish(topic, message);



//Created By: Mohan Palanisamy for Holiday Lights IoT project at Element 14

#include <Wire.h>
#include <SPI.h>
#include <Bridge.h>
#include <YunClient.h>
#include <IPStack.h>
#include <Countdown.h>
#include <MQTTClient.h>

class MQTTHelper {


  void begin(char* hostname, int port); // to abstract connection setup arduino style
  void sendMessage(char* topic, char* msgbuf);




Future adjustments:

On Chuck i should be able to create shreds to make tingling sounds with the proper scale. Then it would be easy to make a very musical christmas tree when the ornaments are touched.


Hope you enjoyed this and try this out for your self. Merry Christmas and Happy Holidays every one!!!