Introduction: Alexa, Let There Be a Light.

This instructable will show you how to control a LED using Amazon Echo. Basically it is a voice activated programmable switch. You can turn on, turn off and blink the LED with Alexa Voice Services. Alexa is voice-controlled assistants similar to Apple's Siri or Google's Now.

This simple and inexpensive project demonstrates that you could add voice control capabilities to any DIY IoT project easily. Keen on adding JARVIS or KITT like interface?

Step 1: What You Will Need

First thing first, you definitely need one of Amazon Echo Family: Echo, Dot or Tap to use Alexa Voice Service. However it is not currently available outside US. So for you who live outside US or look for cheaper alternatives, you could either:

  • Build homebrew version of Amazon Echo using Raspberry Pi, or
  • Use ECHOSIM.IO, Amazon Echo Simulator that run on your browser. This is the easiest although actually it is intended for testing purposes. This project is shown using this method but it should work the same if you use the Echo Family or the homebrew version.

Then you need the following 3 internet accounts. If you don't have it, please sign-up, they are free.

  1. Amazon: https://www.amazon.com
  2. IFTTT: https://ifttt.com
  3. Adafruit IO: https://io.adafruit.com

Finally, you also need the following electronic components to construct the electronic switch hardware:

  • 1x ESP8266 Serial to Wifi Module
  • 1x 220 Ohm Resistor
  • 1x generic LED
  • 4x Dupont Pin Female to Male Jumpers
  • 2x 1.5V batteries and its holder
  • 1x Breadboard. If you are comfortable with soldering then you can get rid of this.

Wifi is required for this electronics switch to communicate to the internet as IoT device.

Step 2: Login to ECHOSIM.IO

Login to ECHOSIM.IO using your Amazon account.

If you haven't use Amazon Echo before, you may play around speaking to Alexa.

For example, say: Alexa, who are you? or Alexa, do you have a boy friend?

Don't forget to click and hold the mic icon while you are speaking.

Let's hear what's Alexa's response.

Step 3: Create IFTTT Recipes

If you are unfamiliar with IFTTT, it is an abbreviation of "If This Then That". It is a free web-based service that allows users to create chains of simple conditional statements, called "recipes", which are triggered based on changes to other web services such as Gmail, Twitter, Pinterest and including Alexa Voice Services that specifically will be used in this project.

You will use the following two IFTTT Channels:

  1. Amazon Alexa Channel:
    This channel provides simple Natural Language Classifier that maps a voice command into an action. This part acts as Trigger Channel of the "If This Then That".
  2. Adafruit Channel:
    This channel provides Internet of Thing (IoT) services to communicate with the electronic switch. This part acts as Action Channel of the "If This Then That".

This combination of trigger and action is called IFTTT recipe. There are at least 3 recipes that will be required. You can create it yourself from scratch but to make life easier, I've published the recipes that I've created so you can just copy it over.

  1. Alexa Adafruit Light On recipe:
    If you say 'Alexa, trigger light on' then it will send 'ON' data to Adafruit IO feed.
  2. Alexa Adafruit Light Off recipe:
    If you say 'Alexa, trigger light off' then it will send 'OFF' data to Adafruit IO feed.
  3. Alexa Adafruit Light Blinking recipe:
    If you say 'Alexa, trigger light blinkingf' then it will send 'BLINK' data to Adafruit IO feed.

Login to IFTTT and search for 'hendro' (my IFTTT userid). You will find the above 3 recipes. Open one of the recipes, specify the 'Feed name' that is defined in Adafruit IO (Lamp) and click 'Add'. Don't change the 'Data to save' field. Repeat the step with the other two recipes.

The first time you do this it will request you to 'Connect' to Amazon and Adafruit. This will only need to be performed once, basically it asks authorization to connect to your Amazon and Adafruit account from your IFTTT account.

Step 4: Create Adafruit IO Feed

Adafruit IO is Adafruit's Internet of Thing (IoT) service platform. IO includes client libraries that wrap the REST and MQTT APIs. For this project, you will use IO as MQTT broker. There are many IoT service platforms available in the internet but IO has advantage that it is available as IFTTT Channel.

Login to Adafruit IO using your Adafruit account. For first time user, you need to get your Adafruit IO Key, a security key that will be used by your IoT devices to communicate to IO. Click the AIO KEY button on the right hand side of the window to retrieve your key. A window will pop up with your AIO KEY. Keep a copy of this in a safe place. You'll need it later.

In this step, you will create a feed named Lamp. Feeds are the core of the Adafruit IO system. The feed holds data (say, the temperature) and metadata (such as the timestamp) about values that get pushed to Adafruit IO. In this project, Lamp feed will contain either ON, OFF or BLINK data pushed by IFTTT. In turn, Lamp feed will push the data to the electronic switch through IO MQTT message.

When you login to your Adafruit IO account, you will be redirected to the Welcome Dashboard. This dashboard is automatically created for you. In order to create a feed, you will need to click the My Dashboards button on the upper left hand side of the screen.

  • Next, click the Your Feeds link on the left hand side of the screen to navigate to the Feeds list.
  • Next, click on the Create Feed button on the right hand side of the screen.
  • A form modal will launch, and you will be presented with two text inputs:
    1. Feed's name: enter Lamp as feed's name.
    2. Description: enter any description about the feed
  • Click the Create Feed button once you have finished entering your feed's name and description. You will then be redirected to your new feed.

You then can create a new block (a widget) in the Welcome Dashboard. Creating a block is actually optional however it helps to visualize the content of the feed from the dashboard, key for testing and debugging. The block that you will create is Text block to represent the Lamp feed.

  • Navigate to Welcome Dashboard
  • Click '+' icon on the left hand side of the screen.
  • A pop up CREATE A NEW BLOCK window will appear, click the Create button on the text block category.
  • In the next window, click the Choose button on the feed selection (Lamp).
  • Next, click the Next Step button below the Choose button.
  • In the next window, click the Create Block button.

The Text block that represents your Lamp feed is created in the Welcome Dashboard. You can adjust the location and size of the block widget.

The Text block is bidirectional:

  • Output: Show data pushed by IFTTT (ON, OFF or BLINK)
  • Input: Enter data (ON, OFF or BLINK) to be pushed to the electronic switch

If you now say to Alexa: 'Alexa, trigger light on', ON will be displayed in the Lamp block. For testing only, you can type OFF in the block overriding the existing ON and it will turn off the LED (provided you also have completed Step-5 below).

Step 5: Wiring the Programmable Electronic Switch

The electronic switch is based on the popular ESP8266 serial to Wifi module. It is a micro-controller with built in Wifi adapter that makes the switch hardware needs only 4 components including the batteries. If you haven't encountered ESP8266 before, this article provides an introduction.

As shown in the attached picture, the circuit wiring is very simple and straightforward, barely needs any explanation. However, working with any micro-controller, you also need firmware and application program. Before wiring the final circuit, you need to load the attached init.lua and Alexa_light.lua scripts (after few variables modification as explained below) into your ESP8266. These lua scripts require NodeMCU firmware in the ESP8266.

I will not describe here how to load that firmware and programs into ESP8266 because it is a topic that much discussed and explained in the internet that you may be already familiar with. If you are a first time user however, you can take a look at 'Getting Started with ESP8266' for detail tutorial.

Brief description of the lua scripts:

  • init.lua:
    • This script will be automatically run at every startup, after reboot or power-on. In turn init.lua will call the main script - Alexa_light.lua.
  • Alexa_light.lua:
    • Before loading it into ESP8266, you need to modify the following variables to suit your setup:
      1. userID: Your Adafruit account name.
      2. userPWD: Your AIO key
      3. SSID: Your Wifi SSID
      4. ssidPWD: Your Wifi password
    • At startup, this script will connect to IO and subscribe to MQTT Topic: 'userID'/f/lamp. It will then just wait for any messages from IO with that Topic.
    • Based on the message that is received, GPIO-02 (pin = 4) will turn on, off or blinking in 1 second interval

Step 6: Final Words

What is shown in this Instructable is basic example of voice control, a technology that is coming into our daily life from what previously was found only in Sci-fi movies. You can of course, expand it beyond the basic shown.

You can replace the LED with a relay or solid-state switch to control electrical equipment or with solenoid or actuator to control mechanical device.

You can add the voice commands such as: blink fast, blink slow, dimmer, brighter, etc. You just need to add the IFTTT recipe and the corresponding routine in the Alexa_light.lua.

I would love to hear from you any enhancement or use case for this Instructable.

Keep tinkering and making..

LED Contest

Participated in the
LED Contest