Control Home Appliances Through Alexa With ESP8266 or ESP32




Introduction: Control Home Appliances Through Alexa With ESP8266 or ESP32

Hey, what's up, Guys! Akarsh here from CETech.

This project of mine is going to help your life become easy and you are going to feel like a king after controlling appliances in your house by just giving a command to Alexa.

The main thing behind this project is nothing but the functioning of two modules ESP8266 and Relay Module. Basically we are going to control our ESP8266 using Alexa.

Towards the end of the article, we will be doing simple connections between the ESP8266 and relay module followed by the code for connecting and controlling ESP8266 with Alexa.

Let's start with the fun now.


Step 1: Get PCBs for Your Project Manufactured

You must check out PCBGOGO for ordering PCBs online for cheap!

You get 10 good quality PCBs manufactured and shipped to your doorstep for 5$ and some shipping. You will also get a discount on shipping on your first order.

PCBGOGO has the capability of PCB assembly and stencil manufacture as well as keeping good quality standards.

Do check them out If you need to get PCBs manufactured or assembled.

Step 2: Looking at the Relay Module

The Relay Module is a convenient board which can be used to control high voltage, high current load such as lamps and AC load. It is designed to interface with a microcontroller such as Arduino, ESP8266 and etc. It comes with a LED to indicate the status of the relay. The relay modules generally have following terminals:

1. NC(Normally closed)=The normally closed configuration is used when you want the relay to be closed by default, meaning the current is flowing unless you send a signal from the Arduino to the relay module to open the circuit and stop the current

2. NO(Normally Open)=The normally open configuration works the other way around: the relay is always open, so the circuit is broken unless you send a signal from the Arduino to close the circuit.

3. Common pin=It is generally in the middle

4 Input pins=It is the pin through which relay is connected to the controlling device.

If not mentioned on module we can find out the NC pin using a multimeter in continuity setting by connecting the common with the other terminal through multimeter probes if it creates a beep sound then the pin is NC.

Step 3: Connecting ESP8266 With Relay Board

The modules can be purchased from here(Link to be added). You will definitely get some good deal here.

Connections are in two parts:

Between ESP8266 and Relay Module:

1. Connect D5 (GPIO14) pin with the input of the relay. You can connect more relay inputs as well by connecting them to other GPIO pins available.

2. Connect Vcc of the relay module to 5V/12V power supply based on your relay module.

3. Connect GND of ESP8266 with GND of relay module and then connect them to GND of power supply.

Between the Relay module and Appliance:

1. Make sure power Socket is turned off before connections.

2. Connect the common with one terminal of the socket.

3. Connect the other terminal of the socket to a terminal of the appliance.

4. Connect the other terminal of the appliance to the NO terminal of the relay.

Once this step is complete you can move over to the software part.

Step 4: Download and Setup the Arduino IDE

Download the Arduino IDE from here

1. Install the Arduino IDE and open it.

2. Go to File > Preferences

3. Add the Additional Boards Manager URLs.

4. Go to Tools > Board > Boards Manager

5. Search for esp8266 and then install the board.

6. Restart the IDE.

Step 5: Adding Additional Libraries to Arduino IDE

We will be using fauxmoESP library to control our ESP8266 using Alexa.

This library requires another library to function which is ESPAsyncTCP.

Learn about the fauxmoESP library from here. For ESPAsyncTCP head over to this page.

FauxmoESP library can be downloaded from here.

ESPAsyncTCP library can be downloaded from here.

After downloading these libraries we need to extract them and put them in the libraries folder of the Arduino IDE which can be found under the documents folder.

Step 6: Coding the Module

1. Download the code for connecting and controlling ESP8266 with Alexa from here.

2. Open the code in Arduino IDE and make the required changes to the SSID/Password at the top of the code.

3. Navigate to Tools > Board. Select the appropriate board that you are using NodeMCU(12E) works in most of the cases.

4. Select the correct comm. port by going to Tools > Port.

5. Hit the upload button.

6. When the tab says Done Uploading you are ready to use the device.

Step 7: The Relay Switches on Command to Alexa

After the code gets uploaded:

1. We can bring in the Alexa device and ask her "Alexa, discover devices".As our device initiates in the pairing mode it will be discoverable to Alexa.

2. When the discovery device screen goes off, it shows that the device is discovered and added.

3. Try it out with saying "Alexa, Turn On " in my case I have given names "Device1" and "Device 2"

You would be able to see that the relay turns on and off as we give commands to Alexa.

In this way, you can control as many home appliances as you want using a suitable relay module and making relevant changes in the code.

That's it from this demonstration!

Step 8:

Arduino Contest 2020

Participated in the
Arduino Contest 2020

Be the First to Share


    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Pets Challenge

      Pets Challenge
    • Backyard Contest

      Backyard Contest



    Question 5 months ago

    Bro this is amazing project....for trial i used the same project for my home with slightly changed codes.....I have added two nodemcu one in my living room and one in bedroom (8 on 1st nodemcu and 8 on 2nd nodemcu) .....and i can control all 16 devices with alexa....the only major challenge i see in that is whenever I try to add a group in alexa app it takes only first 8 listed devices (lights) and does not consider next 8 to form a group......individually i can control all 16 devices but i want to form a groups for master commands.......any thoughts how we can solve this


    Question 8 months ago

    Hi There
    Many thanks for this project, it works really well.
    I am trying to add an additional 2 relays (total 4), but can't seem to get it working.
    I have attached a screen shot of the additional code, I inserted in your code in the appropriate sections , but no luck.Please can you help?
    Many thanks

    Screen Shot 2020-11-12 at 6.11.35 pm.png

    Answer 8 months ago

    The code seems fine, where do you face the issue?