Magicbit
Published

Light (230V) control with blynk app - (ESP32)

How to make light (230V) control with Magicbit and Blynk app.

IntermediateProtip1 hour472
Light (230V) control with blynk app - (ESP32)

Things used in this project

Hardware components

Magicbit
×1
Relay (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
bulb (230V)
×1
Bulb holder
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk App

Story

Read more

Code

Arduino Code

Arduino
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define relayPin 26  //D26
#define OLED_RESET 4

Adafruit_SSD1306 display(128,64);

int relayState = 1; // RELAY OFF 

char auth[] = "YcwWFZ09lNlVi1V8PbmX_Q4d1rzY6AyQ";

char ssid[] = "Jazz-LTE-EB8E";
char pass[] = "40758892";

BLYNK_WRITE(V1) {
  relayState = param.asInt();
  digitalWrite(relayPin, relayState);
  }


BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(V1);
}
void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
   
  pinMode(relayPin, OUTPUT);

 //On power ON rely in OFF state
  digitalWrite(relayPin, relayState);


  
}
void loop()
{
  Blynk.run();
  if(relayState==1){
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(10, 0);
    display.println(" Light   ON");//Pump On
    Serial.println("Light ON");
    display.display();
    display.clearDisplay();
    delay(1000);
  }
  else{
    
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(10, 0);
    display.println(" Light  OFF");//Pump Off
    Serial.println("Light OFF");
    display.display();
    display.clearDisplay();
    delay(1000);
  }

}

Credits

Magicbit

Magicbit

57 projects • 34 followers
Magicbit is an integrated development platform based on ESP32 for learning, prototyping, coding, electronics, robotics, IoT and more.

Comments