Arduino Smart Home With Alexa & Google Assistant Using ESP-01 - IoT Project 2022

by techstudycell in Circuits > Arduino

17768 Views, 25 Favorites, 0 Comments

Arduino Smart Home With Alexa & Google Assistant Using ESP-01 - IoT Project 2022

vlcsnap-2022-02-10-21h57m09s894.png
vlcsnap-2022-02-10-21h57m28s396.png
Arduino Home Automation P3.jpg
Arduino ESP01 control relay PCB 6.png
Arduino Home Automation P11.jpg
Arduino IoT Project with Google Assistant & Alexa app using ESP8266 Arduino UNO WiFi control Relay

In this IoT project, I have shown how to make an IoT-based Arduino Smart Home with Google Assistant & Alexa using ESP-01 to control 4 home appliances with voice commands, IR remote, and manual switches. If the internet is not available, then you can control the home appliances from IR remote & manual switches. During the article, I have shown all the steps to make this smart home system.

This Arduino Home Automation system has the following features:

  1. Control appliances with Google Assistant.
  2. Control appliances with Alexa.
  3. Used Arduino EEPROM to remember previous states
  4. Control appliances with IR remote.
  5. Control appliances manually with switches or pushbuttons
  6. Monitor real-time feedback in the Google Home and Amazon Alexa App.
  7. Control home appliances manually without internet.
  8. All resources used for this project are FREE.

So if you follow all the steps, you can easily make this IoT project just by using Arduino UNO, ESP01, and relay module.

Although the PCB is not mandatory, I have used PCB to make the circuit compact and give the project a professional look.

Supplies

Required Components for this IoT Project (without PCB)

  • Arduino UNO
  • ESP-01
  • 1838 IR receiver (with metal case)
  • 1k, 2k, 4.7k resistors (1/4 watt)
  • 5-mm LED
  • 1117 3.3V voltage regulator
  • 4-channel 5V SPDT Relay Module
  • Switches or Push Buttons
  • FTDI232 USB to TTL
  • 5V DC supply.

Required Components for the Arduino control Relay PCB:

  • Atmega328P microcontroller
  • ESP8266 ESP01
  • PC817 Optocuplors (4 no)
  • 510-ohm 0.25-watt Resistor (4 no) (R1 -- R4)
  • 1k 0.25-watt Resistors (6 no) (R5 -- R10)
  • 2k 0.25-watt Resistor
  • 4.7k 0.25-watt Resistor
  • 10k 0.25-watt Resistors (2no)
  • 22pF ceramic capacitor
  • 104 ceramic capacitor
  • 220uF 25V Capacitor (2no)
  • 1uF Box capacitor (1no)
  • 16MHz Crystal
  • LED 5-mm (6 no)
  • 1N4007 Diodes (4 no) (D1 -- D4)
  • Push Buttons (8 no)
  • BC547 Transistors (4 no)
  • Relays 5v (SPDT) (4 no)
  • Terminal Connectors
  • Jumper (5no)
  • Switch (1no)
  • Hi-link ac-dc 220v-5v

How This Arduino IoT Project Works?

Arduino Home Automation P9.png

This Arduino ESP8266 Home Automation works in the following steps.

  1. When you ask Google assistant to control appliances, it sends the signal to the Sinric server,
  2. ESP-01 will receive the signal from the Sinric through the internet.
  3. ESP-01 sends the same signal to Arduino through the serial terminal.
  4. Arduino UNO will process that signal and accordingly turn on or off the relays.
  5. Arduino sends the feedback to ESP-01 through the Serial communication.
  6. ESP-01 sends feedback to the Sinric server through the internet.
  7. Real-time feedback can be monitored in the Google Home or Amazon Alexa app.

Circuit Diagram of the ESP01 Arduino Control Relays

Arduino control relay circuit P2.jpg

The circuit is very simple, I have used the digital pins D4, D5, D6 & D7 to control the 4 relays.

And the digital pins D10, D11, D12 & D13 are connected with switches to control the 4 relays manually.

The output pin of the IR receiver is connected with A0.

I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors.

I have used D7 as RX and D8 as TX for the serial communication with the ESP-01 module.

I have made a voltage divider using 2k and 4.7k resistors to drop down the 5volt logic level to 3.3volt logic level for the serial communication with the ESP-01 module.

If you use the momentary pushbutton then just connect the pushbutton across the digital pins and GND instead of switches.

If you use Arduino UNO then you can use the 3.3V pin instead of the 1117 3.3V regulator to supply the ESP01 but for Arduino Nano, you have to use the 1117 3.3V voltage regulator.

I have used a 5V mobile charger to supply the smart relay module.

Please take proper safety precautions while working with high voltage.

Create an Account in Sinric Pro

vlcsnap-2021-04-25-08h41m16s941.png
sinricp1.jpg
sinricp2.jpg

First, visit https://sinric.pro/

You have to create an account in Snric Pro.

Then log in to Sinric Pro Account.

You will get an APP KEY and APP SECRET for the account, which will be required in the code.

Add Room and Devices in Sinric Pro

vlcsnap-2021-04-25-08h41m32s840.png
vlcsnap-2021-04-25-08h42m54s116.png
vlcsnap-2021-04-25-08h41m48s426.png

After that add a room and give a nickname to that room (Ex: Living Room)

Then Add devices one by one and give the nickname for each device. Sinric will assign a unique device ID for each device.

Here, I have used the free Sinric Pro account, so I can add a maximum of 3 devices for free.

Testing the Circuit Before Designing the PCB

vlcsnap-2022-02-10-21h57m28s396.png
Arduino Home Automation P5.jpg
Arduino Home Automation P7.png
vlcsnap-2022-02-10-21h57m44s300.png

Before designing the PCB, I have made the circuit with Arduino UNO, ESP01, some resistors, and an IR receiver for testing all the features.

Design the PCB for This Smart Home System

Arduino ESP01 control relay PCB 1.png
Arduino ESP01 control relay PCB 2.png
Arduino ESP01 control relay PCB 3.png

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the smart relay module.

You can download the PCB Gerber file of this home automation project from the following link:

Download PCB Gerber from GitHub

Order the PCB

JLC PCB 1.jpg
JLC PCB 2.jpg
JLC 2.jpg

After downloading the Garber file you can easily order the PCB from JLCPCB.

1. Visit https://jlcpcb.com and Sign in / Sign up.

2. Click on the QUOTE NOW button.

3. Click on the "Add Gerber file" button. Then browse and select the Gerber file you have downloaded.

Uploading the Gerber File and Set the Parameters

esp01 pcb.png
JLC 4.jpg

4. Set the required parameter like Quantity, PCB masking color, etc

5. After selecting all the Parameters for PCB click on SAVE TO CART button.

Select Shipping Address and Payment Mode

JLC5.jpg
JLC6.jpg
Arduino ESP01 control relay PCB 7.png

6. Type the Shipping Address.

7. Select the Shipping Method suitable for you.

8. Submit the order and proceed with the payment. You can also track your order from JLCPCB.com.

My PCBs took 2 days to get manufactured and arrived within a week using the DHL delivery option.

PCBs were well packed and the quality was really good at this affordable price.

Get the IR Codes (HEX Code) From Remote

vlcsnap-2022-02-13-00h00m41s479.png
Get HEX code.png

Now, to get the HEX codes from the remote, first, we have to connect the IR receiver output pin with the A0 pin of Arduino UNO.
And give the 5V across the VCC and GND. The IR receiver must have a metallic casing, otherwise, you may face issues.

Then follow the following steps to get the HEX codes:

  1. Install the IRremote library in Arduino IDE.
  2. Download the attached code, and upload it to Arduino UNO.
  3. Open Serial Monitor with Baud rate 9600.
  4. Now, press the IR remote button.
  5. The respective HEX code will populate in the serial monitor.
  6. Save all the HEX codes in a text file. You have to update these HEX codes in the main sketch.

Program the ESP8266 ESP-01 With Arduino IDE

Arduino ESP01 control relay PCB 4.png
Program ESP01 with Arduino IDE.png

If you use the PCB, then you can easily go to program mode with a switch (PMOD) and directly connect the FTDI232 USB to the serial interface board with ESP-01.

Otherwise, you refer to this circuit to program the ESP-01. During programming, the GPIO-0 and GND should be connected.

First, download the attached source code & install all the required libraries mentioned in the code.
Required Arduino Libraries:

  1. Sinric Pro
  2. ArduinoJson
  3. WebSockets

Then enter the WiFi credentials:

#define WIFI_SSID "YOUR-WIFI-NAME"
#define WIFI_PASS "YOUR-WIFI-PASSWORD"

Enter the APP KEY and APP SECRET from the Sinric pro account Credential menu.

#define APP_KEY "YOUR-APP-KEY"
#define APP_SECRET "YOUR-APP-SECRET"

Enter the Device IDs from the Sinric pro account Devices menu.

#define device_ID_1 "SWITCH_ID_NO_1_HERE"
#define device_ID_2 "SWITCH_ID_NO_2_HERE"
#define device_ID_3 "SWITCH_ID_NO_3_HERE"
#define device_ID_4 "SWITCH_ID_NO_4_HERE"

Now select the "Generic ESP8266 Module" and proper PORT. Then upload the code to ESP01 Board.

After uploading the code, turn off the PMOD switch on the PCB and press the reset button.

Program the Arduino UNO or ATmega328P With Arduino IDE

vlcsnap-2022-02-06-20h06m19s222.png
Arduino ESP01 control relay PCB 5.png

In the PCB I have used an ATmega328P microcontroller, so I have used FTDI232 USB to TTL board to program the microcontroller (Refer to tutorial video).

But if you don't use PCB then you can directly connect the Arduino UNO with the laptop.

For the main sketch, you need to install following libraries

Then you have to update the HEX code in the sketch for IR remote control.

For momentary switch use the code: Code_ArduinoUNO_EEPROM_WiFi_IR_Button_4Relay.ino

and for latched switch use the code: Code_ArduinoUNO_EEPROM_WiFi_IR_Switch_4Relay.ino

Setup the Google Home App

NodeMCU-Alexa-Google-Home-Control P 3 .jpg

First, download and install the Google Home App. then follow the steps to create Home in Google Home app

  1. Tap on the "+" icon (upper left corner).
  2. Tap on Create new home.
  3. Enter the Home nickname and address.
  4. Then click on Continue.

The Home is created. Now again tap on the "+" icon to add devices.

Connect Sinric Pro With Google Home App | Add Devices

NodeMCU-Alexa-Google-Home-Control P 4 .jpg

After creating the Home in the Google Home app, you can connect the Sinric Pro with the Google Home app

  1. Tap on the "+" icon, then select Set up device.
  2. Tap on Works with Google.
  3. Search for Sinric Pro, then select Sinric Pro.
  4. Enter the email id and password used for the Sinric account,
  5. Then tap on Sign in.

Thus, all the devices from Sinric Pro will be added to Google Home Account.

Configure the Alexa App for This Smart Home System

NEW  NodeMCU-Alexa-Google-Home-Control  .jpg

Download and install the Amazon Alexa App from the Google play store or App Store.

  1. Go to "More", then select "Skills & Games".
  2. Search for Sinric Pro and tap on "Sinric Pro".
  3. Tap on "ENABLE TO USE".
  4. Log in with the Sinric account credentials.

Connecting Devices With Alexa

NodeMCU-Alexa-Google-Home-Control P 2 .jpg
  1. Tap on CLOSE.
  2. Tap on "DISCOVER DEVICES".
  3. It will take a minute to add devices. During this time the ESP-01 should be connected with the WiFi.
  4. Tap on "Devices", and tap on "Plug" to see all the devices.

Thus, all the devices from Sinric Pro will be added to Amazon Alexa App.

Controlling Relays With Google Assistant and Google Home

Arduino Home Automation P2.jpg
Arduino Home Automation P4.jpg

If the ESP01 is connected with the WiFi, then you can control the home appliances from Google Home App.

You can also ask Google Assistant to turn on and off the appliances.

You can control, monitor the real-time status of the relays in the Google Home App from anywhere in the world.

You don't need any Google Home Nest device for this home automation project.

Controlling Relays With Alexa

Arduino Home Automation P3.jpg
Arduino Home Automation P6.png

You can also control the home appliances from Amazon Alexa App if the ESP01 is connected with the WiFi.

You can also ask Alexa to turn on and off the appliances.

You can also control the appliances from the manual switches or IR remote and monitor the real-time feedback of the relays in the Amazon Alexa App from anywhere in the world.

You don't need any Echo DOT device for this home automation project.

Controlling Relays Manual Switches & IR Remote

Arduino Home Automation P10.png
Arduino Home Automation P1.jpg

If the WiFi is not available, you can control the relays from the manual switches or IR remote.

The ESP01 will check for the WiFi after every 4 seconds.

When the WiFi is available, the ESP01 will automatically connect with the WiFi.

Please refer to the circuit diagram to connect the manual switches or pushbuttons.

Now you can control your home appliances in a smart way.
I hope you have liked this Google and Alexa control home automation project. I have shared all the required information for this project.

I will really appreciate it if you share your valuable feedback. Also if you have any queries please write in the comment section.

Thank you & Happy Learning.