IoT Project Using ESP32 Alexa With OTA WiFi Update
by techstudycell in Circuits > Microcontrollers
1240 Views, 7 Favorites, 0 Comments
IoT Project Using ESP32 Alexa With OTA WiFi Update
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:
- Update WiFi credentials to ESP32 through OTA using the ESP BLE Provisioning app.
- Control home appliances with Alexa (voice control).
- Control home appliances with an IR Remote.
- Control home appliances with manual switches.
- Monitor real-time feedback in the Amazon Alexa app
- 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
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
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
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 Remote, manual 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
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?
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
- Visit https://jlcpcb.com/ and Sign in / Sign up.
- Click on the QUOTE NOW button.
- Click on the "Add your Gerber file" button. Then browse and select the Gerber file you have downloaded.
- Set the required parameters like Quantity, PCB masking color, etc.
- Select the Assemble side and SMT Quantity.
- Now upload the BOM and PickAndPlace files.
- Now confirm all the components which you want to be soldered by SMT services.
- Click on the SAVE TO CART button.
Select Shipping Address and Payment Mode
- Type the Shipping Address.
- Select the Shipping Method suitable for you.
- 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
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
- Install the IRremote library in Arduino IDE
- Download the attached code, and upload it to ESP32.
- Open Serial Monitor with Baud rate 9600.
- Now, press the IR remote button.
- The respective HEX code will populate in the serial monitor.
Save all the HEX codes in a text file.
Downloads
Program ESP32 Using Arduino IDE
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
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
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
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
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.