IoT Project Using ESP32 Alexa With OTA WiFi Update

by techstudycell in Circuits > Microcontrollers

1023 Views, 7 Favorites, 0 Comments

IoT Project Using ESP32 Alexa With OTA WiFi Update

esp32 alexa home automation p14.png
esp32 alexa home automation p15.png
esp32 alexa home automation p3.png
insta1.jpg
IoT based projects using ESP32 Alexa Home Automation | Enter WiFi Credentials Over the Air

In this IoT project, I have shown how to make IoT-based ESP32 Home Automation using Alexa, IR remote, and switches to control a 4-channel relay module with and without the internet. If the internet is unavailable, you can control the home appliances from IR remote & manual switches.

You can also update the WiFi credentials through OTA using the ESP BLE Provisioning app.

During the article, I have shown all the steps to make this home automation system.

This ESP32 control relay module has the following features:

  1. Update WiFi credentials to ESP32 through OTA using the ESP BLE Provisioning app.
  2. Control home appliances with Alexa (voice control).
  3. Control home appliances with an IR Remote.
  4. Control home appliances with manual switches.
  5. Monitor real-time feedback in the Amazon Alexa app
  6. Control home appliances manually without internet from IR remote and switches.

If you don't want to use any PCB, you can also make this IoT project using a 4-channel relay module, ESP32, and IR receiver sensor.

Supplies

vlcsnap-2023-09-05-20h12m16s858.png

Required Components (without PCB) for the ESP32 project.

  • 1. ESP32 DEV KIT V1   
  • 2. 4-channel 5V SPDT Relay Module
  • 3. TSOP1838 IR receiver (with metallic casing)
  • 4. Switches
  • 5. Amazon Echo Dot


Required Components (for PCB)

  • ESP32 DEVKIT
  • TSOP1838 IR receiver
  • Relays 5v (SPDT) (4 no)
  • BC547 Transistors (4 no)
  • PC817 Optocuplors (4 no)
  • 510-ohm 0.25-watt Resistor (4 no) (R1 - R4)
  • 1k 0.25-watt Resistors (6 no) (R5 - R11)
  • LED 5-mm (6 no)
  • 1N4007 Diodes (4 no) (D1 - D4)
  • Push Buttons (4 no) or Switches
  • Terminal Connectors
  • Any Alexa devices like ECHO DOT

Circuit Diagram of the ESP32 Projects

esp32 alexa home automation p8.png

The circuit is very simple, I have used the GPIO pins D23, D22, D21 & D19 to control the 4 relays.

The GPIO pins D13, D12, D14 & D27 are connected with switches to control the relays manually.

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

IR remote receiver (TSOP1838) connected with D35.

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

Please take proper safety precautions while working with high voltage.

Testing the Circuit Before Designing the PCB

esp32 alexa home automation p4.png
esp32 alexa home automation p5.png
esp32 alexa home automation p7.png

Before designing the PCB, I made the complete circuit using ESP32, a 4-channel relay module, IR receiver, and manual switches.

As you can see, the relay can be controlled from the IR Remotemanual switches, and Amazon Alexa App.

In the following steps, I have explained the complete projects in detail and also shared the code and PCB Garber file.

Download the code for this project.

Design the PCB for This Home Automation System

vlcsnap-2023-09-05-18h09m24s958.png
vlcsnap-2023-09-05-18h08m48s767.png
vlcsnap-2023-09-05-18h09m17s614.png

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

You can download the PCB Gerber, BOM, and "pick and place" files of this ESP32 control relay PCB from the following link:

GitHub link to Download PCB Gerber File


For this project, I have the JLC SMT Service while ordering the PCB.

Why You Should Use JLC SMT Service?

vlcsnap-2023-09-05-18h09m04s170.png

On JLCPCB's one-stop online platform, customers enjoy low-cost & high-quality & fast SMT service at an $8.00 setup fee($0.0017 per joint).

$27 New User coupon & $24 SMT coupons every month.

Visit https://jlcpcb.com

JLCPCB SMT Parts Library 200k+ in-stock components (689 Basic components and 200k+ Extended components)

Parts Pre-Order service https://support.jlcpcb.com/article/164-what-is-jlcpcb-parts-pre-order-service

Build a Personal library Inventory, save parts for now or the future

Assembly will support 10M+ parts from Digikey, Mouser.

Steps to Order the PCB Assembly From JLCPCB

vlcsnap-2023-09-05-18h09m55s307.png
vlcsnap-2023-09-05-18h10m06s587.png
vlcsnap-2023-09-05-18h10m22s694.png
vlcsnap-2023-09-05-18h10m30s134.png
vlcsnap-2023-09-05-18h10m41s613.png
  1. Visit https://jlcpcb.com/ and Sign in / Sign up.
  2. Click on the QUOTE NOW button.
  3. Click on the "Add your Gerber file" button. Then browse and select the Gerber file you have downloaded.
  4. Set the required parameters like QuantityPCB masking color, etc.
  5. Select the Assemble side and SMT Quantity.
  6. Now upload the BOM and PickAndPlace files.
  7. Now confirm all the components which you want to be soldered by SMT services.
  8. Click on the SAVE TO CART button.

Select Shipping Address and Payment Mode

JLC6.jpg
vlcsnap-2023-09-05-18h09m17s614.png
vlcsnap-2023-09-06-08h54m49s429.png
vlcsnap-2023-09-06-08h55m20s608.png
  1. Type the Shipping Address.
  2. Select the Shipping Method suitable for you.
  3. Submit the order and proceed with the payment.

You can also track your order from the JLCPCB. My PCBs took 3 days to manufacture 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

get hex code p1.png

Now, to get the HEX codes from the remote, first, we have to connect the IR receiver output pin with GPIO D35.

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 ESP32.
  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.

Save all the HEX codes in a text file.

Program ESP32 Using Arduino IDE

esp32 alexa home automation p2.png
esp32 alexa home automation p9.png

Please download the code for this IoT project.

First, you have to install the required libraries. I have shared all the links in the code.

 * Download the libraries 
 * Espalexa Library (2.7.0): https://github.com/Aircoookie/Espalexa
 * IRremote Library (3.6.1): https://github.com/Arduino-IRremote/Arduino-IRremote
 * AceButton Library (1.9.2): https://github.com/bxparks/AceButton


Then enter the Device Names for Alexa.

// device names
String Device_1_Name = "Night Lamp";
String Device_2_Name = "Room Light";
String Device_3_Name = "Studio Light";
String Device_4_Name = "Toilet Light";


Update the HEX codes for IR Remote Buttons

//Update the HEX code of IR Remote buttons 0x<HEX CODE>
#define IR_Button_1  0x1FEE01F
#define IR_Button_2  0x1FE10EF
#define IR_Button_3  0x1FE906F
#define IR_Button_4  0x1FE50AF
#define IR_All_On   0x1FE807F
#define IR_All_Off  0x1FE48B7


In the code, I have used WiFiProv.h library to reset the WiFi credentials from mobile using the ESP BLE Provisioning app.

After doing these changes, go to Tools and select the board as "ESP32 Dev Module", Partition Scheme as "Huge APP (3MB...)" and the proper PORT in Arduino IDE.

Then click on the upload button to program the ESP32 board.

Generate the QR Code to Update WiFi Details

esp32 alexa home automation p10.png
vlcsnap-2023-09-05-20h59m38s686.png

After uploading the code, open the serial monitor with Baud rate 115200. Then press the boot button of ESP32 for 5 seconds.

A QR code will appear in the serial monitor, then copy the QR code and paste in Notepad++ or any other IDE.

Enter WiFi Credentials to ESP32

esp32 alexa home automation p15.png
vlcsnap-2023-09-05-23h36m59s980.png

Now turn on the Bluetooth and GPS on your mobile, then scan the QR code using the ESP BLE Provisioning app.

Enter the WiFi credentials (WiFi Name and Password) and submit.

The ESP BLE Provisioning app will send the WiFi credentials to ESP32 through BLE. The ESP32 will connect to that WiFi and the inbuilt blue LED will turn on.

Configure the Alexa App for the Smart Home System

setup amazon alexa p1.jpg
esp32 alexa home automation p11.png

While configuring the Amazon Alexa App, the ESP32, Amazon Echo Dot and the smartphone should be connected to same the WiFi network.


Open the Amazon Alexa App and follow the steps:

1. Tap on Devices. Then Tap on the "+" icon.

2. Tap on "Light", then select "Others".

3. Select WiFi.

4 . Tap on "DISCOVER DEVICES". (It will take a minute to add devices.)

5. Tap on "Devices", and tap on "Lights" to see all the devices.


Once the Alexa App finds all the devices, you can control those devices with voice commands using the Alexa Echo Dot.

Control Relays With Alexa and IR Remote

esp32 alexa home automation p12.png
esp32 alexa home automation p13.png
esp32 alexa home automation p14.png

Now you can control the relays with voice commands using Alexa. Or if the WiFi is not available, you can control the relays with the IR remote and manual switches.

**After adding the devices to the Amazon Alexa app, only the Echo Dot and ESP32 must be connected with the same WiFi. Your mobile can be connected to any different network.

If the WiFi is available, you can also monitor the real-time feedback on the Amazon Alexa app.

I hope you have liked this Alexa 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.