This guide has been updated to use the Adafruit IO Arduino Library

The previous version of this guide used the Adafruit MQTT Arduino Library, but we suggest using the Adafruit IO Arduino Library. If you'd like to use this library, we suggest following the MQTT, Adafruit IO & You! Learn Guide

The Arduino sketch for the LEDs is also fairly straight forward. Copy the following code into a new Arduino sketch. You'll need to modify your config.h file to reflect your Wireless Network and Adafruit IO configuration.

If you do not know how to do this, follow the steps on the the Arduino Setup page. 

// Remote Control with the Huzzah + Adafruit IO
// 
// LED Board
// 
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Richard Albritton, based on original code by Tony DiCola for Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

#include <ESP8266WiFi.h>

// RGB LED Pins
#define Blue  5
#define Green 4
#define Red   2

// set up the 'digital' feed
AdafruitIO_Feed *AssistiveCallButtons = io.feed("assistive-call-buttons");

void setup() {

  // set power switch tail pin as an output
  pinMode(Blue, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Red, OUTPUT);

  digitalWrite(Red, HIGH);
  digitalWrite(Blue, HIGH);
  digitalWrite(Green, HIGH);

  // set up serial monitor
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // set up a message handler for the 'digital' feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  AssistiveCallButtons -> onMessage(handleMessage);

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
  // recv. the assistive-call-buttons feed
  AssistiveCallButtons->get();

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  Serial.print("received <- AssistiveCallButtons");  
  switch(data->toInt()) {
    case 0: // your hand is on the sensor
      digitalWrite(Red, HIGH);
      digitalWrite(Blue, HIGH);
      digitalWrite(Green, HIGH);
      break;
    case 1: // your hand is close to the sensor
      digitalWrite(Red, LOW);
      digitalWrite(Red, HIGH);
      digitalWrite(Red, HIGH);
      break;
    case 2: // your hand is a few inches from the sensor
      digitalWrite(Red, HIGH);
      digitalWrite(Red, HIGH);
      digitalWrite(Red, LOW);
      break;
    case 3: // your hand is nowhere near the sensor
      digitalWrite(Red, HIGH);
      digitalWrite(Red, LOW);
      digitalWrite(Red, HIGH);
      break;
  }
  // delay in-between reads for stability
  delay(1);
}

You will then need to check that the name of your feed matches the feed defined in the sketch:

AdafruitIO_Feed *AssistiveCallButtons = io.feed("assistive-call-buttons");

When you are finished reviewing the sketch and have finished making the necessary config changes, upload the sketch to your HUZZAH using the Arduino IDE. You should also open up your Adafruit IO dashboard so you can monitor the Remote Buttons gauge.

Let's test this thing out now.

This guide was first published on Oct 11, 2015. It was last updated on Sep 29, 2015.

This page (LED Code) was last updated on Jun 04, 2018.

Text editor powered by tinymce.