Summary

This section describes the control of NodeMCU via ‘ Amazon echo ‘. The following describes the control of devices connected from basic LED control to a wide range through the voice. These attempts are considered to be very valuable because in the future control of various devices via voice will become popular. Finally, the information has been extracted from ‘ Instructable.com’.

Introduction

 

23

What we will explore on this tutorial, is how to use Alexa, an intelligent personal assistant developed by Amazon Lab126, made popular by the Amazon Echo and Echo-Dot.

Alexa is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic, and other real time information. Alexa can also control several smart devices using itself as a home automation hub. We will use on this project, the “Echo-Dot”, that allows users to activate the device using a wake-word (such as “Alexa”).

In the home automation space, Alexa can interact with several different devices as Philips Hue, Belkin Wemo, SmartThings, etc. In our case, we will emulate the WeMo.

WeMo is a series of products from Belkin International, Inc. that enables users to control home electronics from anywhere. The product suite includes a switch, motion sensor, Insight Switch, light switch, camera and app. The WeMo Switch (our case here) can be plugged into any home outlet, which can then be controlled from an iOS or Android smartphone running the WeMo App, via home WiFi or mobile phone network.

The above block diagram shows what will be developed on our project.

 

Bill of Material (BoM)

(All values are referencial in USD)

  1. NodeMCU ESP8266-12E ($8.79)
  2. Echo Dot (2nd Generation) – Black ($49.99)
  3. Mini BreadBoard ($1.00)
  4. 400-point Experiment Breadboard Breadboard ($ 4.97)
  5. 4-Channel Relay Module ($8.49)
  6. LEDs (Red and Green) ($1.00)
  7. 2 x Resistor (220 ohm)
  8. 5V 2 Terminals Electronic Continuous Sound Buzzer ($1.00)
  9. Male-Female Dupont Cables ($1.00)
  10. DC 5V 0.2A Cooling Fan ($4.00)
  11. External 5V power Supply or battery

 

WeMo Emulation

4

In the article: HOW TO MAKE AMAZON ECHO CONTROL FAKE WEMO DEVICES, wrote by Rick Osgut you can learn the bases of WeMo emulation.

The WeMo devices use UPnP to perform certain functions over the network. The device detection function starts out with the Echo or Dot (in our case here, the Dot) searching for WeMo devices using UPnP. The device then responds to the Dot with the device’s URL using HTTP over UDP. The Dot then requests the device’s description using that HTTP URL. The description is then returned as an HTTP response.
The actual “on/off” functionality of the WeMo devices is simpler since the Dot already knows about the device. The Dot simply connects to the WeMo over the HTTP interface and issues a “SetBinaryState” command. The WeMo then obliges and returns a confirmation via HTTP. See the Echo/Dot Communication diagram above.

Another great source of information used to built the project were the post: Building an IoT power switch with the ESP8266 (and control it with your Amazon Echo!) by Wai Lun and the GitHub depository: Amazon Alexa + WeMos switch made with Arduino D1 Mini by Aruna Tennakoon.

And finally, I learned a lot from Christopher Kuzma and his projects using NodeMCU. Staring from his code and changing some parts with I learned from the other sites, I finished with a test code that you can download from my GitHib : Alexa_LED_Control_V2_EXT.ino

Verify if you have all necessary libraries to run the code, like: ESP8266WiFi.hESP8266WebServer.h and WiFiUdp.h. You can get them here: Arduino core for ESP8266 WiFi chip.

5

6            7

8

 

 

For our first test, let’s connect a LED at NodeMCU pin D1 as shown at above diagram.

Open the file Alexa_LED_Control_V2_EXT.ino that you downloaded from my GitHub and change the dummy wifi credentials, with your own:

Confirm that you have properly defined the pin where the LED is connect and give a name for your device:

In my case, the device will be named “Lights“. Here in this example is a single LED, but could be connected to a relay that will turn on the lights of my office.

Upload the code to your NodeMCU.

On Serial monitor you can see the message “Connecting to UDP” and “Connection Successful”. This means that from NodeMCU’s side it all OK.

Now, let’s ask to Alexa to find your device. There are 2 methods to do it:

  1. Using the Alexa App in your Smartphone as shown on the photos. In our case, Alexa will find “1 Smart Home device”: lights WeMo Switch.
  2. Asking Alexa to do it directly using voice command, like: “Alexa, Find connected devices” as shown at the video below:

Working With Multiple Devices

910

 

Let’s go deeper and develop a more realistic circuit with multiple devices that can be used with home automation.

We will use a 4 Channel relay module to control 2 lamps and 2 outlets. This segment of the project was based on the great tutorial post by Charles Gantt, How To: DIY Home Automation With NodeMCU and Amazon Alexa.

Follow the below instructions:

Connect the Relays inputs with NodeMCU’s pins as bellow:

Our “smart devices” will be 2 fixed Lamps and 2 general Outlets. As you saw on the previous steps, we must emulate “WeMo Devices” and to do that we must name them as below:

  • Light One
  • Light Two
  • Outlet One
  • Outlet Two

Next we must define them in our code, so Alexa can understand it. We will also define 2 commands (on and off) and one Port number for each device.

The general format should be:

Now, you must define the 2 functions related with each device condition:

For Lights:

And for Outlets:

In my case here I choose to test the 4 WeMo smart switches with devices powered with external 5 VDC. Once we have relays, we could have any type of real devices as TVs, refrigerators, etc.

  • As “Light 1″, we will use a Red LED
  • As “Light 2″, we will use a GREEN LED
  • As Outlet 2, we will use a small buzzer (you can imagine a Radio or a TV! 😉
  • As Outlet 1, we will use a small 5V fan

Follow the above electrical diagram to finish the HW connection.

Download the complete code: NODEMCU_ALEXA_WeMos_4X_Serial_Monitor_EXT.inofrom my GitHub.

Change the dummy wifi credentials, with your own:

And that’s it!.

Follow the same procedure as defined on previous step to let Alexa find your 4 devices.

The video below shows a demo of this step:

Thank you for reading it.