PROJECT EXPO
CYBER PHYSICS APPLICATION IN
INDUSTRIAL IOT
TOPIC :- Smart Socket System
(Home Automation)
PRESENTED BY:-
GROUP NUMBER- 11
GROUP MEMBERS :-
1. Shivam Saurav (22052936)
2. Shivam Kumar (22052935)
3. Vinamra Saurav (22052954)
4. Vaibhav Agarwal (22052951)
5. Rajat Kr. Panda (22052923)
CERTIFICATE
This is to certify that that the project report submitted on “IN Smart Socket
System (Home Automation)” by the students of 2nd year CSE GROUP
NUMBER-11 members Shivam Saurav (22052936), Shivam Kumar
(22052935), Vaibhav Agarwal (22052951), Vinamra Saurav (22052954) and
Rajat Panda (22052923) is a bonafied piece ofwork submitted to Kalinga
Institute of Industrial Technology during the academic year of 2023-24.
The project work was created under the supervision and guidance of Surath
Behera , Ankit Soni Associate Professor & Associate Dean PG Program
(University), School of Electrical Engineering and associated Lab Technicians
of Cyber Physics Application in Industrial IoT Lab and all data sources have
been duly acknowledged.
Certified by
Dr. Surath Behera
Supervisor
ACKNOWLEDGEMENT
We extend our heartfelt gratitude to all those who have contributed to the
completion of this project. Their support, guidance, and encouragement have
been invaluable throughout this journey.
We would like to express our deepest appreciation to our Founder Dr. Achyuta
Samanta providing us an opportunity to conduct our work on this noble project.
We would also like to thank Dr. Ankit Soni for his mentorship and expertise,
which provided us with invaluable insights and guidance at every stage of the
project.
We are also thankful to the team of Lab Technicians for their assistance in data
collection and hardware implementation, which significantly enriched the
quality of our findings.
Finally, we are grateful to our esteemed faculties, families and friends for their
patience, understanding, and encouragement throughout this endeavour. Their
unwavering support has been a source of strength and inspiration, driving us to
achieve our goals. We also seek the blessings of the Almighty for making us
able to draw the project smoothly within the due course of time.
Thank you all for being an integral part of this journey.
1) NAME OF THE PROJECT:-
- Smart Socket System (Home Automation)
2) OBJECTIVE OF THE PROJECT:-
- The home automation systems allow to control electronic devices remotely
and to perform automatic routines based on the user's programming
preferences, making domestic environments more convenient, comfortable,
and efficient, also optimizing energy costs.
3) MOTIVATIONS FOR THE PROJECT:-
• Reduction in cost of Home Automation.
• Enhanced safety measures for workers in industrial settings.
4) COMPONENTS REQUIRED:-
• Arduino UNO
• Breadboard
• Bluetooth module (HC-05)
• Relay module(s)
• MQ135 Sensor
• Power supply (5V)
• Jumper Wires
• Connecting Wires
• Smartphone with Bluetooth capability
• Connecting Cable
Arduino UNO
Relay Module
5) CIRCUIT DIAGRAM:-
6) BLOCK DIAGRAM:-
7) OPERATIONAL CODE:-
// CONNECTION PINOUT DIAGRAM
/*
|-------------|-----------------|-----------------|
| PLUG-A | PLUG-B | PLUG-C |
|-------------|-----------------|-----------------|
RELAY GPIO -> | 14 | 12 | 13 |
BUTTON GPIO -> | 4 | 0 | 2 |------[ USING TACTILE SWITCHES ]-----
| | | |
|-------------|-----------------|-----------------|
*/
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h> // function code for comparatibility for both esp32 and
esp8266
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProSwitch.h"
#include <map>
#define WIFI_SSID "xen" // defining wifi credentials to connect with
#define WIFI_PASS "123456789"
#define APP_KEY "1937e401-e943-4b51-b56e-756e58587ccf"
#define APP_SECRET "118a550e-823e-45a7-bf18-9da32ecdfe5e-881e8e65-bf7f-4dbc-8dad-
d02430da19f6"
#define BAUD_RATE 115200 // defined baud rate for serial monitor
#define DEBOUNCE_TIME 250
#define RELAYPIN_1 14 // defining gpio pins for relay connection with esp
#define RELAYPIN_2 12
#define RELAYPIN_3 13
typedef struct { // structure for the std::map below
int relayPIN;
int flipSwitchPIN;
bool activeLow;
} deviceConfig_t;
// this is the main configuration
std::map<String, deviceConfig_t> devices = {
//--------------------------------------------------------
//{deviceId, {relayPIN, flipSwitchPIN, activeLow}}
{"65ee9a9938f6f4a3cdbf194c", { 14, 4, true }},
{"65ee9aab38f6f4a3cdbf1969", { 12, 0, true }},
{"65ee9ab760d81635d1c4efca", { 13, 2, true }},
//-----------------------------------------------------------
};
typedef struct { // struct for the std::map below
String deviceId;
bool lastFlipSwitchState;
unsigned long lastFlipSwitchChange;
bool activeLow;
} flipSwitchConfig_t;
std::map<int, flipSwitchConfig_t> flipSwitches; // this map is used for mapping flipSwitch PINs to
deviceId and handling debounce and last flipSwitch state checks
// it will be setup in "setupFlipSwitches" function, using informations from
devices map
void setupRelays() {
for (auto &device : devices) { // setup for each device (relay, flipSwitch combination)
int relayPIN = device.second.relayPIN; // get the relay pin
pinMode(relayPIN, OUTPUT); // set relay pin to OUTPUT
digitalWrite(relayPIN,HIGH); // modified
}
}
void setupFlipSwitches() {
for (auto &device : devices) { // for each device (relay / flipSwitch combination)
flipSwitchConfig_t flipSwitchConfig; // create a new flipSwitch configuration
flipSwitchConfig.deviceId = device.first; // set the deviceId
flipSwitchConfig.lastFlipSwitchChange = 0; // set debounce time
flipSwitchConfig.lastFlipSwitchState = false; // set lastFlipSwitchState to false (LOW)
int flipSwitchPIN = device.second.flipSwitchPIN; // get the flipSwitchPIN
bool activeLow = device.second.activeLow; // set the activeLow
flipSwitchConfig.activeLow = activeLow;
flipSwitches[flipSwitchPIN] = flipSwitchConfig; // save the flipSwitch config to flipSwitches map
if(activeLow) {
pinMode(flipSwitchPIN, INPUT_PULLUP); // set the flipSwitch pin to INPUT_PULLUP
}
else {
pinMode(flipSwitchPIN, INPUT); // set the flipSwitch pin to INPUT
}
}
}
bool onPowerState(String deviceId, bool &state) {
Serial.printf("%s: %s\r\n", deviceId.c_str(), state ? "on" : "off");
//modified ( ! )
int relayPIN = devices[deviceId].relayPIN; // get the relay pin for corresponding device
digitalWrite(relayPIN, state); // set the new relay state
modified ( ! )
return true;
}
void handleFlipSwitches() {
unsigned long actualMillis = millis(); // get actual millis
for (auto &flipSwitch : flipSwitches) { // for each flipSwitch in flipSwitches
map
unsigned long lastFlipSwitchChange = flipSwitch.second.lastFlipSwitchChange; // get the timestamp
when flipSwitch was pressed last time (used to debounce / limit events)
if (actualMillis - lastFlipSwitchChange > DEBOUNCE_TIME) { // if time is > debounce
time...
int flipSwitchPIN = flipSwitch.first; // get the flipSwitch pin from
configuration
bool lastFlipSwitchState = flipSwitch.second.lastFlipSwitchState; // get the lastFlipSwitchState
bool activeLow = flipSwitch.second.activeLow;
bool flipSwitchState = digitalRead(flipSwitchPIN); // read the current flipSwitch state
if(activeLow) flipSwitchState = !flipSwitchState;
if (flipSwitchState != lastFlipSwitchState) { // if the flipSwitchState has changed...
#ifdef TACTILE_BUTTON
if (flipSwitchState) { // if the tactile button is pressed
#endif
flipSwitch.second.lastFlipSwitchChange = actualMillis; // update lastFlipSwitchChange
time
String deviceId = flipSwitch.second.deviceId; // get the deviceId from config
int relayPIN = devices[deviceId].relayPIN; // get the relayPIN from config
bool newRelayState = !digitalRead(relayPIN); // set the new relay State
digitalWrite(relayPIN, newRelayState); // set the trelay to the new state
SinricProSwitch &mySwitch = SinricPro[deviceId]; // get Switch device from
SinricPro
mySwitch.sendPowerStateEvent(newRelayState); // send the event
#ifdef TACTILE_BUTTON
}
#endif
flipSwitch.second.lastFlipSwitchState = flipSwitchState; // update lastFlipSwitchState
}
}
}
}
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
#if defined(ESP8266)
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.setAutoReconnect(true);
#elif defined(ESP32)
WiFi.setSleep(false);
WiFi.setAutoReconnect(true);
#endif
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED)
{
Serial.printf(".");
delay(250);
}
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}
void setupSinricPro() {
for (auto &device : devices) {
const char *deviceId = device.first.c_str();
SinricProSwitch &mySwitch = SinricPro[deviceId];
mySwitch.onPowerState(onPowerState);
}
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(BAUD_RATE);
setupRelays();
setupFlipSwitches();
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
handleFlipSwitches();
}
8) RESULT:-