0% found this document useful (0 votes)
40 views42 pages

Main Project Final Report

The document presents a thesis on an IoT-based home automation and energy monitoring system, submitted to SASTRA Deemed to be University for the B.Tech degrees in Electronics & Communication Engineering and Mechatronics. The system utilizes an ESP32 microcontroller to enable remote control and monitoring of home appliances, promoting energy conservation and user convenience. It features real-time energy data display, automated email alerts for excessive consumption, and a user-friendly interface for managing electrical devices.

Uploaded by

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

Main Project Final Report

The document presents a thesis on an IoT-based home automation and energy monitoring system, submitted to SASTRA Deemed to be University for the B.Tech degrees in Electronics & Communication Engineering and Mechatronics. The system utilizes an ESP32 microcontroller to enable remote control and monitoring of home appliances, promoting energy conservation and user convenience. It features real-time energy data display, automated email alerts for excessive consumption, and a user-friendly interface for managing electrical devices.

Uploaded by

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

Home Automation and Energy Monitoring System using IoT

Thesis submitted to the SASTRA Deemed to be University


in partial fulfillment of the requirements
for the award of the degree of

B.Tech. ELECTRONICS & COMMUNICATION ENGINEERING

Submitted by
Vivian Akshay J
(Reg. No. 125004353),
Sam Joshua B C
(Reg. No. 125004240),

May 2025

SCHOOL OF ELECTRICAL AND ELECTRONICS ENGINEERING

THANJAVUR, TAMIL NADU, INDIA – 613 401


i
Home Automation and Energy Monitoring System using IoT

Thesis submitted to the SASTRA Deemed to be University


in partial fulfillment of the requirements
for the award of the degree of

B.Tech. MECHATRONICS

Submitted by

Ajay V
(Reg. No. 125012006)

May 2025

SCHOOL OF MECHANICAL ENGINEERING

THANJAVUR, TAMIL NADU, INDIA – 613 401

ii
SCHOOL OF ELECTRICAL AND ELECTRONICS ENGINEERING

THANJAVUR, TAMIL NADU, INDIA – 613 401

BONAFIDE CERTIFICATE

This is to certify that the thesis titled “Home Automation and Energy Monitoring System
using IoT” submitted in partial fulfillment of the requirements for the award of the degree of
B. Tech. Electrical & Electronics Engineering to the SASTRA Deemed to be University, is a
bona-fide record of the work done by Vivian Akshay J (Reg. No. 125004353), Sam Joshua
B C (Reg. No. 125004240), during the Eighth semester of the academic year 2024-25, in the
School of Electrical & Electronics Engineering, under my supervision. This thesis has not
formed the basis for the award of any degree, diploma, associateship, fellowship or other similar
title to any candidate of any University.

Signature of Project Supervisor :


Name with Affiliation : Dr. Sriranjani R, Senior Assistant Professor, SEEE
Date :
Project Viva-voce held on :

Examiner 1 Examiner 2

iii
SCHOOL OF MECHANICAL ENGINEERING

THANJAVUR, TAMIL NADU, INDIA – 613 401

BONAFIDE CERTIFICATE
This is to certify that the thesis titled “Home Automation and Energy Monitoring System
using IoT” submitted in partial fulfillment of the requirements for the award of the degree of
B. Tech. Mechatronics to the SASTRA Deemed to be University, is a bona-fide record of the
work done by Ajay V (Reg. No. 125012006) during the Eighth semester of the academic year
2024-25, in the School of Electrical & Electronics Engineering, under my supervision. This
thesis has not formed the basis for the award of any degree, diploma, associateship, fellowship
or other similar title to any candidate of any University.

Signature of Project Supervisor :


Name with Affiliation : Dr. Sriranjani R, Senior Assistant Professor, SEEE
Date :
Project Viva-voce held on :

Examiner 1 Examiner 2

iv
SCHOOL OF ELECTRICAL & ELECTRONICS ENGINEERING
THANJAVUR – 613 401

DECLARATION
We declare that the report titled “HOME AUTOMATION AND ENERGY MONITORING
SYSTEM USING IoT” submitted by me is an original work done by me under the guidance of
Dr. Sriranjani R, Senior Assistant Professor, School of Electrical and Electronics
Engineering, SASTRA Deemed to be University during the eighth semester of the academic
year 2024-25, in the School of Electrical and Electronics Engineering. The work is original
and wherever I have used materials from other sources, I have given due credit and cited them
in the text of the report. This report has not formed the basis for the award of any degree,
diploma, associateship, fellowship, or other similar title to any candidate of any University.

Name of the candidate(s): Signature of the candidate(s):

Vivian Akshay J (Reg. No. 125004353)

Sam Joshua B C (Reg. No. 125004240)

Ajay V (Reg. No. 125012006)

Date:

v
ACKNOWLEDGEMENTS

We would like to express our gratitude to Prof. R. Sethuraman, Chancellor, Prof. S.


Vaidhyasubramanian, Vice Chancellor and Dr. S. Swaminathan, Dean, Planning and
Development, SASTRA Deemed University, who provided all facilities and constant
encouragement throughout the course of the project.

We sincerely thank Prof. R. Chandramouli, Registrar, SASTRA Deemed University for


providing the opportunity to pursue this project.

It’s our privilege to express our sincerest regards to Dr. K. Thenmozhi, Dean and to all
Associate Deans of SEEE, who motivated us during the project.

We owe a debt of most profound gratitude to our guide Dr. Sriranjani R, Senior Assistant
Professor, SEEE for her valuable inputs, guidance. Her expertise and advice were incredibly
helpful throughout our project.

We also want to thank the panel members Dr. Jaiseeli C and Dr. Sumathi R for their helpful
comments

We would like to express our gratitude to our co-ordinator Dr. M. Balasubramanian, Senior
Assistant Professor, SEEE, who made it easy for us to do the project.

We would like to extend our gratitude to all the teaching and non-teaching faculties of the
School of Electrical and Electronics Engineering who have either directly or indirectly helped
us in the completion of the project.

vi
ABSTRACT
This project presents an IoT-based smart home system designed to control and monitor energy usage
in real time system. Using web server and cloud control, the system allows users to operate home
appliances remotely from a mobile or computer interface, ensuring seamless management of
electrical appliances anytime, anywhere. The core of the system is built around the ESP32
microcontroller, which continuously monitors power consumption through voltage and current
sensors. Real-time energy data is displayed on an integrated OLED screen and updated to the web
server and cloud for remote monitoring. To prevent excessive energy usage, the system features a
smart alert mechanism that sends an automated email notification via Gmail if consumption exceeds
a predefined threshold. This solution is compact, cost-effective, and user-friendly and it not only
promotes energy conservation but also provides consumers with greater control and awareness over
their electricity usage, enhances convenience and increases efficiency, contributing to smarter and
more sustainable living.

Specific Contribution

Designed and implemented the web server/cloud interface for controlling electrical appliances
remotely using ESP32.Handled the relay module integration and ensured reliable switching of
devices through the user interface.

Specific Learning

• Gained hands-on experience in building and hosting a web server/cloud-based control


system using ESP32.
• Understood how to manage GPIO-based device control over Wi-Fi.

Signature of the Guide Student Reg. No : 125004353

Name of the Guide : Dr. Sriranjani R Name : Vivian Akshay J

vii
ABSTRACT
This project presents an IoT-based smart home system designed to control and monitor energy usage
in real time system. Using web server and cloud control, the system allows users to operate home
appliances remotely from a mobile or computer interface, ensuring seamless management of
electrical appliances anytime, anywhere. The core of the system is built around the ESP32
microcontroller, which continuously monitors power consumption through voltage and current
sensors. Real-time energy data is displayed on an integrated OLED screen and updated to the web
server and cloud for remote monitoring. To prevent excessive energy usage, the system features a
smart alert mechanism that sends an automated email notification via Gmail if consumption exceeds
a predefined threshold. This solution is compact, cost-effective, and user-friendly and it not only
promotes energy conservation but also provides consumers with greater control and awareness over
their electricity usage, enhances convenience and increases efficiency, contributing to smarter and
more sustainable living.

Specific Contribution
Implemented the email alert system for power limit exceed notifications. Managed OLED display
setup to show voltage, current, power, and energy data.

Specific Learning
• Learned to automate email alerts using SMTP in ESP32.
• Understood how to display real-time power data on OLED for local monitoring.

Signature of the Guide Student Reg. No : 125004240

Name of the Guide : Dr. Sriranjani R Name : Sam Joshua B C

viii
ABSTRACT

This project presents an IoT-based smart home system designed to control and monitor energy usage
in real time system. Using web server and cloud control, the system allows users to operate home
appliances remotely from a mobile or computer interface, ensuring seamless management of
electrical appliances anytime, anywhere. The core of the system is built around the ESP32
microcontroller, which continuously monitors power consumption through voltage and current
sensors. Real-time energy data is displayed on an integrated OLED screen and updated to the web
server and cloud for remote monitoring. To prevent excessive energy usage, the system features a
smart alert mechanism that sends an automated email notification via Gmail if consumption exceeds
a predefined threshold. This solution is compact, cost-effective, and user-friendly and it not only
promotes energy conservation but also provides consumers with greater control and awareness over
their electricity usage, enhances convenience and increases efficiency, contributing to smarter and
more sustainable living.

Specific Contribution

Integrated ACS712 and ZMPT101B sensors for current and voltage measurement. Calculated real-
time power and energy consumption data from sensor inputs.

Specific Learning

• Gained hands-on experience in interfacing voltage and current sensors.


• Learned to process analog sensor data to monitor real-time energy.

Signature of the Guide Student Reg. No : 125012006

Name of the Guide : Dr. Sriranjani R Name : Ajay V

ix
SUMMARY OF THE BASE PAPER

Title: Smart Home Energy Management System using IEEE 802.15.4 and ZigBee.

Authors: Dae-Man Han and Jae-Hyun Lim


Year: 2010
URL: https://ieeexplore.ieee.org/document/5606276/

Abstract:
Wireless personal area network and wireless sensor networks are rapidly gaining popularity, and
the IEEE 802.15 Wireless Personal Area Working Group has defined no less than different
standards so as to cater to the requirements of different applications. The ubiquitous home
network has gained widespread attentions due to its seamless integration into everyday life. This
innovative system transparently unifies various home appliances, smart sensors and energy
technologies. The smart energy market requires two types of ZigBee networks for device control
and energy management. Today, organizations use IEEE 802.15.4 and ZigBee to effectively
deliver solutions for a variety of areas including consumer electronic device control, energy
management and efficiency, home and commercial building automation as well as industrial
plant management. We present the design of a multi-sensing, heating and air conditioning system
and actuation application - the home users: a sensor network-based smart light control system
for smart home and energy control production. This paper designs smart home device
descriptions and standard practices for demand response and load management "Smart Energy"
applications needed in a smart energy based residential or light commercial environment. The
control application domains included in this initial version are sensing device control, pricing
and demand response and load control applications. This paper introduces smart home interfaces
and device definitions to allow interoperability among ZigBee devices produced by various
manufacturers of electrical equipment, meters, and smart energy enabling products. We
introduced the proposed home energy control systems design that provides intelligent services
for users and we demonstrate its implementation using a real testbad.

x
LIST OF FIGURES

Figure no. List Page no.


Fig 4.1 Circuit diagram 4
Fig 4.2 Web server interface 5
Fig 4.3 Cloud interface 6
Fig 4.4 Vrms plot 7
Fig 4.5 Irms plot 7
Fig 4.6 Power plot 7
Fig 4.7 Energy plot 7
Fig 4.8 Power monitoring using 8
OLED display
Fig 4.9 Power monitoring using 8
web server
Fig 4.10 Power monitoring using 8
Blynk
Fig 4.11 Gmail alert 13
Fig 5.1 Turning on fan using web 19
server
Fig 5.2 Turning off fan using web 19
server
Fig 5.3 Turning on light using web 20
server
Fig 5.4 Turning off light using 20
web server
Fig 5.5 Turning on fan using 20
Blynk
Fig 5.6 Turning off fan using 21
Blynk
Fig 5.7 Turning on light using 21
Blynk
Fig 5.8 Turning off light using 21
Blynk
Fig 5.9 Energy monitoring using 22
OLED
Fig 5.10 Energy monitoring using 22
web server
Fig 5.11 Energy monitoring using 23
Blynk
Fig 5.12 Power consumption alert 23
through Gmail

Fig 5.13 Final compact setup (front) 24


Fig 5.14 Final compact setup (back) 24

xi
ABBREVIATIONS

a) IoT – Internet of Things

b) WiFi – Wireless Fidelity

c) ESP32 – Espressif Systems 32 bit

d) OLED – Organic Light Emitting Diode

e) RMS – Root Mean Square

f) SMTP – Simple Mail Transfer Protocol

g) HTML – Hyper Text Markup Language

h) HTTP- Hyper Text Transfer Protocol

i) URL – Uniform Resource Locator

j) GPIO – General Purpose Input/Output

k) kWh – Kilowatt hour

l) API – Application Programming Interface

m) EmonLib – Energy Monitoring Library

xii
TABLE OF CONTENTS

TITLE Page No
Bona-fide certificate iii
Declaration v
Acknowledgements vi
Abstract vii
Summary of the base paper x
List of figures xi
Abbreviations xii
Table of contents xiii
1.Introduction 1
2.Problem Statement 2
3.Literature survey 3
4. Methodology 4
4.1. Components used 4
4.2. Circuit Diagram 4
4.3. Working procedure 5
4.3.1. Web Server Control 5
4.3.2. Cloud Control 6
4.3.2.a) Blynk 6
4.3.2.b) ThingSpeak 7
4.3.3. Energy Monitoring 8
4.3.4. Calculation and Calibration for 9
Power Monitoring
4.3.4.a) Voltage sensing 9
4.3.4.b) Current Sensing 11
4.3.4.c) Power Calculation 11
4.3.4.d) Energy Calculation (kWh) 12
4.3.5. Smart Alert System 12
4.4. Code 13
5.RESULTS OBTAINED 19
5.1. Web Server Control : 19
5.2. Cloud Control : 20
5.3. Energy Monitoring 22
5.4. Smart Alert 23
5.5. Final Compact Setup 24
6.Conclusion 25
7.References 28
8.Appendix – Plagiarism Report 29

xiii
CHAPTER 1

INTRODUCTION

In the era of smart homes, the demand for efficient and user-friendly appliance management systems
has seen significant growth. Traditional methods of manually operating fans and lights often lack
the flexibility and convenience expected in modern living environments. To address these needs,
the project focuses on designing a smart home automation system capable of remotely controlling a
fan and a light through both web server and cloud platforms. Utilizing IoT technology, the system
enables users to operate appliances from virtually anywhere, offering enhanced convenience, better
energy management, and an overall improvement in user experience.

The core of the system is built around the ESP32 microcontroller, chosen for its robust processing
capabilities and inbuilt Wi-Fi support. Relays are integrated for direct control of the fan and light
circuits, while voltage and current sensors provide real-time monitoring of power consumption. Data
acquired from the sensors is processed and displayed on an OLED screen as well as sent to web
server and cloud platforms, allowing users to track appliance performance remotely. Furthermore,
the system is designed to send alerts when the monitored power consumption exceeds predefined
thresholds, thereby helping users to identify unusual usage patterns and promote efficient energy
use.

This project emphasizes the importance of combining reliable hardware components with effective
software integration to achieve seamless remote appliance management. By leveraging cloud
services alongside web server access, the system offers a dual control mechanism, enhancing
reliability even in varying network conditions. Overall, the implementation demonstrates how IoT-
based solutions can transform conventional appliance operation into a smarter, more responsive
system, paving the way for broader applications in the domain of smart living.

1
CHAPTER 2

Problem Statement

In most homes today, appliances like fans and lights are still operated manually. While this method
has been the norm for decades, it often leads to energy being wasted—especially when devices are
accidentally left running. Additionally, manual control lacks convenience, particularly in larger
homes or for users who wish to manage their appliances remotely.

Another major drawback of traditional setups is the lack of real-time energy monitoring. Without
insight into how much electricity each device uses, homeowners are unable to make informed
decisions about their energy consumption. This often results in higher utility bills and missed
opportunities for reducing environmental impact. Moreover, existing systems do not notify users
when power usage exceeds certain levels, which can pose safety risks and add to energy costs.

Given the rising need to conserve energy and reduce unnecessary consumption, there's a clear
demand for a smarter solution. This solution should make it possible to control appliances through
both a web interface and a cloud-based platform. Alongside remote control, it should also track real-
time data such as voltage, current, and overall power usage. To make the data accessible, key
information should be displayed locally on OLED screens and remotely through dashboards.
Importantly, the system should also alert users—via email or SMS—when energy usage surpasses
a defined limit, enabling timely interventions.

Implementing such a solution would not only improve user convenience by allowing remote access
but also help optimize energy use. In the long run, it supports the broader goal of building more
sustainable and intelligent living spaces that can adapt to modern energy efficiency demands.

2
CHAPTER 3

LITERATURE SURVEY

Title Journal Methodology


The Working Principles of ESP32 Conducted a comprehensive study on the
and Analytical Comparison of ESP32 microcontroller, understanding its
using Low-Cost Microcontroller architecture, features, and applications in
1 General Study Modules in Embedded Systems
on ESP32 embedded systems.
Design Husam Kareem; Dmitiy
Dunaev

Home Automation System Learned proper power connections between


Using ESP32 and Firebase ESP32, relay module, power supply, and
Interfacing a Ankit Koushal;Rahul appliances, ensuring safe and efficient
2 Relay Module Gupta;FarmanJan;Kamaldeep switching.
with ESP32 Kamaldeep;Vikram Kumar

Design of web- Developed a web-based home automation


based Smart Home with 3D system with a convenient interface. Uses
virtual reality interface sensors and web technologies for remote
3 Web server Wenshan Hu;Hong
device control and monitoring.
control Zhou;Chaoyang Lin;Xianfeng
Chen;Zhen Chen;Yiyan Lu

Home Automation System using Implemented an IoT-based home automation


Internet-of-Things & Blynk App system using ESP32 and Blynk. The system
Interfacing with Tanishka Bhala;Alok enables remote monitoring and control via a
4 Aggarwal;Shalini
blynk for cloud cloud-connected mobile application.
control Aggarwal;Kshitij Garg;Abhishek
Gupta

A Smart Survey On ElectricMeter Utilized IoT-enabled smart meters for real-


Using Iot time voltage, current, and power
5 Energy M. Dhivya;K. Valarmathi measurement. Data is processed and
monitoring transmitted to cloud platforms for remote
monitoring and analysis.

3
CHAPTER 4

METHODOLOGY

4.1. Components used :

1. ESP32 Development Board – 1 No 5. Buck-boost module (XL6009) – 1 no

2. 5V Relay Module – 2 Nos 6. OLED display – 1 no

3. Current sensor (ACS712) -1 no 7. LM 7805

4. Voltage sensor(zmpt101b) -1 no

4.2. Circuit Diagram :

Fig 4.1. Circuit diagram

4
4.3. Working procedure :

The working of the project is divided into multiple functional parts:

• Web Server Control,

• Cloud Control,

• Energy Monitoring,

• and Smart Alert System.

4.3.1. Web Server Control :

In this implementation, the ESP32 is programmed to operate as a web server through integration
with the WebServer library. After connecting to Wi-Fi, it starts a server on port 80 and creates
multiple routes (/bulb_on, /bulb_off, /fan_on, /fan_off) to control appliances. The root URL serves
a simple HTML page displaying real-time voltage, current, power, and energy (kWh) data, along
with ON/OFF buttons for the bulb and fan. User actions on the web page send HTTP GET requests,
which the ESP32 handles instantly by toggling GPIO pins. The server runs efficiently alongside
data monitoring, Blynk updates, and ThingSpeak uploads without blocking other processes. The
web server interface is shown in Fig 4.2.

Fig 4.2. Web server interface

5
4.3.2. Cloud Control

4.3.2.a) Blynk :

The project integrates Blynk IoT Cloud to enable remote control and monitoring of devices via a
mobile app. Using the BlynkSimpleEsp32 library, the ESP32 connects to Blynk Cloud with an
authentication token after establishing Wi-Fi connectivity. Virtual pins (V0 for bulb and V1 for fan)
are mapped to control the relay outputs, allowing users to switch appliances ON/OFF through the
app interface. Additionally, real-time voltage, current, power, and energy readings are sent to the
Blynk dashboard using virtual writes, enabling live data monitoring from anywhere in the world.
Blynk ensures smooth communication without interrupting local server operations. The Blynk
interface is shown in Fig 4.3.

Fig 4.3. Cloud interface

6
4.3.2.b) ThingSpeak :

The project uses ThingSpeak cloud platform to log and visualize real-time electrical parameters like
voltage, current, power, and energy consumption. After establishing Wi-Fi connectivity, the ESP32
uploads sensor readings to ThingSpeak using the API key and channel ID through HTTP requests
every 15 seconds. Each parameter is mapped to specific fields on ThingSpeak, allowing users to
monitor historical trends and live data through graphical charts. This cloud integration enhances
system transparency, helping users track power usage remotely through any web browser or mobile
device. These plots of Vrms,Irms, power and energy are shown in figures 4.4, 4.5, 4.6 and 4.7
respectively.

Fig 4.4. Vrms plot Fig 4.5. Irms plot

Fig 4.6. Power plot Fig 4.7. Energy plot

7
4.3.3. Energy Monitoring :

The system implements real-time energy monitoring by using a ZMPT101B voltage sensor and an
ACS712 current sensor interfaced with the ESP32. The measured voltage and current values are
processed using the EmonLib library to calculate true RMS voltage (Vrms), current (Irms),
instantaneous power, and accumulated energy consumption (kWh). These calculated values are
displayed locally on an OLED screen for instant feedback and also sent to cloud and web server for
remote access. Continuous monitoring ensures users can track energy usage accurately, helping in
better power management and efficiency analysis. The power monitoring using OLED,web server
and Blynk interface are shown in figures 4.8, 4.9, and 4.10 respectively.

Fig 4.8. Power monitoring using OLED display

Fig 4.9. Power monitoring using web server Fig 4.10. Power monitoring using blynk

8
4.3.4. Calculation and Calibration for Power Monitoring :

Importance of Calibration

Calibration adjusts the output to match real-world values by compensating for hardware variations
across different sensors.

4.3.4.a) Voltage sensing :

Method 1:

Objective :

To measure high AC voltages (such as 230V) safely using a microcontroller like ESP32, which can
only handle voltages between 0V and 3.3V on its analog input pins.

Approach :

A voltage sensor module (e.g., ZMPT101B) is used to scale down the high voltage to a safe
measurable value for the ESP32. The scaling is determined by a factor known as sensitivity.

Formula :

Vinput
Voutput =
sensitivity

Where:

Vinput = actual AC voltage (e.g., 230V

sensitivity = scaling factor (typical value around 500)

Voutput = reduced voltage suitable for ADC input

Example:

If Vinput = 230V and Sensitivity = 500 :

230
Voutput = =0.46V
500

Thus, 230V is scaled down to 0.46V.


9
Importance of Sensitivity :

The sensitivity value is determined by the internal design of the sensor (resistor divider, op-amp
setup). Although typically close to 500, calibration is necessary because it may vary slightly between
individual sensors.

Calculating Vrms :

2
√∑ Vsamples
Vrms =
total samples

Method 2 (Using EmonLib) :

Approach:

Using an external library like EmonLib, which simplifies the Vrms calculation internally through
calibration.

Formula :

Raw sensor value × vcalibration


Vrms =
ADCmax

Where:
• Raw Sensor Value = ADC reading (0–4095 for ESP32)

• Vcalibration = calibration constant for voltage

• ADCmax = 4095 (for 12-bit ADC)

10
4.3.4.b) Current Sensing :

Formula:

Raw sensor value × icalibration


Irms =
ADCmax

Where:
• Raw Sensor Value = ADC reading from the current sensor

• Icalibration = calibration constant for current

• ADCmax = 4095 (for 12-bit ADC)

Purpose of Current Calibration :

Like voltage calibration, current calibration ensures accurate readings despite slight manufacturing
differences in individual current sensor modules.

Example:

If the raw value is 2048 and icalibration = 30

2048 × 30
Irms = ≈ 15𝐴
4095

Thus, the measured current is approximately 15A.

4.3.4.c) Power Calculation :

Power (W)= Vrms × Irms

11
4.3.4.d) Energy Calculation (kWh) :

Method 1: Simple

Power(W) × Time(hours)
kWh=
1000

Method 2: Real-time (Using milliseconds):

Power(W) × time difference(ms)


kWh+=
3600000

Example

If Power = 100W and Time difference = 5000ms (5 seconds):

100 × 5000
kWh+= = 0.138 kWh
3600000

Thus, 0.138 kWh (units) are consumed in 5 seconds.

4.3.5. Smart Alert System :

In this project, an automatic email alert system is implemented using the ESP_Mail_Client library.
When total energy consumption (kWh) exceeds 0.3 kWh, the ESP32 trigger the sendAlert()
function. This function connects to the Gmail SMTP server securely and sends an email notification
to the user's email address. The system restricts sending to a maximum of 5 alerts to prevent
spamming. The Gmail alert is shown in Fig 4.11.

12
Fig 4.11. Gmail alert

4.4. Code :
#define BLYNK_TEMPLATE_ID "TMPL3jFh-qPNV"
#define BLYNK_TEMPLATE_NAME "Home Automation"
#define BLYNK_AUTH_TOKEN "NEXrGf03BC_ntic5ZFrheJbTw6SRF98D"

#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include "EmonLib.h"
#include <ZMPT101B.h>
#include <ESP_Mail_Client.h>
#include <BlynkSimpleEsp32.h> // Blynk Library
#include <ThingSpeak.h> // ThingSpeak Library

// WiFi credentials
const char* ssid = "vivo1902";
const char* password = "abcd1245";
WiFiClient client;
#define THINGSPEAK_CHANNEL_ID 2899257 // Replace with your ThingSpeak Channel ID
#define THINGSPEAK_API_KEY "5SH5QFBWB9RWBO0D" // Replace with your API Key

// OLED display settings


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Web server on port 80
WebServer server(80);
13
// Sensor setup
EnergyMonitor emon;
#define vCalibration 233.0
#define currCalibration 20.7

// Voltage sensor setup


#define SENSITIVITY 500.0f
ZMPT101B voltageSensor(34, 50.0);

// Relay pins
const int bulbRelayPin = 23;
const int fanRelayPin = 19;

// Blynk Virtual Pins


#define BULB_VPIN V0
#define FAN_VPIN V1

// Power variables
float Vrms, Irms, Power, kWh = 0;
unsigned long lastmillis = millis();
int mailCount = 0; // Track email count to limit to 5

// Email Configuration
#define SMTP_SERVER "smtp.gmail.com"
#define SMTP_PORT 465
#define AUTHOR_EMAIL "akshayvivianwork@gmail.com"
#define AUTHOR_PASSWORD "mpxk iezu ueky yztb"
#define RECIPIENT_EMAIL "8754156481@airtel.com"

ESP_Mail_Session session;
SMTPSession smtp;

void sendAlert() {
if (mailCount >= 5) return; // Stop sending after 5 mails

smtp.debug(1);
session.server.host_name = SMTP_SERVER;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.time.ntp_server = "pool.ntp.org";

if (!smtp.connect(&session)) {
Serial.println(" Email server connection failed.");
return;
}
SMTP_Message message;
message.sender.name = "ESP32 Alert";
message.sender.email = AUTHOR_EMAIL;
message.subject = "Power Consumption Alert!";
14
message.addRecipient("User", RECIPIENT_EMAIL);

String alertMessage = "ALERT! Power consumption exceeded 0.3 kWh.\nCurrent kWh: ";
alertMessage += String(kWh, 4);
message.text.content = alertMessage.c_str();

if (MailClient.sendMail(&smtp, &message)) {
Serial.println(" Email alert sent successfully.");
mailCount++;
} else {
Serial.println(" Email alert failed.");
}

smtp.closeSession();
}

void setup() {
Serial.begin(115200);

pinMode(bulbRelayPin, OUTPUT);
pinMode(fanRelayPin, OUTPUT);
digitalWrite(bulbRelayPin, HIGH); // Default OFF
digitalWrite(fanRelayPin, HIGH); // Default OFF

Wire.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
display.clearDisplay();

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.print("ESP32 IP Address: ");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);

// Blynk Initialization
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, password);

// Web Server Routes


server.on("/", handleRoot);
server.on("/bulb_on", turnOnBulbRelay);
server.on("/bulb_off", turnOffBulbRelay);
server.on("/fan_on", turnOnFanRelay);
server.on("/fan_off", turnOffFanRelay);
server.begin();
15
emon.voltage(35, vCalibration, 1.7);
emon.current(34, currCalibration);
voltageSensor.setSensitivity(SENSITIVITY);
}

void loop() {
server.handleClient();
Blynk.run();

Vrms = voltageSensor.getRmsVoltage();
emon.calcVI(20, 2000);
Irms = emon.Irms / 100;
Power = (Vrms * Irms);
kWh += Power * (millis() - lastmillis) / 36000000.0;

// Blynk Display for Power Data


Blynk.virtualWrite(V2, Vrms);
Blynk.virtualWrite(V5, Irms);
Blynk.virtualWrite(V4, Power);
Blynk.virtualWrite(V6, kWh);

// OLED Display
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Vrms: "); display.print(Vrms); display.println(" V");
display.setCursor(0, 10);
display.print("Irms: "); display.print(Irms); display.println(" A");
display.setCursor(0, 20);
display.print("Power: "); display.print(Power); display.println(" W");
display.setCursor(0, 30);
display.print("kWh: "); display.print(kWh, 4); display.println(" kWh");
display.display();

// Send Data to ThingSpeak Every 15 Seconds


if (millis() - lastmillis > 15000) {
ThingSpeak.setField(1, Vrms);
ThingSpeak.setField(2, Irms);
ThingSpeak.setField(3, Power);
ThingSpeak.setField(4, kWh);

int response = ThingSpeak.writeFields(THINGSPEAK_CHANNEL_ID,


THINGSPEAK_API_KEY);
if (response == 200) {
Serial.println(" Data sent to ThingSpeak successfully.");
} else {
Serial.print(" ThingSpeak Error: ");
Serial.println(response);
}
16
lastmillis = millis();
}

// Email alert for energy consumption


if (kWh >= 0.3) {
sendAlert();
}

lastmillis = millis();
}

// BLYNK CONTROL FUNCTIONS


BLYNK_WRITE(BULB_VPIN) {
int bulbState = param.asInt();
digitalWrite(bulbRelayPin, bulbState == 1 ? LOW : HIGH);
Blynk.virtualWrite(BULB_VPIN, bulbState); // Update Blynk UI
}

BLYNK_WRITE(FAN_VPIN) {
int fanState = param.asInt();
digitalWrite(fanRelayPin, fanState == 1 ? LOW : HIGH);
Blynk.virtualWrite(FAN_VPIN, fanState); // Update Blynk UI
}

// WEB SERVER CONTROL FUNCTIONS


void turnOnBulbRelay() {
digitalWrite(bulbRelayPin, LOW);
Blynk.virtualWrite(BULB_VPIN, 1);
handleRoot();
}
void turnOffBulbRelay() {
digitalWrite(bulbRelayPin, HIGH);
Blynk.virtualWrite(BULB_VPIN, 0);
handleRoot();
}
void turnOnFanRelay() {
digitalWrite(fanRelayPin, LOW);
Blynk.virtualWrite(FAN_VPIN, 1);
handleRoot();
}
void turnOffFanRelay() {
digitalWrite(fanRelayPin, HIGH);
Blynk.virtualWrite(FAN_VPIN, 0);
handleRoot();
}

// WEB SERVER INTERFACE


void handleRoot() {
String html = "<html><head><style>";
html += "body { font-family: Arial; background-color: #121212; color: #ffffff; padding: 20px;
17
text-align: center; }";
html += "h1 { color: #4CAF50; }";
html += "p { font-size: 30px; margin: 10px; }";
html += "button { font-size: 32px; padding: 20px 60px; background-color: #4CAF50; color:
white; border: none; border-radius: 5px; cursor: pointer; }";
html += "</style></head><body>";
html += "<h1>ESP32 Smart Meter</h1>";
html += "<p>Vrms: " + String(Vrms) + " V</p>";
html += "<p>Irms: " + String(Irms) + " A</p>";
html += "<p>Power: " + String(Power) + " W</p>";
html += "<p>kWh: " + String(kWh, 4) + " kWh</p>";
html += "<p>Relay Status (Bulb): " + String(digitalRead(bulbRelayPin) == LOW ? "ON" :
"OFF") + "</p>";
html += "<form action='/bulb_on' method='GET'><button>Bulb ON</button></form>";
html += "<form action='/bulb_off' method='GET'><button>Bulb OFF</button></form>";
html += "<p>Relay Status (Fan): " + String(digitalRead(fanRelayPin) == LOW ? "ON" :
"OFF") + "</p>";
html += "<form action='/fan_on' method='GET'><button>Fan ON</button></form>";
html += "<form action='/fan_off' method='GET'><button>Fan OFF</button></form>";
html += "</body></html>";

server.send(200, "text/html", html);


}

18
CHAPTER 5

RESULTS OBTAINED

5.1. Web Server Control :

Fig 5.1. Turning on fan using web server

Fig 5.2. Turning off fan using web server

19
Fig 5.3. Turning on light using web server

Fig 5.4. Turning off light using web server

5.2. Cloud Control :

Fig 5.5. Turning on fan using Blynk

20
Fig 5.6. Turning off fan using Blynk

Fig 5.7. Turning on light using Blynk

Fig 5.8. Turning off light using Blynk

21
5.3. Energy Monitoring :

Fig 5.9. Energy monitoring using OLED

Fig 5.10. Energy monitoring using web server

22
Fig 5.11. Energy monitoring using Blynk

5.4. Smart Alert :

Fig 5.12. power consumption alert through Gmail

23
5.5. Final Compact Setup :

Fig 5.13. Final compact setup (front)

Fig 5.14. Final compact setup (back)

Results obtained
https://drive.google.com/drive/folders/1y2kvn2ZcpL9pvUetE9XiyGLtKPbxBD2k
24
CHAPTER 6

CONCLUSION

As part of this project, my primary responsibility was to design and implement the web/cloud-based
interface that allows users to remotely control electrical appliances through the ESP32
microcontroller. The included configuring the ESP32 web server ensures seamless integration with
the relay module for the switching operations. Through this task, I learned how to host a web server
that responds to user inputs and how to handle GPIO outputs effectively. I gained an understanding
over communication over Wi-Fi, and the structure of dynamic control panels tailored for real-time
hardware interaction. Additionally, I ensured that the relay operations were responsive and stable
under various Wi-Fi conditions, which involved multiple rounds of testing and debugging. This
component of the system was crucial, as it enabled the user-friendly control of connected devices,
making the smart automation complete. Overall, the experience enhanced my technical confidence
and taught me how to build responsive and reliable IoT interfaces for practical use cases.

Signature of the Guide Student Reg. No : 125004353

Name of the Guide : Dr. Sriranjani R Name : Vivian Akshay J

25
CONCLUSION
My key contribution to this project was developing the email alert notification system and setting
up the OLED display for local real-time power monitoring. I implemented the SMTP protocol with
ESP32 to send automated emails whenever power consumption crossed a predefined threshold,
which adds a layer of safety and awareness to the user. This required understanding how secure mail
servers work with embedded devices and ensuring the reliability of alert triggers. Alongside this, I
was responsible for configuring and programming the OLED display to continuously show voltage,
current, power, and energy readings. This component made the system more interactive and
provided immediate on-site feedback about energy usage. The process of integrating these two
features helped me develop strong skills in embedded communication, I2C display interfacing, and
real-time data handling. It also taught me how to balance user experience with system performance.
Through this project, I gained significant insight into how real-world smart monitoring systems
function and how automation can simplify routine energy management tasks.

Signature of the Guide Student Reg. No : 125004240

Name of the Guide : Dr. Sriranjani R Name : Sam Joshua B C

26
CONCLUSION
In this project, I focused on the integration and calibration of the ACS712 current sensor and
ZMPT101B voltage sensor to capture accurate and real-time measurements. My role was to convert
the analog signals from these sensors into usable digital values for calculating voltage, current,
power, and energy consumption. This involved writing and refining code for analog signal
acquisition and learning how to eliminate noise to get stable and accurate readings. I worked
extensively on understanding the electrical characteristics of these sensors and applying
mathematical formulas to derive real-time energy data. This foundational data was then used for
both display on the OLED and for cloud-based monitoring. By completing this task, I gained
practical knowledge of how embedded systems interact with sensors, how to interpret analog inputs,
and how to process data for real-time applications. This experience not only improved my
understanding of power systems and IoT but also gave me hands-on exposure to the kind of
challenges faced in building reliable energy monitoring systems from scratch.

Signature of the Guide Student Reg. No : 125012006

Name of the Guide : Dr. Sriranjani R Name : Ajay V

27
CHAPTER 7

REFERENCES

1. H. Kareem and D. Dunaev, "The Working Principles of ESP32 and Analytical Comparison
of using Low-Cost Microcontroller Modules in Embedded Systems Design," 2021 4th
International Conference on Circuits, Systems and Simulation (ICCSS), Kuala Lumpur,
Malaysia, 2021, pp. 130-135, doi: 10.1109/ICCSS51193.2021.9464217.

2. Koushal, R. Gupta, F. Jan, K. Kamaldeep and V. Kumar, "Home Automation System Using
ESP32 and Firebase," 2022 Seventh International Conference on Parallel, Distributed and
Grid Computing (PDGC), Solan, Himachal Pradesh, India, 2022, pp. 228-231, doi:
10.1109/PDGC56933.2022.10053309.

3. W. Hu, H. Zhou, Chaoyang Lin, Xianfeng Chen, Z. Chen and Y. Lu, "Design of web-based
Smart Home with 3D virtural reality interface," Proceedings of 2012 UKACC International
Conference on Control, Cardiff, 2012, pp. 223-228, doi:
10.1109/CONTROL.2012.6334633.

4. T. Bhala, A. Aggarwal, S. Aggarwal, K. Garg and A. Gupta, "Home Automation System


using Internet-of-Things & Blynk App," 2023 IEEE Pune Section International Conference
(PuneCon), Pune, India, 2023, pp. 1-4, doi: 10.1109/PuneCon58714.2023.10450120.

5. H. K. Patel, T. Mody and A. Goyal, "Arduino Based Smart Energy Meter using GSM," 2019
4th International Conference on Internet of Things: Smart Innovation and Usages (IoT-SIU),
Ghaziabad, India, 2019, pp. 1-6, doi: 10.1109/IoT-SIU.2019.8777490.

28
CHAPTER 8

APPENDIX

Plagiarism Report :

29

You might also like