0% found this document useful (0 votes)
62 views13 pages

CPP Report

The document discusses home automation and how it allows users to control devices in their home remotely using the internet. It describes the main components of a home automation system including sensors, controllers, and actuators. It then provides details on setting up a specific home automation project using NodeMCU ESP8266 to control relays with voice commands from Google Assistant and manual switches.

Uploaded by

nikunjsabane3
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)
62 views13 pages

CPP Report

The document discusses home automation and how it allows users to control devices in their home remotely using the internet. It describes the main components of a home automation system including sensors, controllers, and actuators. It then provides details on setting up a specific home automation project using NodeMCU ESP8266 to control relays with voice commands from Google Assistant and manual switches.

Uploaded by

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

1.

1 INTRODUCTION

“Home automation” refers to the automatic and


electronic control of household features, activity,
and appliances. In simple terms, it means you can
easily control the utilities and features of your
home via the Internet to make life more convenient
and secure, and even spend less on household
bills. Read on to find answers to some of the most
common questions about home automation
technology, and get a few ideas for home
automation solutions to incorporate in your home.
Home automation is a network of hardware, communication, and
electronic interfaces that work to integrate everyday devices with
one another via the Internet. Each device has sensors and is
connected through WiFi, so you can manage them from your
smartphone or tablet whether you’re at home, or miles away. This
allows you to turn on the lights, lock the front door, or even turn
down the heat, no matter where you are.
There are three main elements of a home automation system:
sensors, controllers, and actuators.
 Sensors can monitor changes in daylight, temperature, or
motion detection. Home automation systems can then adjust
those settings (and more) to your preferences.
 Controllers refer to the devices — personal computers, tablets
or smartphones — used to send and receive messages about
the status of automated features in your home.
 Actuators may be light switches, motors, or motorized valves
that control the actual mechanism, or function, of a home
automation system. They are programmed to be activated by a
remote command from a controller.

2.1

2.2 DESCRIPTION AND WORKING

In this IoT projects, We have make the smart home with Google
Assistant & Alexa using NodeMCU ESP8266 to control relays with
voice commands and manual switches. We have used all the free tools
for this IoT-based home automation system.

Working

Circuit Diagram of the NodeMCU Home Automation


The circuit is very simple, We have used the GPIO pins D1, D2, D5 &
D6 to control the 4 relays.
And the GPIO pins SD3, D3, D7 & RX connected with switches to
control the 4 relays manually.
We have used the INPUT_PULLUP function in Arduino IDE instead of
using the pull-up resistors.
We have used a 5V mobile charger to supply the smart relay module.
Here, the D3 pin should not be connected with GND during the
booting process of NodeMCU.

Controlling Relays With Google Assistant Using NodeMCU

If the NodeMCU is connected with the WiFi, then we can control the
home appliances from Google Home App and also from the manual
switches.
we can also ask Google Assistant to turn on and off the appliances.
we can control, monitor the real-time status of the relays in the
Google Home App from anywhere in the world. we don't need any
Google Home Nest device for this home automation project.

Controlling Relays Manually With Switches


If the WiFi is not available, We can control the relays
from the manual switches.

The NodeMCU will check for the WiFi after every 5


seconds. When the WiFi is available, the NodeMCU will
automatically connect with the WiFi.
Please refer to the circuit diagram to connect the
manual switches.

Create an Account in Sinric Pro

1.First, visit https://sinric.pro/

2.We have to create an account in Snric Pro.

3.Then log in to Sinric Pro Account.

4.We will get an APP KEY and APP SECRET for the
account, which will be
required in the code.

Add Room and Devices in Sinric Pro


After that add a room and give a nickname to that
room (Ex Living Room)

Then Add devices one by one and give the nickname


for each device. Sinric will assign a unique device ID
for each device.

Here, I have used the free Sinric Pro account, so I can


add a maximum of 3 devices for free.
Program NodeMCU Using Arduino IDE

// Uncomment the following line to enable serial debug output

//#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG

#define DEBUG_ESP_PORT Serial

#define NODEBUG_WEBSOCKETS

#define NDEBUG

#endif

#include <Arduino.h>

#include <ESP8266WiFi.h>

#include "SinricPro.h"

#include "SinricProSwitch.h"

#include <map>

#define WIFI_SSID "YOUR-WIFI-NAME"

#define WIFI_PASS "YOUR-WIFI-PASSWORD"

#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-


5dabxxxxxxxx"

#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-


e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"

//Enter the device IDs here

#define device_ID_1 "SWITCH_ID_NO_1_HERE"

#define device_ID_2 "SWITCH_ID_NO_2_HERE"

#define device_ID_3 "SWITCH_ID_NO_3_HERE"

#define device_ID_4 "SWITCH_ID_NO_4_HERE"

// define the GPIO connected with Relays and switches

#define RelayPin1 5 //D1

#define RelayPin2 4 //D2

#define RelayPin3 14 //D5

#define RelayPin4 12 //D6

#define SwitchPin1 10 //SD3


#define SwitchPin2 0 //D3

#define SwitchPin3 13 //D7

#define SwitchPin4 3 //RX

#define wifiLed 16 //D0

// comment the following line if you use a toggle switches instead of tactile buttons

//#define TACTILE_BUTTON 1

#define BAUD_RATE 9600

#define DEBOUNCE_TIME 250

typedef struct { // struct for the std::map below

int relayPIN;

int flipSwitchPIN;

deviceConfig_t;

// this is the main configuration

// please put in your deviceId, the PIN for Relay and PIN for flipSwitch

// this can be up to N devices...depending on how much pin's available on your device ;)

// right now we have 4 devicesIds going to 4 relays and 4 flip switches to switch the relay manually

std::map<String, deviceConfig_t> devices = {

//{deviceId, {relayPIN, flipSwitchPIN}}

{device_ID_1, { RelayPin1, SwitchPin1 }},

{device_ID_2, { RelayPin2, SwitchPin2 }},

{device_ID_3, { RelayPin3, SwitchPin3 }},

{device_ID_4, { RelayPin4, SwitchPin4 }}

};

typedef struct { // struct for the std::map below

String deviceId;

bool lastFlipSwitchState;

unsigned long lastFlipSwitchChange;

flipSwitchConfig_t;

std::map<int, flipSwitchConfig_t> flipSwitches;


// this map is used to map 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) { // 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);

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 = true; // set lastFlipSwitchState to false (LOW)--

int flipSwitchPIN = device.second.flipSwitchPIN; // get the flipSwitchPIN

flipSwitches[flipSwitchPIN] = flipSwitchConfig; // save the flipSwitch config to flipSwitches map

pinMode(flipSwitchPIN, INPUT_PULLUP); // set the flipSwitch pin to INPUT

bool onPowerState(String deviceId, bool &state)

Serial.printf("%s: %s\r\n", deviceId.c_str(), state ? "on" : "off");

int relayPIN = devices[deviceId].relayPIN; // get the relay pin for corresponding device

digitalWrite(relayPIN, !state); // set the new relay state


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 flipSwitchState = digitalRead(flipSwitchPIN); // read the current flipSwitch state

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

WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED)

Serial.printf(".");

delay(250);

digitalWrite(wifiLed, LOW);

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);

SinricPro.restoreDeviceStates(true);

void setup()

Serial.begin(BAUD_RATE);

pinMode(wifiLed, OUTPUT);

digitalWrite(wifiLed, HIGH);

setupRelays();

setupFlipSwitches();

setupWiFi();

setupSinricPro();

void loop()

SinricPro.handle();

handleFlipSwitches();

After that select the NodeMCU 1.0 (ESP-12E Module)


board and the PORT. Then click on the upload button.

Setup the Google Home App

First, download and install the Google Home App.


then follow the steps to create Home in Google Home
app
1. Tap on the "+" icon (upper left corner).
2. Tap on Create new home.
3. Enter the Home nickname and address.
4. Then click on Continue.

The Home is created. Now again tap on the "+" icon to


add devices.

Connect Sinric Pro With Google Home App | Add Devices

After creating the Home in the Google Home app, you


can connect the Sinric Pro with the Google Home app

1. Tap on the "+" icon, then select Set up device.


2. Tap on Works with Google.
3. Search for Sinric Pro, then select on Sinric Pro.
4. Enter the email id and password used for the
Sinric account,
5. Then tap on Sign in.

Thus, all the devices from Sinric Pro will be added to


Google Home Account.

Connect the Home Appliances


Connect the 4 home appliances with the relay module
as per the circuit diagram. Please take proper safety
precautions while working with high voltage.

Connect 5-volt DC supply with the PCB. (I have used


my old mobile charger 5V 5Amp)

Turn ON the Supply

Turn on the 110V/230V supply and 5V DC supply.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy