Materials:-
NodeMCU ESP8266Relay Module
Touch sensor (TTP223)
Transistor Driver BC547 based
4 plug Module Board
5V,1Amp SMPS
PCB
How to program Nodemcu
nodemcu को प्रोग्राम करने के लिए arduino ide software का उसे करेंगे इसमें arduinoide install के बाद ये उसमे ये step fallow करना है।
Step-1
file me preference पर click करना है।
Step-2
Step-3
Step-4
Step-5
Step-6
अब search बार में Blynk लिख कर उसमें Blynk by volodymyr shymanskyy को install करना है।
Step-7
Step-8
Step-9
Program
//Ceneloctronics YT:- https://www.youtube.com/channel/UCj62JBDfG1DiUGZ7pb1LbMQ
//blogger :-http://ceneloctronics.blogspot.com/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h> // For OTA with ESP8266
#include <WiFiUdp.h> // For OTA
#include <ArduinoOTA.h> // For OTA
BlynkTimer timer;
void checktouchButton();
int relay1State = LOW;
int touchButton1State = HIGH;
int relay2State = LOW;
int touchButton2State = HIGH;
int relay3State = LOW;
int touchButton3State = HIGH;
int relay4State = LOW;
int touchButton4State = HIGH;
#define AUTH "lRmZrzA7RP9SdixbxXM6sj_YL6kw0JJy" // You should get Auth Token in the Blynk App.
#define WIFI_SSID "ceneloctronics" //Enter Wifi Name
#define WIFI_PASS "12345678" //Enter wifi Password
#define SERVER "blynk-cloud.com " // Comment-out if use Blynk hosted cloud service
#define PORT 8442
#define RELAY_PIN_1 12 //D6
#define RELAY_PIN_2 16 //D0
#define RELAY_PIN_3 4 //D2
#define RELAY_PIN_4 5 //D1
#define Touch_Swnsor_1 15 //D8
#define Touch_Swnsor_2 14 //D5
#define Touch_Swnsor_3 13 //D7
#define Touch_Swnsor_4 3 //Rx
#define VPIN_BUTTON_1 V12
#define VPIN_BUTTON_2 V13
#define VPIN_BUTTON_3 V14
#define VPIN_BUTTON_4 V15
#define OTA_HOSTNAME "Home_Automation"
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual (VPIN_BUTTON_1);
Blynk.syncVirtual (VPIN_BUTTON_2);
Blynk.syncVirtual (VPIN_BUTTON_3);
Blynk.syncVirtual (VPIN_BUTTON_4);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON_1) {
relay1State = param.asInt();
digitalWrite(RELAY_PIN_1, relay1State);
}
BLYNK_WRITE(VPIN_BUTTON_2) {
relay2State = param.asInt();
digitalWrite(RELAY_PIN_2, relay2State);
}
BLYNK_WRITE(VPIN_BUTTON_3) {
relay3State = param.asInt();
digitalWrite(RELAY_PIN_3, relay3State);
}
BLYNK_WRITE(VPIN_BUTTON_4) {
relay4State = param.asInt();
digitalWrite(RELAY_PIN_4, relay4State);
}
void checktouchButton()
{
if (digitalRead(Touch_Swnsor_1) == LOW) {
// pushButton1State is used to avoid sequential toggles
if (touchButton1State != LOW) {
// Toggle Relay state
relay1State = !relay1State;
digitalWrite(RELAY_PIN_1, relay1State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}
touchButton1State = LOW;
} else {
touchButton1State = HIGH;
}
if (digitalRead(Touch_Swnsor_2) == LOW) {
// pushButton2State is used to avoid sequential toggles
if (touchButton2State != LOW) {
// Toggle Relay state
relay2State = !relay2State;
digitalWrite(RELAY_PIN_2, relay2State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_2, relay2State);
}
touchButton2State = LOW;
} else {
touchButton2State = HIGH;
}
if (digitalRead(Touch_Swnsor_3) == LOW) {
// pushButton3State is used to avoid sequential toggles
if (touchButton3State != LOW) {
// Toggle Relay state
relay3State = !relay3State;
digitalWrite(RELAY_PIN_3, relay3State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_3, relay3State);
}
touchButton3State = LOW;
} else {
touchButton3State = HIGH;
}
if (digitalRead(Touch_Swnsor_4) == LOW) {
// pushButton4State is used to avoid sequential toggles
if (touchButton4State != LOW) {
// Toggle Relay state
relay4State = !relay4State;
digitalWrite(RELAY_PIN_4, relay4State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_4, relay4State);
}
touchButton4State = LOW;
} else {
touchButton4State = HIGH;
}
}
void setup()
{
Serial.begin(115200);
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS,"blynk-cloud.com", 8442);
ArduinoOTA.setHostname(OTA_HOSTNAME); // For OTA - Use your own device identifying name
ArduinoOTA.begin(); // For OTA
pinMode(RELAY_PIN_1, OUTPUT);
pinMode(Touch_Swnsor_1, INPUT_PULLUP);
digitalWrite(RELAY_PIN_1, relay1State);
pinMode(RELAY_PIN_2, OUTPUT);
pinMode(Touch_Swnsor_2, INPUT_PULLUP);
digitalWrite(RELAY_PIN_2, relay2State);
pinMode(RELAY_PIN_3, OUTPUT);
pinMode(Touch_Swnsor_3, INPUT_PULLUP);
digitalWrite(RELAY_PIN_3, relay3State);
pinMode(RELAY_PIN_4, OUTPUT);
pinMode(Touch_Swnsor_4, INPUT_PULLUP);
digitalWrite(RELAY_PIN_4, relay4State);
// Setup a function to be called every 100 ms
timer.setInterval(500L, checktouchButton);
}
void loop()
{
Blynk.run();
ArduinoOTA.handle(); // For OTA
timer.run();
}
Circuit Diagram
TTP223 connect with node MCU or relay module
Wiring Diagram of relay and plug
App QR code
Both with internet and without internet program
-----------------------------------------------------------------------------------------------------------------------------
//#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
// define the GPIO connected with Relays and switches
#define RelayPin1 12 //D6
#define RelayPin2 16 //D0
#define RelayPin3 4 //D2
#define RelayPin4 5 //D1
#define SwitchPin1 15 //D8
#define SwitchPin2 14 //D5
#define SwitchPin3 13 //D7
#define SwitchPin4 3 //RX
#define wifiLed 0 //D3
#define VPIN_BUTTON_1 V12
#define VPIN_BUTTON_2 V13
#define VPIN_BUTTON_3 V14
#define VPIN_BUTTON_4 V15
int toggleState_1 = 1; //Define integer to remember the toggle state for relay 1
int toggleState_2 = 1; //Define integer to remember the toggle state for relay 2
int toggleState_3 = 1; //Define integer to remember the toggle state for relay 3
int toggleState_4 = 1; //Define integer to remember the toggle state for relay 4
int wifiFlag = 0;
#define AUTH "AUTH TOKEN" // You should get Auth Token in the Blynk App.
#define WIFI_SSID "WIFI NAME" //Enter Wifi Name
#define WIFI_PASS "WIFI PASSWORD" //Enter wifi Password
BlynkTimer timer;
void relayOnOff(int relay){
switch(relay){
case 1:
if(toggleState_1 == 1){
digitalWrite(RelayPin1, LOW); // turn on relay 1
toggleState_1 = 0;
Serial.println("Device1 ON");
}
else{
digitalWrite(RelayPin1, HIGH); // turn off relay 1
toggleState_1 = 1;
Serial.println("Device1 OFF");
}
delay(100);
break;
case 2:
if(toggleState_2 == 1){
digitalWrite(RelayPin2, LOW); // turn on relay 2
toggleState_2 = 0;
Serial.println("Device2 ON");
}
else{
digitalWrite(RelayPin2, HIGH); // turn off relay 2
toggleState_2 = 1;
Serial.println("Device2 OFF");
}
delay(100);
break;
case 3:
if(toggleState_3 == 1){
digitalWrite(RelayPin3, LOW); // turn on relay 3
toggleState_3 = 0;
Serial.println("Device3 ON");
}
else{
digitalWrite(RelayPin3, HIGH); // turn off relay 3
toggleState_3 = 1;
Serial.println("Device3 OFF");
}
delay(100);
break;
case 4:
if(toggleState_4 == 1){
digitalWrite(RelayPin4, LOW); // turn on relay 4
toggleState_4 = 0;
Serial.println("Device4 ON");
}
else{
digitalWrite(RelayPin4, HIGH); // turn off relay 4
toggleState_4 = 1;
Serial.println("Device4 OFF");
}
delay(100);
break;
default : break;
}
}
void with_internet(){
//Manual Switch Control
if (digitalRead(SwitchPin1) == LOW){
delay(200);
relayOnOff(1);
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); // Update Button Widget
}
else if (digitalRead(SwitchPin2) == LOW){
delay(200);
relayOnOff(2);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); // Update Button Widget
}
else if (digitalRead(SwitchPin3) == LOW){
delay(200);
relayOnOff(3);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3); // Update Button Widget
}
else if (digitalRead(SwitchPin4) == LOW){
delay(200);
relayOnOff(4);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4); // Update Button Widget
}
}
void without_internet(){
//Manual Switch Control
if (digitalRead(SwitchPin1) == LOW){
delay(200);
relayOnOff(1);
}
else if (digitalRead(SwitchPin2) == LOW){
delay(200);
relayOnOff(2);
}
else if (digitalRead(SwitchPin3) == LOW){
delay(200);
relayOnOff(3);
}
else if (digitalRead(SwitchPin4) == LOW){
delay(200);
relayOnOff(4);
}
}
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.syncVirtual(VPIN_BUTTON_2);
Blynk.syncVirtual(VPIN_BUTTON_3);
Blynk.syncVirtual(VPIN_BUTTON_4);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON_1) {
toggleState_1 = param.asInt();
digitalWrite(RelayPin1, toggleState_1);
}
BLYNK_WRITE(VPIN_BUTTON_2) {
toggleState_2 = param.asInt();
digitalWrite(RelayPin2, toggleState_2);
}
BLYNK_WRITE(VPIN_BUTTON_3) {
toggleState_3 = param.asInt();
digitalWrite(RelayPin3, toggleState_3);
}
BLYNK_WRITE(VPIN_BUTTON_4) {
toggleState_4 = param.asInt();
digitalWrite(RelayPin4, toggleState_4);
}
void checkBlynkStatus() { // called every 3 seconds by SimpleTimer
bool isconnected = Blynk.connected();
if (isconnected == false) {
wifiFlag = 1;
digitalWrite(wifiLed, HIGH); //Turn off WiFi LED
}
if (isconnected == true) {
wifiFlag = 0;
digitalWrite(wifiLed, LOW); //Turn on WiFi LED
}
}
void setup()
{
Serial.begin(9600);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
pinMode(wifiLed, OUTPUT);
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(SwitchPin3, INPUT_PULLUP);
pinMode(SwitchPin4, INPUT_PULLUP);
//During Starting all Relays should TURN OFF
digitalWrite(RelayPin1, toggleState_1);
digitalWrite(RelayPin2, toggleState_2);
digitalWrite(RelayPin3, toggleState_3);
digitalWrite(RelayPin4, toggleState_4);
WiFi.begin(WIFI_SSID, WIFI_PASS);
timer.setInterval(3000L, checkBlynkStatus); // check if Blynk server is connected every 3 seconds
Blynk.config(AUTH);
}
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("WiFi Not Connected");
}
else
{
Serial.println("WiFi Connected");
Blynk.run();
}
timer.run(); // Initiates SimpleTimer
if (wifiFlag == 0)
with_internet();
else
without_internet();
}
-----------------------------------------------------------------------------------------------------------------------------
More information about touch switchboard
मेरे पिछले touch switchboard ब्लॉग पोस्ट link
Full Video is hear
Bro can I use 8 appliances in this project pls reply in english
ReplyDeleteyes you can use for 8 appliances you need to use esp32 and add some step in programming
ReplyDeleteCan you please send me the circuit diagram and the code?
DeleteDM me on my Instagram @ceneloctronics
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteSir please add without internet and with internet ststem
ReplyDeleteU cannot control it without internet as it uses wifi
DeleteThis comment has been removed by the author.
ReplyDeleteSir pls make video on with wifi+Bluetooth+blynk+touchbutton code through ESP32 module and if possible try to add Alexa and Google assit mic so that it would be a full automation
ReplyDeleteWhat is the resistor value????
ReplyDeleteSir are u make a hotspot home automation using esp8266
ReplyDeletehow much ohms is the resistor?
ReplyDelete