Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Cleo Nandodirakit community
Published

Home Light Control with Blynk App -B24

Simple IoT project to turn lights on and off using a smartphone with the Blynk app

BeginnerFull instructions provided242
Home Light Control with Blynk App -B24

Things used in this project

Hardware components

FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Incandescent Lamp, 3.7 V
Incandescent Lamp, 3.7 V
×1
light fitting
×1
cable
×1
steker
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Grove - 2-Channel SPDT Relay
Seeed Studio Grove - 2-Channel SPDT Relay
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

Schematics

Code

Code

Arduino
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID           "TMPL6Skv0T3jm"
#define BLYNK_TEMPLATE_NAME         "Quickstart Device"
#define BLYNK_AUTH_TOKEN            "CsfNbYqCYr-bJxV-KqaAqsuxV7HgE40d"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "PONPES MINHAJUT TAMYIZ";
char pass[] = "Bismillah123";

BlynkTimer timer;

// Pin relay terhubung ke GPIO 2 (D4)
const int relayPin = 2;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
  // Set incoming value from pin V0 to a variable
  int value = param.asInt();
  Serial.print("V0 changed to: ");
  Serial.println(value);

  // Update state
  Blynk.virtualWrite(V1, value);
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  Serial.println("Connected to Blynk Cloud");

  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more than 10 values per second.
  long uptime = millis() / 1000;
  Serial.print("Uptime: ");
  Serial.println(uptime);
  Blynk.virtualWrite(V2, uptime);
}

// This function is called every time the Virtual Pin 4 state changes
BLYNK_WRITE(V4)
{
  int relayState = param.asInt();
  Serial.print("V4 changed to: ");
  Serial.println(relayState);

  if (relayState == 1) {
    Serial.println("Turning relay ON");
    digitalWrite(relayPin, HIGH); // Aktifkan relay
  } else {
    Serial.println("Turning relay OFF");
    digitalWrite(relayPin, LOW);  // Nonaktifkan relay
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  Serial.println("Starting...");

  // Set pin relay sebagai output
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Pastikan relay dalam keadaan nonaktif saat mulai

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  // You can also specify server:
  //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

Credits

Cleo Nando
1 project • 0 followers
Contact
dirakit community
23 projects • 109 followers
Indonesia IoT Community by Informatics UIN Sunan Kalijaga Yogyakarta
Contact

Comments

Please log in or sign up to comment.