I’ve been working on my Arduino-Controlled humanoid robot Jeeves, and I got to thinking about Alexa.

The idea for Alexa to control an Arduino device

As you may have read on an earlier post, I build a little python app that pings a web page which in turn can issue simple on/off commands to control my Harmony Remote with Alexa. This got me started thinking about using Alexa to control an Arduino-based controller, and then in turn use Alexa as a voice portal for my robot horde.

In particular, when my humanoid creation is done, I’d like to be able to summon it via simple voice control via Alexa. For example, I say something like “Alexa, tell Jeeves to come here” and that would cause Jeeves to lumber into the living room and state “You Rang?” like Lurch did in one of the best sitcoms ever created.

So I’ve been doing a little experimentation and have come up with a way of doing exactly that.

The plan for Alexa to control an Arduino device

Basically, I start with an Arduino, attach an ethernet shield to it and connect it to the network. I program a server on the Arduino to listen for commands and do something when it gets them, and then in the pyHarmony App, I put in a string to talk to the Arduino, issuing recognizable commands, then push that off to the website, and have it tell the Arduino what to do.

Sounds pretty simple, right? Well, guess what? It Is!

In this installment, I’ll start by putting together the Arduino side of the project. It’s pretty simple and consists of an Arduino and an Ethernet Shield. You can find these at adafruit.com, here: Arduino, and here: Ethernet Shield.

To begin with, I’ll talk about crafting an Arduino program that I’ll call a listener. This is a bit of code running on the Arduino that the pyHarmony web service can actually talk to.

Basically my listener is a small server running on the network, that listens on a particular port for commands. (This is exactly what most other servers do as well. For example, a Mail Server might listen on port 110 for simple commands coming from your mail box as they relate to sending or receiving email, while a web server listens on port 80 for commands relating to fetching and processing web pages.)

In this case, we want to build a simple server that listens on a port for commands relating to telling Jeeves what to do. I’ll  start out simple, but add more commands and processes as I start assembling the various components of Jeeves.

Next time we’ll put in a “real” command, add some magic to FauxMo and pyHarmony, and get everyone talking to each other!

Using Alexa to Control an Arduino Device

The code for Alexa to control an Arduino device

Here is the beginning bits of a working server. It will send back whatever it receives! It’s not fancy, but it’s certainly an effective proof-of-concept to start with!

#include <SPI.h>
#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.

 // the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 192, 168, 1, 177 };  The ip of the arduino  
// the router's gateway address:
byte gateway[] = { 192, 168, 1, 1 };
// the subnet:
byte subnet[] = { 255, 255, 255, 0 };

// telnet defaults to port 50 - set to what you want
EthernetServer server = EthernetServer(50);

void setup()
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);

  // start listening for clients 

void loop()
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client == true) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:

Next Time

In the next installment, I’ll continue to add code make the Alexa side of the project.  Are you planning on using Alexa to control an Arduino device?  I’d love to hear your ideas on different projects to use this technology.  Share in the comments or reach out to me on Facebook!

Shopping cart

Shipping and discount codes are added at checkout.