Internet and Manual Control HomeAutomation System with feedback using ESP32 & Blynk.

Internet and Manual Control HomeAutomation System with feedback using ESP32 & Blynk.

Internet and Manual Control HomeAutomation System with feedback using ESP32 & Blynk.

  • Hey hello friends , welcome to another post, In this article I will let you know how to make internet and manual control homeautomation system using blynk iot cloud platform.
  • By using this homeautoamtion system you can control  your home appliances over internet from your smartphone from anywher in this world  as well as check the status of your appliances either it is  ON/OFF. that is you will able to know the real time status of your Appliances, and also control it.
  • Remotelly controlled Home Automation along with Manual Control as well as Real-Time Feedback of the Switches. 
  • you can control the appliances with Internet and also with your regular manual traditional switches.

Components Requried

To make this project we need some components whose list is mention below.

Designing the PCB.

To design the circuit and PCB, we used EasyEDA which is a browser based software to design PCBs.

Designing the circuit works like in any other circuit software tool, you place some components and you wire them together. 

Then, you assign each component to a footprint.

Having the parts assigned, place each component. When you’re happy with the layout, make all the connections and route your PCB.

Save your project and export the Gerber files.

Ordering the PCBs at PCBWay.

This project is sponsored by PCBWay. PCBWay is a full feature Printed Circuit Board manufacturing service.

Turn your DIY breadboard circuits into professional PCBs – get 10 boards for approximately $5 + shipping (which will vary depending on your country).

Once you have your Gerber files, you can order the PCB. Follow the next steps.

1. Download the Gerber files – click here to download the .zip file.

2. Go to PCBWay website and open the PCB Instant Quote page. 

3. PCBWay can grab all the PCB details and automatically fills them for you. Use the “Quick-order PCB (Autofill parameters)”.

4. Press the “+ Add Gerber file” button to upload the provided Gerber files.

And that’s it. You can also use the OnlineGerberViewer to check if your PCB is looking as it should.

Now select the shipping method , the one you prefer and has cost efficient.

You can increase your PCB order quantity and change the solder mask color. I’ve ordered the Black color.

Once you’re ready, you can order the PCBs by clicking “Save to Cart” and complete your order.

PCBWayhas lots of other staggering solder mask, Now they can produce pink, orange, grey, even the transparent solder mask. 

Apart from this they also provide Black core PCB.

After approximately one week using the DHL shipping method, I received the PCBs at my place.

As usual, everything comes well packed, and the PCBs are really high-quality. 

The letters on the silkscreen are really well-printed and easy to read. Additionally, the solder sticks easily to the pads.

Let's Make it...!

Now grab all the components whose list is mention above, and soldered on the PCB.

After soldiering rest of components PCB look like this neat, clean and well arranged.

Blynk Iot Cloud Platform.

Blynk mobile application is available for both IOS as well as Android users.

Scan above QR Code with your phone and you will get a full copy of this project.

Connection of Switches & Bulbs

Connect all the bulb and switches as Shown in the Schematics below.

Code

Copy or download the following code to your Arduino IDE and upload it to your Arduino board.

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;


#define DEBUG_SW 0


#define S1 32
#define R1 15

#define S2 35
#define R2 2

#define S3 34
#define R3 4

#define S4 39
#define R4 22


#define LED1 26
#define LED2 25
#define LED3 27
#define Buzzer 21



int MODE = 0;


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxx";

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";


int switch_ON_Flag1_previous_I = 0;
int switch_ON_Flag2_previous_I = 0;
int switch_ON_Flag3_previous_I = 0;
int switch_ON_Flag4_previous_I = 0;


BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  digitalWrite(R1, pinValue);
  // process received value
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable
  digitalWrite(R2, pinValue);
  // process received value
}

BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable
  digitalWrite(R3, pinValue);
  // process received value
}

BLYNK_WRITE(V4)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V4 to a variable
  digitalWrite(R4, pinValue);
  // process received value
}

void with_internet()
{
  if (digitalRead(S1) == LOW)
  {
    if (switch_ON_Flag1_previous_I == 0 )
    {
      digitalWrite(R1, LOW);
      if (DEBUG_SW) Serial.println("Relay1- ON");
      Blynk.virtualWrite(V1, 0);
      switch_ON_Flag1_previous_I = 1;
    }
    if (DEBUG_SW) Serial.println("Switch1 -ON");

  }
  if (digitalRead(S1) == HIGH )
  {
    if (switch_ON_Flag1_previous_I == 1)
    {
      digitalWrite(R1, HIGH);
      if (DEBUG_SW) Serial.println("Relay1 OFF");
      Blynk.virtualWrite(V1, 1);
      switch_ON_Flag1_previous_I = 0;
    }
    if (DEBUG_SW)Serial.println("Switch1 OFF");
  }


  if (digitalRead(S2) == LOW)
  {
    if (switch_ON_Flag2_previous_I == 0 )
    {
      digitalWrite(R2, LOW);
      if (DEBUG_SW)  Serial.println("Relay2- ON");
      Blynk.virtualWrite(V2, 0);
      switch_ON_Flag2_previous_I = 1;
    }
    if (DEBUG_SW) Serial.println("Switch2 -ON");

  }
  if (digitalRead(S2) == HIGH )
  {
    if (switch_ON_Flag2_previous_I == 1)
    {
      digitalWrite(R2, HIGH);
      if (DEBUG_SW) Serial.println("Relay2 OFF");
      Blynk.virtualWrite(V2, 1);
      switch_ON_Flag2_previous_I = 0;
    }
    if (DEBUG_SW)Serial.println("Switch2 OFF");
    //delay(200);
  }

  if (digitalRead(S3) == LOW)
  {
    if (switch_ON_Flag3_previous_I == 0 )
    {
      digitalWrite(R3, LOW);
      if (DEBUG_SW) Serial.println("Relay3- ON");
      Blynk.virtualWrite(V3, 0);
      switch_ON_Flag3_previous_I = 1;
    }
    if (DEBUG_SW) Serial.println("Switch3 -ON");

  }
  if (digitalRead(S3) == HIGH )
  {
    if (switch_ON_Flag3_previous_I == 1)
    {
      digitalWrite(R3, HIGH);
      if (DEBUG_SW) Serial.println("Relay3 OFF");
      Blynk.virtualWrite(V3, 1);
      switch_ON_Flag3_previous_I = 0;
    }
    if (DEBUG_SW)Serial.println("Switch3 OFF");
    //delay(200);
  }

  if (digitalRead(S4) == LOW)
  {
    if (switch_ON_Flag4_previous_I == 0 )
    {
      digitalWrite(R4, LOW);
      if (DEBUG_SW) Serial.println("Relay4- ON");
      Blynk.virtualWrite(V4, 0);
      switch_ON_Flag4_previous_I = 1;
    }
    if (DEBUG_SW) Serial.println("Switch4 -ON");

  }
  if (digitalRead(S4) == HIGH )
  {
    if (switch_ON_Flag4_previous_I == 1)
    {
      digitalWrite(R4, HIGH);
      if (DEBUG_SW) Serial.println("Relay4 OFF");
      Blynk.virtualWrite(V4, 1);
      switch_ON_Flag4_previous_I = 0;
    }
    if (DEBUG_SW)Serial.println("Switch4 OFF");
    //delay(200);
  }



}

void without_internet()
{

  digitalWrite(R1, digitalRead(S1));
  digitalWrite(R2, digitalRead(S2));
  digitalWrite(R3, digitalRead(S3));
  digitalWrite(R4, digitalRead(S4));

}


void checkBlynk() { // called every 3 seconds by SimpleTimer

  bool isconnected = Blynk.connected();
  if (isconnected == false) {
    MODE = 1;
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, LOW);
  }
  if (isconnected == true) {
    MODE = 0;
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
    digitalWrite(LED3, HIGH);
  }
}

void setup()
{
  // Debug console
  if (DEBUG_SW) Serial.begin(9600);
  pinMode(S1, INPUT);
  pinMode(R1, OUTPUT);

  pinMode(S2, INPUT);
  pinMode(R2, OUTPUT);

  pinMode(S3, INPUT);
  pinMode(R3, OUTPUT);

  pinMode(S4, INPUT);
  pinMode(R4, OUTPUT);


  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(Buzzer, OUTPUT);

  digitalWrite(LED1, HIGH);
  delay(200);
  digitalWrite(LED2, HIGH);
  delay(200);
  digitalWrite(LED3, HIGH);
  delay(200);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  delay(500);

  digitalWrite(LED1, HIGH);
  delay(200);
  digitalWrite(LED2, HIGH);
  delay(200);
  digitalWrite(LED3, HIGH);
  delay(200);

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  //pinMode(MODE, INPUT);
  WiFi.begin(ssid, pass);
  timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds
  Blynk.config(auth);//, ssid, pass);

}

void loop()
{
  if (WiFi.status() != WL_CONNECTED)
  {
    if (DEBUG_SW) Serial.println("Not Connected");
  }
  else
  {
    if (DEBUG_SW) Serial.println(" Connected");
    Blynk.run();
  }

  timer.run(); // Initiates SimpleTimer
  if (MODE == 0)
    with_internet();
  else
    without_internet();
}

Copy the above code and open in arduino ide. before you upload the code you need to enter the ssid and password of your router or hotspot. And blynk authentication token that is sent by blynk on your registered email id.

After doing this much of modifications, Upload the code in your ESP32 Board after selecting right board and COM port.

Now your homeautomation system is ready to work.

If you have any question or queries regarding this project please comment below.


Thank you so much for reading. 

One thought on “Internet and Manual Control HomeAutomation System with feedback using ESP32 & Blynk.

  1. What could be the problem if the esp32 and switch is not working when you power on but only the light bulb is working

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top