ESP32 Home Automation Using Arduino IoT Cloud Google Assistant

by techstudycell in Circuits > Microcontrollers

107 Views, 1 Favorites, 0 Comments

ESP32 Home Automation Using Arduino IoT Cloud Google Assistant

insta1.jpg
ESP32 Arduino IoT Cloud project p1.png
Google Assistant ESP32 based Home Automation using Arduino IoT Cloud | IoT Projects
ESP32 Arduino IoT Cloud project p331.jpg

In this IoT project, I have shown how to make an IoT-based Home Automation with Arduino IoT Cloud & Google Assistant using ESP32 to control 4 home appliances with voice commands. You can manually control the home appliances with switches and an IR remote if the internet is unavailable. During the article, I have shown all the steps to make this smart home system.

This IoT-based Home Automation system has the following features:

  1. Control appliances with Google Home and Arduino IoT Cloud Dashboard.
  2. Control the relays with the IR remote.
  3. Control appliances manually with switches.
  4. Control home appliances manually without internet.
  5. Monitor real-time feedback and room temperature in the Amazon Alexa app.
  6. All resources used for this project are FREE.

So, you can easily make this home automation project at home just by using an ESP32, DHT11 sensor, 1838 IR receiver, and relay module. Or you can also use a custom-designed PCB for this project.

Supplies

20240519_185046.jpg

You can make this project just by using ESP32, DHT11 sensor, 1838 IR receiver, and 4-channel relay module. But if you use PCB then you need the following components.

  • ESP32 DEVKIT V1
  • DHT11 sensor
  • 1838 IR receiver (with metallic case)
  • Relays 5v (SPDT) (4 no)
  • BC547 Transistors (5 no)
  • PC817 Optocuplors (4 no)
  • 510-ohm 0.25-watt Resistor (5 no) (R1 - R5)
  • 1k 0.25-watt Resistors (7 no) (R6 -- R12)
  • Hi-Link HLK-5M05 AC to DC converter.
  • LED 5-mm (7 no)
  • 1N4007 Diodes (4 no) (D1 - D4)
  • Push Buttons (1 no)
  • Terminal Connectors
  • 5V DC supply

Circuit Diagram of the ESP32 IoT Project

Circuit ESP32 Arduino IoT Cloud project p9.png

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

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

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

IR remote receiver (TSOP1838) connected with D35. And the DHT11 sensor connected with D4.

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

Please take proper safety precautions while working with high voltage.

Google Assistant Control Relay Using ESP32

ESP32.png
ESP32 Arduino IoT Cloud project p2.png

You can control the home appliances from the Google Home App or Google Assistant with voice commands and also monitor the room temperature if the ESP32 is connected to Wi-Fi.

You can also ask Google Assistant to turn on and off the appliances from anywhere in the world.

ESP32 Control Relays With Arduino IoT Cloud Dashboard

ESP32 Arduino IoT Cloud project p5.png
ESP32 Arduino IoT Cloud project p33.png

You can also monitor the room temperature and control the home appliances from the Arduino IoT Cloud web dashboard and Arduino IoT Cloud Remote mobile app if the ESP32 is connected to WiFi.

In this project, I have used the FREE plan of Arduino IoT Cloud. In the FREE plan, you can control maximum of 5 relays or sensors.

When you control the relays from the Arduino IoT Cloud Remote mobile app the current state of the relay is also updated in the Google Home app.

Control Relays With IR Remote & Switches

ESP32 Arduino IoT Cloud project p6.png
ESP32 Arduino IoT Cloud project p7.png

You can always control the relays with IR remote and switches.

I will explain how to get the IR codes (HEX codes) from any remote in the following steps.

If the ESP32 is connected to Wi-Fi, then you can also monitor the real-time feedback in the Google Home App & Arduino cloud dashboard.

When the WiFi is available, the ESP32 will automatically reconnect with the WiFi.

Design the PCB for This Smart Home System

vlcsnap-2024-06-26-16h51m01s874.png
vlcsnap-2024-06-26-16h51m36s349.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 file of this home automation project from the following link:

Download the PCB Gerber File

Steps to Order the PCB From JLCPCB

vlcsnap-2024-06-26-16h51m08s309.png
vlcsnap-2024-06-26-16h51m17s243.png
JLCPCB-color.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).

New User coupon & SMT coupons every month.

Visit https://jlcpcb.com

Currently, on JLCPCB, we have launched several promotions for multilayer PCB prototyping. We no longer have extra charges for via-in-pad on 6-20 layer PCBs.

https://jlcpcb.com/blog/42-special-offer-for-6-8-layer-high-precision-pcbs

How does JLC Via-in-pad optimize routing efficiency?

https://jlcpcb.com/6-layer-pcb


JLCPCB's newly launched Multi-color Silkscreen service, allows you to incorporate any image design you like onto your PCB.

https://jlcpcb.com/blog/653-multi-color-silkscreen-pcb

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 (For PCB Assembly).
  6. Now upload the BOM and PickAndPlace files (For PCB Assembly).
  7. Now confirm all the components you want to be soldered by SMT services (For PCB Assembly).
  8. Click on the SAVE TO CART button.


Select Shipping Address and Payment Mode

JLC6.jpg
vlcsnap-2023-09-06-08h54m49s429.png
vlcsnap-2024-06-27-10h32m37s174.png
vlcsnap-2024-06-27-10h32m41s537.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.

Create Arduino IoT Cloud FREE Account

ESP32 Arduino IoT Cloud project p10.png
ESP32 Arduino IoT Cloud project p12.png
ESP32 Arduino IoT Cloud project p13.png

For this smart house project, I have used the Arduino Cloud Free plan.

Click on the following link to create an Arduino IoT Cloud account.

https://cloud.arduino.cc/


  1. Click on "GET STARTED FOR FREE".
  2. Enter the email ID, user name, set password. Then click on "Sign Up".
  3. Click on "Create New", and select "Thing".
  4. Give a name, then click on "Rename".


Click on the Configure button under Smart Home Integration. Then select Google Home.

Add ESP32 Device in the Arduino IoT Cloud

ESP32 Arduino IoT Cloud project p14.png
ESP32 Arduino IoT Cloud project p15.png
ESP32 Arduino IoT Cloud project p16.png
ESP32 Arduino IoT Cloud project p17.png
ESP32 Arduino IoT Cloud project p18.png

Click on the Select Device on the right, then select "Set up new device".

  1. Select "Third Party device", then select device type as ESP32 and device model as DOIT ESP32 DEVKIT V1.
  2. You will get a Device ID and Secret Key which will be required in the code.
  3. Click on "Continue", You will find the device added.


Add Varriables Under Thing in Arduino IoT Cloud

ESP32 Arduino IoT Cloud project p21.png
ESP32 Arduino IoT Cloud project p22.png
ESP32 Arduino IoT Cloud project p23.png
ESP32 Arduino IoT Cloud project p24.png

Now to control 4 relays, and get reading from the DHT11 sensor, you have to add 5 variables.

Click on the "ADD VARIABLE" button.

Enter a name, then select Google-compatible light type. Variable Permission will be "Read & Write" and Variable Update Policy will be "On Change".

Similarly, you have to add the next 3 variables.

For the room temperature, reading select Google compatible Temperature Sensor. Variable Update Policy will be "Periodically", and mention the interval time.

Set Up Arduino IoT Cloud Dashboard

ESP32 Arduino IoT Cloud project p25.png
ESP32 Arduino IoT Cloud project p26.png
ESP32 Arduino IoT Cloud project p27.png
ESP32 Arduino IoT Cloud project p28.png
ESP32 Arduino IoT Cloud project p29.png

Now click on Dashboard on the top to set up the Arduino cloud dashboard.

Then click on Build Dashboard. After that click onthe EDIT icon.

Then click on ADD and select Switch.

Give a name to this Switch, then link a variable with this switch widget.

Then click on Done.

In a similar way, you have to add total 4 Switch widgets to control 4 relays.

For the temperature, select Gauge widgets and link the Temperature variable. You can also set the MIN and MAX limits.

Get the IR Codes (HEX Code) From Remote

Screenshot 2024-06-26 234803.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 the ESP32 With Arduino IDE

ESP32 Arduino IoT Cloud project p30.png
sketch1.png
code p2.png

To program the ESP32, I have used Arduino IDE.

Download the attached code.

First, you have to install the ArduinoIoTCloud library. During installation, it may ask to install other dependencies. Then click on Install All.

In the code, enter the following details.

const char DEVICE_LOGIN_NAME[] = ""; //Enter DEVICE ID
const char SSID[]        = "";  //Enter WiFi SSID (name)
const char PASS[]        = "";  //Enter WiFi password
const char DEVICE_KEY[]     = "";  //Enter Secret device password (Secret Key)


The DEVICE_LOGIN_NAME[] and DEVICE_KEY[] from the PDF that you have downloaded while adding the device to the Arduino IoT cloud.

Then update the HEX codes to control the relays from the IR remote.

switch(results.value){
          case 0x80BF49B6:  relayOnOff(1); light1 = toggleState_1; break; //update the HEX-code
          case 0x80BFC936:  relayOnOff(2); light2 = toggleState_2; break; //update the HEX-code
          case 0x80BF33CC:  relayOnOff(3); light3 = toggleState_3; break; //update the HEX-code
          case 0x80BF718E:  relayOnOff(4); light4 = toggleState_4; break; //update the HEX-code
          default : break;         
        }


I have shown all the steps in the tutorial video. After making all these changes, you can upload the code to ESP32.

Configure the Google Home App for Arduino IoT Cloud

vlcsnap-2024-06-26-17h11m45s193.png

First, download and install the Google Home App. then follow the steps:

  1. Open the Google Home app and create a Home.
  2. Then click on "+" and select "Set up device", the " works with Google".
  3. Now search for "Arduino", and log in to the Arduino IoT Cloud account.
  4. All the devices from Arduino IoT Cloud will be added to Google Home.

Now you can also control the appliances with voice commands using Google Assistant.

Finally!! the Arduino Cloud Smart Home System Is Ready

vlcsnap-2024-06-26-17h09m21s939.png

Connect the 4 home appliances with the relay module as per the circuit diagram.

Please take proper safety precautions while working with high voltage.

Now you can smartly control your home appliances.

I hope you have liked this Arduino IoT and Google Assistant home automation project. I have shared all the required information for this project.

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

Thank you & Happy Learning.