ESP32 project with preferences

ESP32 Project with Alexa & Google Home using ESP RainMaker

ESP32 Project to control 8 relays with Google Assistant, Alexa, IR remote & switch. Remember the last GPIO state (EEPROM). Circuit + Code.

In this ESP32 project, I have explained how to make home automation using ESP RainMaker to control 8 relays with Google Assistant, Alexa, IR remote, and manual switches. You can also control the relays and monitor real-time feedback on Google Home and Amazon Alexa App from anywhere in the world.

It can also remember the last GPIO states after power failure. So after you restart the ESP32, the relays will turn ON/OFF automatically according to the previous state.

And you don’t need any Google Nest or Amazon Echo Dot devices for this voice control home automation project.

ESP RainMaker Home Automation

You can control the relays with IR remote and manual switches without WiFi. The ESP32 will automatically connect with the Wi-Fi if the Wi-Fi is available.

ESP32 project with preferences

For this project, I have used all the FREE tools. So if you follow all steps, you can easily make this Smart Home System with Google Assistant and Alexa to control the appliances with voice commands.

Required Components for the ESP32 project

Required Components for the ESP32 project
  • ESP32 DevKIT V1 Amazon
  • 4-channel or 8-channel 5V SPDT Relay Module Amazon
  • TSOP1838 IR receiver (with metallic casing)
  • Manual Switches or Pushbuttons Amazon
  • Amazon Echo Dot (optional) Amazon
  • Google Nest Mini (optional)

Circuits of the ESP32 Project with ESP RainMaker

Circuit of the IoT projects using ESP32
Circuit of ESP32 IoT project with Switch (Latched)

In the circuit, I have used D23, D22, D21, D19, D18, D5, D25 & D26 GPIOs to control the 8-channel relay module.

And the GPIO D13, D12, D14, D27, D33, D32, D15 & D4 are connected with switches to control the relay module manually.

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

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

As per the source code, when the control pins of the relay module receive the LOW signal the relay will turn on and the relay will turn off for the HIGH signal in the control pin.

I have used a 5V 5Amp mobile charger to supply the circuit.

Circuit of the IoT projects using ESP32 with Push-button
ESP32 IoT projects with Push-button (Momentary)

If you want to use push buttons instead of switches, you have to connect the push buttons across the GPIO pins and GND pin as shown in the above circuit.

8-ch Relay module connection

Please take proper safety precautions while connecting the appliances with the relay module.

Tutorial video on ESP32 Project with Preferences Library

In the tutorial video, I have covered the following steps in detail.

  • How to use the Preferences library to save data in ESP32 NVS flash memory.
  • Programming the ESP32 for RainMaker with Arduino IDE
  • Add devices in the ESP RainMaker app.
  • Control 8 relays with Google Home, Alexa, IR & switches.

Program ESP32 with Arduino IDE

In the Tutorial video, I explained all the steps to program the ESP32 using Arduino IDE.

  • Update the Preferences –> Additional boards Manager URLs:,
ESP32 board (Version: 2.0.3)
  • Then install the ESP32 board (Version: 2.0.3) from the Board manager or Click Here to download the ESP32 board.
  • Download the required libraries from the following links:
  • In Arduino IDE, select Board as ‘ESP32 DEV Module‘, and the Partition scheme as ‘RainMaker‘.

Source Codes for ESP RainMaker IoT Project

Click on the following buttons to download the source codes for this ESP32 project.

First, you have to upload the Code for Getting HEX codes to ESP32 and connect the IR receiver with GPIO D35.

After that, open the serial monitor, and select the Baud Rate at 115200.

Now, you have to press all the remote buttons (one by one) which you want to use to control the relays.

Now, save all the HEX codes. You have to update the main code with these HEX codes. You need 8 HEX codes to control 8 relays.

In the main sketch, update the HEX code of the IR Remote buttons (as shown in the tutorial video).

//Update the HEX code of IR Remote buttons 0x<HEX CODE>
#define IR_Button_1   0x80BF49B6
#define IR_Button_2   0x80BFC936
#define IR_Button_3   0x80BF33CC
#define IR_Button_4   0x80BF718E
#define IR_Button_5   0x80BFF10E
#define IR_Button_6   0x80BF13EC
#define IR_Button_7   0x80BF51AE
#define IR_Button_8   0x80BFD12E
#define IR_All_Off    0x80BF3BC4

And if you want you can also change the device names. Google and Alexa will identify the devices with these names.

// define the Device Names
char deviceName_1[] = "Switch1";
char deviceName_2[] = "Switch2";
char deviceName_3[] = "Switch3";
char deviceName_4[] = "Switch4";
char deviceName_5[] = "Switch5";
char deviceName_6[] = "Switch6";
char deviceName_7[] = "Switch7";
char deviceName_8[] = "Switch8";

In the code, I have used Preferences.h library to remember the last states of all the GPIO connected with relays. Please refer to the following article on the ESP32 Preferences library.

Add Devices in ESP RainMaker App

After programming, please press and hold the BOOT button for 4 seconds.

Then turn ON the mobile Bluetooth and GPS.

Scan the following QR code with your ESP RainMaker app.

QR code

Please refer to the following article to add the devices with the ESP RainMaker app.

Now, please refer to the following articles to connect the ESP RainMaker with Amazon Alexa and Google Home App.

After doing all these steps, now you control the appliances with Google Assistant and Alexa.

PCB for this ESP32 Home Automation system

To make the circuit compact, I designed a PCB for this ESP32 IoT project.

If you want, you can also use this PCB to make the circuit compact and give the project a professional look. This PCB can be used for any ESP32 Home Automation project.

About PCBWay and their services

You can order any custom design PCBs from PCBWay at very reasonable prices.

This image has an empty alt attribute; its file name is PCBWay-750x161-Banner.jpg

PCBWay not only produces FR-4 and Aluminum boards but also advanced PCBs like Rogers, HDI, Flexible and Rigid-Flex boards, at very affordable prices.
For the online instant quote page please visit –

You can also explore different PCB projects from their Open-source community

For more details please visit the following articles.
Why PCBway
PCB Capabilities
High-Quality PCB

Steps to order PCB from PCBWay

To order the PCB first visit

Step 2 to order from PCBWay

Then enter the following details:

  1. PCB Size (Length & Width) in mm & PCB quantity
  2. Select masking color for the PCB
  3. Select country and shipping method
  4. Click on the “Save to Cart” button
Step-3 to order from PCBWay

Now click on the “Add Gerber Files” to upload the PCB Gerber file.

Then click on the “Submit Order Now” to place the order.

After that, they will review the Gerber file and accordingly confirm the order.

I have used their services for my different home automation projects, I always received the PCB on time and the quality is very good in this price range.

Control Relays with ESP RainMaker App

Control Relay with ESP RainMaker

With this ESP RainMaker home automation project, you can also monitor the real-time feedback on the ESP RainMaker app.

Control relays with the Google Assistant & Alexa

Control Relays with Google Home
Control Relays with Google Home

You can control appliances with Google Assistant from anywhere in the world through the internet.

If the ESP32 is connected with WiFi, then you can also control and monitor the real-time feedback in the Google Home app.

Control Relays with Alexa
Control Relays with Alexa App

You can ask Alexa to control appliances from anywhere in the world through the internet.

And you can also control and monitor the real-time feedback on the Amazon Alexa app.

Control relays with the IR Remote & Switches

Control relays with IR Remote
Control relays with IR Remote

You can use any IR remote to control the appliances.

If the Wi-Fi is not connected, still you can control relays with the IR remote.

Control relays with switches
Control relays with switches

You can also control the appliances from manual switches or push buttons.

If the ESP32 is connected to Wi-Fi then it will send real-time feedback to the IoT server (ESP RainMaker).

I hope you like this Smart home IoT project idea with the Espressif ESP32.

Click Here for more such ESP32 projects.

Please do share your feedback on this IoT project. Thank you for your time.