Internet of Useless Things Workshop with Arduino MKR1000

Workshop Goals

  1. Learn how to setup and use the Arduino MKR1000 board
  2. Learn how to connect the board to the service with the Adafruit MQTT library
  3. Learn how to connect your to other online services (like Twitter,  Instagram, Google etc.) using IFTTT
  4. Make an Internet of Things thing that has absolutely no reason to be on the internet


There are some steps we need to first do to get to the actual fun part.

Install Arduino IDE and the Necessary Libraries

  1. Download and install the Arduino IDE (
  2. Open the Arduino Boards Manager (Tools—>Board—>Boards Manager)
  3. Search for Arduino SAMD Boards and install the latest version (the description should mention the MKR1000 board)
  4. Open the Library Manager (Sketch—>Include Library—>Library Manager)
  5. Install the Adafruit MQTT Library
  6. Install the ArduinoHTTPCLient library

Setup the MKR1000 Board

If you are taking part in the Arduino Day workshop, you can skip this step. This has already been done.

  1. Solder the header pins to the MKR1000 board, so you can easily plug it to the breadboard
  2. Follow the instructions how to update the Firmware and update the SSL certificates and IFTTT

You will need an account for two services for this workshop. Adafruit IO allows us to stream, log, and interact with our data. IFTTT allows us to connect that data to other services.

  1. Create an Adafruit account
  2. Log in with the account to Adafruit IO
  3. Also register to IFTTT
  Adafruit MQTT Library WINC1500 Example
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
#include <SPI.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <WiFI.h>

char ssid[] = "aalto open";     //  your network SSID (name)
char pass[] = "";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

/************************* Setup *********************************/

#define AIO_SERVER      ""
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "your_id"
#define AIO_KEY         "your_key"

/************ Global State (you don't need to change this!) ******************/

//Set up the wifi client
WiFiClient client;


// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1);  }

/****************************** Feeds ***************************************/

// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");

// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");

/*************************** Sketch Code ************************************/

#define LEDPIN 6

void setup() {

  while (!Serial);

  Serial.println(F("Adafruit MQTT demo for WINC1500"));

  // Initialise the Client
  Serial.print(F("\nInit the WiFi module..."));
  // check for the presence of the breakout
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WINC1500 not present");
    // don't continue:
    while (true);
  Serial.println("ATWINC OK!");
  pinMode(LEDPIN, OUTPUT);

uint32_t x=0;

void loop() {
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.

  // this is our 'wait for incoming subscription packets' busy subloop
  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &onoffbutton) {
      Serial.print(F("Got: "));
      Serial.println((char *)onoffbutton.lastread);

      if (0 == strcmp((char *)onoffbutton.lastread, "OFF")) {
        digitalWrite(LEDPIN, LOW);
      if (0 == strcmp((char *)onoffbutton.lastread, "ON")) {
        digitalWrite(LEDPIN, HIGH);

  // Now we can publish stuff!
  Serial.print(F("\nSending photocell val "));
  if (! photocell.publish(x++)) {
  } else {


// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // attempt to connect to Wifi network:
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid);

    // wait 10 seconds for connection:
    uint8_t timeout = 10;
    while (timeout && (WiFi.status() != WL_CONNECTED)) {
  // Stop if already connected.
  if (mqtt.connected()) {

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println("Retrying MQTT connection in 5 seconds...");
       delay(5000);  // wait 5 seconds
  Serial.println("MQTT Connected!");