0% found this document useful (0 votes)
7 views45 pages

Ankit Raj

The project report details the development of a Home Automation System using the ESP32 microcontroller, which allows remote control of household appliances via WiFi and Google Assistant. The system aims to enhance convenience and accessibility, particularly for individuals with mobility challenges, by enabling smartphone control of devices like lights and fans. The report includes acknowledgments, an abstract, and outlines the project's components, circuit diagrams, and operational principles.

Uploaded by

sumankr7466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views45 pages

Ankit Raj

The project report details the development of a Home Automation System using the ESP32 microcontroller, which allows remote control of household appliances via WiFi and Google Assistant. The system aims to enhance convenience and accessibility, particularly for individuals with mobility challenges, by enabling smartphone control of devices like lights and fans. The report includes acknowledgments, an abstract, and outlines the project's components, circuit diagrams, and operational principles.

Uploaded by

sumankr7466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Page 1

Page 1

A
PROJECT REPORT
ON
HOME AUTOMATION SYSTEM USING ESP32

Submitted in partial fulfillment of


the requirement for the award of the degree of

Diploma
in
Electrical Engineering

Submitted by
Name Enrollment No.
ANKIT RAJ 21011200005

Under the guidance of


Mr. Rohit Kumar Rajak
(Lecturer)

K.K. UNIVERSITY, NALANDA, BIHARSHARIF-803115


(Estd. Under Bihar Private Universities Act, 2013
vide Notification 15/M 1-38/2014-1147 dt. June 2017)
Page 2

K.K. UNIVERSITY, NALANDA, BIHARSHARIF-803115

(Estd. Under Bihar Private Universities Act, 2013


vide Notification 15/M 1-38/2014-1147 dt. June 2017)

Declaration

I, Ankit Raj (21011200005), bearing hereby certify that the Project Report

entitled “HOME AUTOMATION USING WIFI MODULE ESP32”, carried

out under the guidance of Mr. Rohit Kr. Rajak, Lecture. is submitted to

K.K University, Nalanda (Biharsharif) in partial fulfillment of the

requirements for the award of Diploma in Electrical Engineering. This is a record

of bonafide work carried out by me independently, and the results embodied in this

report have not been reproduced or copied from any source. The results embodied

in this report have not been submitted to any other Board or Institute for the award

of any other degree.

Date - Name of Student - Ankit Raj(21011200005)

Department of EE, K.K.U


Page 3

K.K. UNIVERSITY, NALANDA, BIHARSHARIF-803115

(Estd. Under Bihar Private Universities Act, 2013


vide Notification 15/M 1-38/2014-1147 dt. June 2017)

Department of Electrical Engineering

Guide’s Certificate

This is to certify that the Project entitled “HOME AUTOMATION USING

WIFI MODULE ESP32”, being submitted by Ankit Raj(21011200005),bearing

to K.K University, Nalanda (Biharsharif) in partial fulfillment of the requirements

for the award of the degree of Diploma in Electrical Engineering, is a record of

bonafide work carried out independently by him. The results of investigations

enclosed in this report have been verified and found satisfactory. The results

embodied in this report have not been submitted to any other Board or Institute for

the award of any other degree or diploma.

CHECKED BY H.O.D DEAN/PRINCIPAL

EXTERNAL EXAMINER
Page 4

ACKNOWLEDGEMENT

With great pleasure I take this opportunity to express my heartfelt gratitude


to all the persons who helped me in making this project work a success.
First of all I am highly indebted to Dean, Prof.(Dr.) Jitendra Kumar for
giving me the permission to carry out this project.
I would like to thank Mr. Kriti Raj, Asst. Prof. & Head of the Department
(EE), for giving support throughout the period of my study at KKU. I am grateful
for his valuable suggestions and guidance during the execution of this project
work.
My sincere thanks to project guide Mr. Rohit Kr. Rajak, Lecturer for
potentially explaining the entire system and clarifying the queries at every stage of
the project.
I would also thank to Mr. Madan Kumar Lab Assistant, who provided
immense support as well as answers to our queries that I kept firing on them during
the development of this application. My whole hearted thanks to the staff of KKU
who co-operated us for the completion of project in time.
Last but not the least, I express my sincere thanks to Er. Ravi Choudhary,
Chairman, K. K Group of Institutions, for his continuous encouragement.
I also thank my parents and friends who aided me in completion of the project.
Page 5

ABSTRACT

The main objective of this project is to develop a HOME AUTOMATION


SYSTEM using an ESP32S board with wifi being remotely controlled by any
google assistance. As technology is advancing so houses are also getting smarter.
Modern houses are gradually shifting from conventional switches to centralized
control system, involving remote controlled switches. Presently, conventional wall
switches located in different parts of the house makes it difficult for the user to go
near them to operate. Even more it becomes more difficult for the elderly or
physically handicapped people to do so. Remote controlled home automation
system provides a most modern solution with smart phones. In order to achieve
this, a wifi module is interfaced to the ESP32 board at the receiver end while on
the transmitter end, a GUI application on the cell phone sends ON/OFF commands
to the receiver where loads are connected. By touching the specified location on
the GUI, the loads can be turned ON/OFF remotely through this technology. The
loads are operated by ESP32 board through opto- isolators and
thyristors using triacs.
Page 6

CONTENTS
Page No

1. INTRODUCTION ……………………………………………………… 7

2. LITERATURE SURVEY ……………………………………………….. 8


3. BLOCK DIAGRAM ……………………………………………………. 9
4. CIRCUIT DIAGRAM ………………………………………………….. 11
5. NODEMCU ESP32S …………………………………………………….12
 OVERVIEW
 PIN DIAGRAM/DESCRIPTION
 FEATURES

6. 8-CHANNEL RELAY MODULE……………………………………….16


 INTRODUCTION
 PIN DIAGRAM
 PIN DESCRIPTION
 FEATURES
7. ESP32S …………………………………………………………………… 18
 INTRODUCTION
 PIN DIAGRAM
 PIN CONFIGURATION
 SPECIFICATION
 CODING
8. POWER SUPPLY ………………………………………………………37
 INTRODUCTION
 DESCRIPTION
9. FLOW CHART (PROGRAMMING)………………………………… 39
10. ADVANTAGES & APPLICATIONS………………………………… 40
11. CONCLUSION………………………………………………………… 42
12. REFERENCES …………………………………………………………43
Page 7

1. INTRODUCTION

Nowadays, we have remote controls for our television sets and other electronic
systems, which have made our lives real easy. Have you ever wondered about
home automation which would give the facility of controlling tube lights, fans and
other electrical appliances at home using a remote control? Off-course, Yes! But,
are the available options cost-effective? If the answer is No, we have found a
solution to it. We have come up with a new system called ESP32S based
Home automation using wifi & google assistant . This system is super-cost
effective and can give the user, the ability to control any electronic device without
even spending for a remote control. This project helps the user to control all the
electronic devices using his/her smartphone. Time is a very valuable thing.
Everybody wants to save time as much as they can. New technologies are being
introduced to save our time. To save people's time we are introducing Home
Automation system using wifi(ESP32S) & google assistant. With the help of this
system you can control your home appliances from your mobile phone. You can
turn on/off your home appliances within the range of Wifi.
Page 8

2. LITERATURE SURVEY

1. Home Automation System Using ESP32S Wi-Fi & Google Assistant.

Introduction
 Home automation, also known as domotics, involves the control and
automation of household systems such as lighting, heating, and appliances.
Modern home automation systems leverage Internet of Things (IoT)
technologies to enhance comfort, security, and energy efficiency. The
integration of WiFi, ESP32S microcontrollers, and voice assistants like Google
Assistant has enabled more advanced and user-friendly home automation
solutions
Overview of Key Components
 ESP32 Microcontroller*: ESP32S is a powerful, low-cost microcontroller with
integrated WiFi and Bluetooth capabilities. Its high processing power,
flexibility, and extensive library support make it ideal for IoT applications.
 WiFi Connectivity*: WiFi is a widely adopted wireless communication
technology, essential for connecting IoT devices to the internet and enabling
remote control and monitoring.
Home Automation Platforms
 Platforms like Home Assistant, OpenHAB, and Blynk provide frameworks for
integrating various smart devices. They support ESP32S and can interface with
Google Assistant, enabling unified control of home automation systems.
Voice Command Processing
 Studies highlight the use of Google Cloud's Natural Language Processing
(NLP) services to interpret and process voice commands from Google
Page 9

Assistant. These commands are then translated into actions that control the
ESP32S devices.

3. BLOCK DIAGRAM

Fig:- Block diagram home automation

DESCRIPTION

SMART PHONE
Page 10

 Used for controlling Purpose, for giving command and gain output,
for this g o o g l e a s s i s t a n t is required.

 NodeMCU Esp-32S (Wi-Fi Enable Microcontroller).

 To take input and perform operation. As per programme fed in the


Microcontroller and obtain output as per user requirement

RELAY DRIVER

 Basically the output of microcontroller is in Mili-volts so this output volt is not


sufficient to run the bulky load output.

So as to run the appliances on 230v we require an Relay module so the output


is fed to the relay module according to given input to the relay module it will
generate output and drive various appliances and load e.g. Lamp, Fan ,Tube
light ,T.V, etc.

Output
 These are the output Generated from the given input by the user The user can
set the various output sections and can gain output through any of the section
like Home appliance A for lights, Home appliance B for fans, Home appliance
C for T.V .and many more………

A PROJECT OF USE BY THIS APPLICATION

 ESP Rain Maker


 Amazon Alexa
 Google Home
Page 11

4. CIRCUIT DIAGRAM

FIG :- CIRCUIT DIAGRAM


1. Microcontroller Connections:

 Power Supply: 50 and GND to the microcontroller.

 Temperature Sensor: Connect the UCC and GND to 50 and GUD respectively.
The data pin goes to a digital input pin on the microcontroller.

 Light Sensor (LDR): Connect in series with a resistor to form a voltage divider,
with the junction connected to an analog input pin.

2. Relay Connections:

 Control Pins: Connect the relay control pins to digital output pins of the
microcontroller through transistors.
Page 12

 Relay Power: Connect the relays UCC and GND to 50 and GND.

 AC Appliance Control: Connect the common (COM) and normally open (NO)
terminals of the relay to the appliance and the mains power.

5. NODEMCU ESP32S

 The NodeMCU ESP32S is a low-cost, open-source IoT platform. Here are


some key points about it:

Microcontroller:

 It is based on the ESP32S microcontroller, which is a powerful, dual-core


processor with integrated Wi-Fi and Bluetooth

Programming:
Page 13

 The NodeMCU firmware supports the Lua scripting language, but you can
also program the ESP32S using the Arduino IDE, MicroPython, or other
development environments.

Connectivity:

 With integrated Wi-Fi and Bluetooth, it’s suitable for a wide range of IoT
applications, including home automation, wearables, and sensor networks.

FEATUR OF NODEMCU ESP32S

 Dual-Core Processor*: The ESP32 has a dual-core Tensilica LX6


microprocessor, allowing for parallel processing of tasks.

 Wi-Fi and Bluetooth*: It supports both Wi-Fi (802.11 b/g/n) and Bluetooth
(Classic and BLE), making it ideal for IoT applications.

 Low Power Consumption*: The ESP32S can operate in various power modes,
enabling it to be used in battery-powered applications.

 Rich Interface Options*: It includes interfaces such as UART, SPI, I2C, I2S,
PWM, ADC, DAC, and touch sensors.

 GPIO Pins*: The NodeMCU ESP32S has numerous General Purpose


Input/Output (GPIO) pins, which are multi-functional.

 Built-in Hall Sensor and Temperature Sensor*: It features a hall effect sensor
and an internal temperature sensor.

 Embedded Flash Memory*: Typically, the ESP32S boards come with built-in
flash memory for program storage.

 OTA Updates*: Over-the-Air (OTA) firmware updates are supported,


allowing remote updates to be deployed.

 These features make the NodeMCU ESP32S suitable for a wide range of
applications, from home automation and wearable electronic
Page 14

PIN DIAGRAM/DESCRIPTION
Page 15

NODEMCU GPIO PIN

NODEMCU ESP32S PIN NODEMCU ESP32S PIN


DEV KIT DEV KIT
D0 GPIO23 D9 GPIO32

GPIO36 D10 GPIO33


D1

D2 GPIO22 D11 GPIO19


D3 GPIO39 D12 GPIO25
D4 GPIO1 D13 GPIO18
D5 GPIO34 D14 GPIO26
D6 GPIO3 D15 GPIO27
D7 GPIO35 D16 GPIO17
D8 GPIO21 D17 GPIO14

ESP32S
NODEMCU NODEMCU ESP32S
PIN
DEV KIT DEV KIT PIN

D18 GPIO12 D23 GPIO9


D19 GPIO4 D24 GPIO15
D20 GPIOO D25 GPIO10
D21 GPIO13 D26 GPIO8
D22 GPIO2 D27 GPIO11
Page 16

6. 8-CHANNEL RELAY MODULE

INTRODUCTION
This is a 5V 8-channel relay interface board, and each channel needs a 15 driver
current. It can be used to control various appliances and equipment with large
current. It is equipped DC30V 10A. It has a standard interface that can be
controlled directly by microcontroller.

PIN DESCRIPTION
1) Input: 0-5 V
2) VCC: Positive supply voltage
3) GND: Ground
4) IN1--IN8: Relay control port
5) Output: supports various types of loads
6) Connect a load, DC 30V/10A,
Page 17

FEATURE
1. Size: 75mm (Length) * 55mm (Width) * 19.3mm (Height)
2. Weight: 61g
3. PCB Color: Blue
4. There are four fixed screw holes at each corner of the board, easy for install
and fix. The diameter of the hole is 3.1mm

5. High quality Single relay is used with single pole double throw, a common
terminal, a normally open terminal, and a normally closed terminal
6. Optical coupling isolation, good anti-interference.
7. Closed at low level with indicator on, released at high level with indicator off
8. VCC is system power source, and JD_VCC is relay power source. Ship 5V
relay by default. Plug jumper cap to use
9. The maximum output of the relay: DC 30V/10A, AC 250V/10A
Page 18

7. ESP32S

INTRODUCTION
ESP32 is the SoC (System on Chip) microcontroller which has gained massive
popularity recently. Whether the popularity of ESP32S grew because of the growth
of IoT or whether IoT grew because of the introduction of ESP32S is debatable. If
you know 10 people who have been part of the firmware development for any IoT
device, chances are that 7−8 of them would have worked on ESP32S at some
point. So what is the hype all about? Why has ESP32S become so popular so
quickly Before we delve into the actual reasons for the popularity of ESP32S, let's
take a look at some of its important specifications. The specs listed below belong
to the ESP32S WROOM 32
Secondly, the μC should be able to perform basic processing of the incoming
sensor data, sometimes at high speeds, and have sufficient memory to store the
Page 19

data. ESP32S has a max operating frequency of 40 MHz, which is sufficiently


high. It has two cores, allowing parallel processing, which is a further add-on.
Finally, its 520 KB SRAM is sufficiently large for processing a large array of data
onboard.
PIN DIAGRAM

PIN CONFIGURATION

FUNCTION DISPLAY PIN ESP32 PIN NOTE


MISO 21 19
MOSI 19 23
SCK 23 18
DC 18 02
CS 24 05
RCT 22 EN SAVE 1 GIPO PIN
T_CS 26 04
VCC (5V) 02 5V
GND 14/25 GND
T_IRQ 11 34 ESP32 INPUT ONL
Page 20

CODING
/
******************************************************************
****************
* TITLE: ESP RainMaker + IR + Manual Switch control 8 Relays using ESP32
DHT11 LDR (Real time feedback + no WiFi control)
* Click on the following links to learn more.
* YouTube Video: https://youtu.be/7knQaSuEgsU
* Related Blog : https://iotcircuithub.com/esp32-projects/
* by Tech StudyCell
* Preferences--> Aditional boards Manager URLs :
* http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://
raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/
package_esp32_index.json
*
* Download Board ESP32 (2.0.3): https://github.com/espressif/arduino-esp32
*
* Download the libraries
* IRremote Library (3.6.1): https://github.com/Arduino-IRremote/Arduino-
IRremote
* DHT Library (1.4.4): https://github.com/adafruit/DHT-sensor-library

******************************************************************
****************/

#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
#include <IRremote.h>
#include <DHT.h>
#include <SimpleTimer.h>

const char *service_name = "PROV_1234RS8";


const char *pop = "12345RS8";
Page 21

// define the Chip Id


uint32_t espChipId = 5;

// define the Node Name


char nodeName[] = "ESP32_Relay_8S";

// 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";

//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

// define the GPIO connected with Relays and switches


static uint8_t RelayPin1 = 23; //D23
static uint8_t RelayPin2 = 22; //D22
static uint8_t RelayPin3 = 21; //D21
static uint8_t RelayPin4 = 19; //D19
static uint8_t RelayPin5 = 18; //D18
static uint8_t RelayPin6 = 5; //D5
static uint8_t RelayPin7 = 25; //D25
static uint8_t RelayPin8 = 26; //D26

static uint8_t SwitchPin1 = 13; //D13


static uint8_t SwitchPin2 = 12; //D12
static uint8_t SwitchPin3 = 14; //D14
static uint8_t SwitchPin4 = 27; //D27
Page 22

static uint8_t SwitchPin5 = 33; //D33


static uint8_t SwitchPin6 = 32; //D32
static uint8_t SwitchPin7 = 15; //D15
static uint8_t SwitchPin8 = 4; //D4

static uint8_t wifiLed = 2; //D2


static uint8_t gpio_reset = 0;
static uint8_t IR_RECV_PIN = 35; // D35 (IR receiver pin)
static uint8_t DHTPIN = 16; // RX2 pin connected with DHT
static uint8_t LDR_PIN = 34; // D34 pin connected with LDR

/* Variable for reading pin status*/


// Relay State
bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay
1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay
2
bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay
3
bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay
4
bool toggleState_5 = LOW; //Define integer to remember the toggle state for relay
5
bool toggleState_6 = LOW; //Define integer to remember the toggle state for relay
6
bool toggleState_7 = LOW; //Define integer to remember the toggle state for relay
7
bool toggleState_8 = LOW; //Define integer to remember the toggle state for relay
8

// Switch State
bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;
bool SwitchState_5 = LOW;
bool SwitchState_6 = LOW;
bool SwitchState_7 = LOW;
bool SwitchState_8 = LOW;

float temperature1 = 0;
Page 23

float humidity1 = 0;
float ldrVal = 0;

DHT dht(DHTPIN, DHT11);

IRrecv irrecv(IR_RECV_PIN);
decode_results results;

SimpleTimer Timer;

//The framework provides some standard device types like switch, lightbulb, fan,
temperature sensor.
static Switch my_switch1(deviceName_1, &RelayPin1);
static Switch my_switch2(deviceName_2, &RelayPin2);
static Switch my_switch3(deviceName_3, &RelayPin3);
static Switch my_switch4(deviceName_4, &RelayPin4);
static Switch my_switch5(deviceName_5, &RelayPin5);
static Switch my_switch6(deviceName_6, &RelayPin6);
static Switch my_switch7(deviceName_7, &RelayPin7);
static Switch my_switch8(deviceName_8, &RelayPin8);
static TemperatureSensor temperature("Temperature");
static TemperatureSensor humidity("Humidity");
static TemperatureSensor ldr("LDR");

void sysProvEvent(arduino_event_t *sys_event)


{
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on
BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on
SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#endif
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
Serial.printf("\nConnected to Wi-Fi!\n");
digitalWrite(wifiLed, true);
Page 24

break;
}
}

void write_callback(Device *device, Param *param, const param_val_t val, void


*priv_data, write_ctx_t *ctx)
{
const char *device_name = device->getDeviceName();
const char *param_name = param->getParamName();

if(strcmp(device_name, deviceName_1) == 0) {

Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_1 = val.val.b;
(toggleState_1 == false) ? digitalWrite(RelayPin1, HIGH) :
digitalWrite(RelayPin1, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_2) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_2 = val.val.b;
(toggleState_2 == false) ? digitalWrite(RelayPin2, HIGH) :
digitalWrite(RelayPin2, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_3) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
Page 25

device_name, param_name);
toggleState_3 = val.val.b;
(toggleState_3 == false) ? digitalWrite(RelayPin3, HIGH) :
digitalWrite(RelayPin3, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_4) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_4 = val.val.b;
(toggleState_4 == false) ? digitalWrite(RelayPin4, HIGH) :
digitalWrite(RelayPin4, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_5) == 0) {

Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_5 = val.val.b;
(toggleState_5 == false) ? digitalWrite(RelayPin5, HIGH) :
digitalWrite(RelayPin5, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_6) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_6 = val.val.b;
(toggleState_6 == false) ? digitalWrite(RelayPin6, HIGH) :
Page 26

digitalWrite(RelayPin6, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_7) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_7 = val.val.b;
(toggleState_7 == false) ? digitalWrite(RelayPin7, HIGH) :
digitalWrite(RelayPin7, LOW);
param->updateAndReport(val);
}

} else if(strcmp(device_name, deviceName_8) == 0) {

Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");

if(strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b? "true" : "false",
device_name, param_name);
toggleState_8 = val.val.b;
(toggleState_8 == false) ? digitalWrite(RelayPin8, HIGH) :
digitalWrite(RelayPin8, LOW);
param->updateAndReport(val);
}
}
}

void readSensor(){

ldrVal = map(analogRead(LDR_PIN), 0, 4095, 10, 0);


//Serial.print("LDR - "); Serial.println(ldrVal);
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
Page 27

return;
}
else {
humidity1 = h;
temperature1 = t;
//Serial.print("Temperature - "); Serial.println(t);
//Serial.print("Humidity - "); Serial.println(h);
}
}

void sendSensor()
{
readSensor();
temperature.updateAndReportParam("Temperature", temperature1);
humidity.updateAndReportParam("Temperature", humidity1);
ldr.updateAndReportParam("Temperature", ldrVal);
}

void manual_control()
{
if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
digitalWrite(RelayPin1, LOW);
toggleState_1 = 1;
SwitchState_1 = HIGH;
my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_1);
Serial.println("Switch-1 on");
}
if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
digitalWrite(RelayPin1, HIGH);
toggleState_1 = 0;
SwitchState_1 = LOW;
my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_1);
Serial.println("Switch-1 off");
}
if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
digitalWrite(RelayPin2, LOW);
toggleState_2 = 1;
SwitchState_2 = HIGH;
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
Page 28

toggleState_2);
Serial.println("Switch-2 on");
}
if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
digitalWrite(RelayPin2, HIGH);
toggleState_2 = 0;
SwitchState_2 = LOW;
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_2);
Serial.println("Switch-2 off");
}
if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
digitalWrite(RelayPin3, LOW);
toggleState_3 = 1;
SwitchState_3 = HIGH;
my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_3);
Serial.println("Switch-3 on");
}
if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
digitalWrite(RelayPin3, HIGH);
toggleState_3 = 0;
SwitchState_3 = LOW;
my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_3);
Serial.println("Switch-3 off");
}
if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
digitalWrite(RelayPin4, LOW);
toggleState_4 = 1;
SwitchState_4 = HIGH;
my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_4);
Serial.println("Switch-4 on");
}
if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
digitalWrite(RelayPin4, HIGH);
toggleState_4 = 0;
SwitchState_4 = LOW;
my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_4);
Page 29

Serial.println("Switch-4 off");
}
if (digitalRead(SwitchPin5) == LOW && SwitchState_5 == LOW) {
digitalWrite(RelayPin5, LOW);
toggleState_5 = 1;
SwitchState_5 = HIGH;
my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_5);
Serial.println("Switch-5 on");
}
if (digitalRead(SwitchPin5) == HIGH && SwitchState_5 == HIGH) {
digitalWrite(RelayPin5, HIGH);
toggleState_5 = 0;
SwitchState_5 = LOW;
my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_5);
Serial.println("Switch-5 off");
}
if (digitalRead(SwitchPin6) == LOW && SwitchState_6 == LOW) {
digitalWrite(RelayPin6, LOW);
toggleState_6 = 1;
SwitchState_6 = HIGH;
my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_6);
Serial.println("Switch-6 on");
}
if (digitalRead(SwitchPin6) == HIGH && SwitchState_6 == HIGH) {
digitalWrite(RelayPin6, HIGH);
toggleState_6 = 0;
SwitchState_6 = LOW;
my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_6);
Serial.println("Switch-6 off");
}
if (digitalRead(SwitchPin7) == LOW && SwitchState_7 == LOW) {
digitalWrite(RelayPin7, LOW);
toggleState_7 = 1;
SwitchState_7 = HIGH;
my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_7);
Serial.println("Switch-7 on");
Page 30

}
if (digitalRead(SwitchPin7) == HIGH && SwitchState_7 == HIGH) {
digitalWrite(RelayPin7, HIGH);
toggleState_7 = 0;
SwitchState_7 = LOW;
my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_7);
Serial.println("Switch-7 off");
}
if (digitalRead(SwitchPin8) == LOW && SwitchState_8 == LOW) {
digitalWrite(RelayPin8, LOW);
toggleState_8 = 1;
SwitchState_8 = HIGH;
my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_8);
Serial.println("Switch-8 on");
}
if (digitalRead(SwitchPin8) == HIGH && SwitchState_8 == HIGH) {
digitalWrite(RelayPin8, HIGH);
toggleState_8 = 0;
SwitchState_8 = LOW;
my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_8);
Serial.println("Switch-8 off");
}
}

void ir_remote(){
if (irrecv.decode(&results)) {
switch(results.value){
case IR_Button_1:
digitalWrite(RelayPin1, toggleState_1);
toggleState_1 = !toggleState_1;

my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_1);
delay(100);
break;
case IR_Button_2:
digitalWrite(RelayPin2, toggleState_2);
toggleState_2 = !toggleState_2;
Page 31

my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_2);
delay(100);
break;
case IR_Button_3:
digitalWrite(RelayPin3, toggleState_3);
toggleState_3 = !toggleState_3;

my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_3);
delay(100);
break;
case IR_Button_4:
digitalWrite(RelayPin4, toggleState_4);
toggleState_4 = !toggleState_4;

my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_4);
delay(100);
break;
case IR_Button_5:
digitalWrite(RelayPin5, toggleState_5);
toggleState_5 = !toggleState_5;

my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_5);
delay(100);
break;
case IR_Button_6:
digitalWrite(RelayPin6, toggleState_6);
toggleState_6 = !toggleState_6;

my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_6);
delay(100);
break;
case IR_Button_7:
digitalWrite(RelayPin7, toggleState_7);
toggleState_7 = !toggleState_7;

my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
Page 32

toggleState_7);
delay(100);
break;
case IR_Button_8:
digitalWrite(RelayPin8, toggleState_8);
toggleState_8 = !toggleState_8;

my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_8);
delay(100);
break;
case IR_All_Off:
all_SwitchOff();
break;
default : break;
}
//Serial.println(results.value, HEX);
irrecv.resume();
}
}

void all_SwitchOff(){
toggleState_1 = 0; digitalWrite(RelayPin1, HIGH);
my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_1); delay(100);
toggleState_2 = 0; digitalWrite(RelayPin2, HIGH);
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_2); delay(100);
toggleState_3 = 0; digitalWrite(RelayPin3, HIGH);
my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_3); delay(100);
toggleState_4 = 0; digitalWrite(RelayPin4, HIGH);
my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_4); delay(100);
toggleState_5 = 0; digitalWrite(RelayPin5, HIGH);
my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_5); delay(100);
toggleState_6 = 0; digitalWrite(RelayPin6, HIGH);
my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_6); delay(100);
toggleState_7 = 0; digitalWrite(RelayPin7, HIGH);
Page 33

my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_7); delay(100);
toggleState_8 = 0; digitalWrite(RelayPin8, HIGH);
my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
toggleState_8); delay(100);
}

void setup()
{

Serial.begin(115200);

// Set the Relays GPIOs as output mode


pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
pinMode(RelayPin5, OUTPUT);
pinMode(RelayPin6, OUTPUT);
pinMode(RelayPin7, OUTPUT);
pinMode(RelayPin8, OUTPUT);
pinMode(wifiLed, OUTPUT);

// Configure the input GPIOs


pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(SwitchPin3, INPUT_PULLUP);
pinMode(SwitchPin4, INPUT_PULLUP);
pinMode(SwitchPin5, INPUT_PULLUP);
pinMode(SwitchPin6, INPUT_PULLUP);
pinMode(SwitchPin7, INPUT_PULLUP);
pinMode(SwitchPin8, INPUT_PULLUP);
pinMode(gpio_reset, INPUT);

// Write to the GPIOs the default state on booting


digitalWrite(RelayPin1, !toggleState_1);
digitalWrite(RelayPin2, !toggleState_2);
digitalWrite(RelayPin3, !toggleState_3);
digitalWrite(RelayPin4, !toggleState_4);
digitalWrite(RelayPin5, !toggleState_5);
digitalWrite(RelayPin6, !toggleState_6);
Page 34

digitalWrite(RelayPin7, !toggleState_7);
digitalWrite(RelayPin8, !toggleState_8);
digitalWrite(wifiLed, LOW);

irrecv.enableIRIn(); // Enabling IR sensor


dht.begin(); // Enabling DHT sensor

Node my_node;
my_node = RMaker.initNode(nodeName);

//Standard switch device


my_switch1.addCb(write_callback);
my_switch2.addCb(write_callback);
my_switch3.addCb(write_callback);
my_switch4.addCb(write_callback);
my_switch5.addCb(write_callback);
my_switch6.addCb(write_callback);
my_switch7.addCb(write_callback);
my_switch8.addCb(write_callback);

//Add switch device to the node


my_node.addDevice(my_switch1);
my_node.addDevice(my_switch2);
my_node.addDevice(my_switch3);
my_node.addDevice(my_switch4);
my_node.addDevice(my_switch5);
my_node.addDevice(my_switch6);
my_node.addDevice(my_switch7);
my_node.addDevice(my_switch8);
my_node.addDevice(temperature);
my_node.addDevice(humidity);
my_node.addDevice(ldr);

Timer.setInterval(2000);

//This is optional
RMaker.enableOTA(OTA_USING_PARAMS);
//If you want to enable scheduling, set time zone for your region using
setTimeZone().
//The list of available values are provided here
https://rainmaker.espressif.com/docs/time-service.html
Page 35

// RMaker.setTimeZone("Asia/Shanghai");
// Alternatively, enable the Timezone service and let the phone apps set the
appropriate timezone
RMaker.enableTZService();
RMaker.enableSchedule();

//Service Name
for(int i=0; i<17; i=i+8) {
espChipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}

Serial.printf("\nChip ID: %d Service Name: %s\n", espChipId, service_name);

Serial.printf("\nStarting ESP-RainMaker\n");
RMaker.start();

WiFi.onEvent(sysProvEvent);
#if CONFIG_IDF_TARGET_ESP32
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE,
WIFI_PROV_SCHEME_HANDLER_FREE_BTDM,
WIFI_PROV_SECURITY_1, pop, service_name);
#else
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP,
WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop,
service_name);
#endif

my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch5.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch6.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
my_switch7.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
Page 36

my_switch8.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
false);
}

void loop()
{
// Read GPIO0 (external button to reset device
if(digitalRead(gpio_reset) == LOW) { //Push button pressed
Serial.printf("Reset Button Pressed!\n");
// Key debounce handling
delay(100);
int startTime = millis();
while(digitalRead(gpio_reset) == LOW) delay(50);
int endTime = millis();

if ((endTime - startTime) > 10000) {


// If key pressed for more than 10secs, reset all
Serial.printf("Reset to factory.\n");
RMakerFactoryReset(2);
} else if ((endTime - startTime) > 3000) {
Serial.printf("Reset Wi-Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
}
}
delay(100);

if (WiFi.status() != WL_CONNECTED)
{
//Serial.println("WiFi Not Connected");
digitalWrite(wifiLed, false);
}
else
{
//Serial.println("WiFi Connected");
digitalWrite(wifiLed, true);
if (Timer.isReady()) {
//Serial.println("Sending Sensor Data");
sendSensor();
Timer.reset(); // Reset a second timer
}
Page 37

ir_remote(); //IR remote Control


manual_control();
}

8. POWER SUPPLY

INTRODUCTION

Today almost every electronic device needs a DC supply for its s


mooth operation and operated within certain power supply limits. This required
DC voltage
or DC supply is derived from single phase ac mains.

A regulated power supply can convert unregulated an AC (alternating current or


voltage) to a constant DC (direct current or voltage).
A regulated power supply is used to ensure that the output remains constant even if
the input changes. A regulated DC power supply is also called as a linear power
supply, it is an embedded circuit and consists of various blocks.
Page 38

The regulated power supply will accept an AC input and give a constant DC
output.
So we have Powered the Kit/ set-up with the Adaptor Which gives exact 5V output
voltage we have used the micro-type USB cables for connection of Controller with
Adaptor.

DESCRIPTION

The basic building blocks of a regulated DC power supply are as follows:


1. A step down transformer
2. A rectifier
3. A DC filter
4. A regulator

Step Down Transformer


A step down transformer will step down the voltage from the ac mains to the
required voltage level. The turn’s ratio of the transformer is so adjusted such as to
obtain the required voltage value. The output of the transformer is given as an
input to the rectifier circuit.

Rectification
Rectifier is an electronic circuit consisting of diodes which carries out the
rectification process. Rectification is the process of converting an alternating
voltage or current into corresponding direct (DC) quantity. The input to a rectifier
is ac whereas its output is unidirectional pulsating DC. Usually a full wave rectifier
or a bridge rectifier is used to rectify both the half cycles of the ac supply (full
wave rectification). Figure below shows a full wave bridge rectifier.'
DC Filtration
The rectified voltage from the rectifier is a pulsating DC voltage having very high
ripple content. But this is not we want, we want a pure ripple free DC

Regulation
This is the last block in a regulated DC power supply. The output voltage or
current will change or fluctuate when there is change in the input from ac mains or
due to change in load current at the output of the regulated power supply or due to
other factors like temperature changes. This problem can be eliminated by using a
regulator.
A regulator will maintain the output constant even when changes at the input or
any other changes occur. Transistor series regulator, Fixed and variable IC
regulators or azener diode operated in the zener region can be used depending on
their applications. IC’s like 78XX and 79XX are used to obtained fixed values of
Page 39

voltages at the output. waveform. Hence a filter is used. Different types of filters
are used such as capacitor filter, LC filter, Choke input filter, π type filter.

9. FLOW CHART
Page 40

10. ADVANTAGES & APPLICATIONS

 Home automation, also known as smart home technology, offers a wide


range of advantages and applications. Here are some key benefits
and practical uses:
Advantages of Home Automation

 Convenience and Comfort: Control home devices remotely via smartphones


or voice assistants.Schedule devices to operate automatically (e.g., lights
turning on at sunset).
 Energy Efficiency: Optimize energy usage with smart thermostats, lighting,
and appliances.Reduce utility bills by monitoring and managing
energy consumption.
 Enhanced Security: Monitor homes in real-time with smart cameras and
doorbells.Receive instant alerts for unusual activities or security breaches.
 Accessibility: Assist elderly and disabled individuals with voice commands
and automated tasks.Improve independence and quality of life with tailored
automation solutions.
 Cost Savings: Reduce energy consumption, leading to lower utility
bills.Prevent damage with smart leak detectors and maintenance alerts.
Applications of Home Automation

 Lighting Control: Automated lighting schedules and scenes.Motion-activated


lights for enhanced security and convenience.
Page 41

 Appliance Control: Smart appliances like refrigerators, ovens, and washing


machines.Remote operation and monitoring of appliance status.
 Energy Management:Smart meters and energy usage analytics.Integration
with renewable energy sources like solar panels.
 Home Maintenance: Smart irrigation systems for gardens.Leak detectors and
automated water shutoff valves.
 Voice Assistants: Control home devices through voice commands (e.g.,
Amazon Alexa, Google Assistant).Integration with other smart home devices
for seamless operatio
Page 42

11. CONCLUSION

 The home automation project utilizing the ESP32S has successfully


demonstrated the potential and feasibility of integrating smart technology into
residential environments. Throughout the project, we aimed to create a cost-
effective, scalable, and user-friendly home automation system that could
control various household devices remotely.

Key findings from this project include:

1. *Cost-Effectiveness and Accessibility*: The ESP32S microcontroller proved


to be a highly affordable and versatile solution for home automation. Its built-in
Wi-Fi capabilities enabled seamless connectivity and control over household
devices without the need for additional expensive hardware.

2. *Ease of Implementation*: The integration of various sensors and actuators


with the ESP32S was straightforward, thanks to its extensive documentation and
community support. This facilitated rapid prototyping and iterative development.

3. *Scalability and Flexibility*: The modular nature of the ESP32S system allows
for easy expansion. Additional devices and sensors can be added to the network
without significant modifications to the existing infrastructure. This makes the
system highly adaptable to different home automation
Page 43

12. REFERENCES

Home automation system by make a porject using are where?

1. BUY a kit ESP32 in amazon.


 Site link:-: https://amzn.to/331pohb
2. BUY A REES52 DC 5V 8 Channel Relay Module.

 https://amzn.to/3mTWyVZ
3. Code for the ESP32 TO project with ESP32
 https://iotcircuithub.com/esp-rainmak..
4. PCB Gerber File of ESP32 control 8 relays:

 .: https://drive.google.com/uc?export=do...
5. Just ask Google Assistant, "Hey Google, turn off lights", or "Alexa,

turn on light". that's it.

 . #iotprojects #esp32 #homeautomation


6. Where are brought using a matrials in a project

 HTTP://maps.app.goo.gl/edoeWoyBPL1mznHW8
Page 44

You might also like