#define BLYNK_TEMPLATE_ID "TMPL6-Plss_2F"
#define BLYNK_TEMPLATE_NAME "nimesh 123"
#define BLYNK_AUTH_TOKEN "IvhH46SShMjp0fW3KIzTf6UgJk3KFzfp"
// Include required libraries
#include <BlynkSimpleEsp32.h>
// Define LED pins
const int ldrled1 = 5;
const int ldrled2 = 18;
const int ldrled3 = 19;
const int ldrled4 = 21;
const int ldrled5 = 22;
const int ldrled6 = 23;
const int ldrpin = 34;
const int potpin1 = 32; // Potentiometer for ldrled1 and ldrled2
const int potpin2 = 33; // Potentiometer for ldrled3 and ldrled4
// LDR threshold for LED control
int ldrValue = 177;
// Blynk virtual pins for controlling LED states
bool ledControl1 = false; // Controls ldrled1 and ldrled2
bool ledControl2 = false; // Controls ldrled3 and ldrled4
char auth[] = "IvhH46SShMjp0fW3KIzTf6UgJk3KFzfp"; // Replace with your Blynk auth token
char ssid[] = "Wokwi-GUEST"; // Replace with your WiFi SSID
char pass[] = ""; // Replace with your WiFi password
// Blynk button for controlling ldrled1 and ldrled2
BLYNK_WRITE(V1) {
ledControl1 = param.asInt(); // Read virtual button state (0 or 1)
}
// Blynk button for controlling ldrled3 and ldrled4
BLYNK_WRITE(V2) {
ledControl2 = param.asInt(); // Read virtual button state (0 or 1)
}
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Set LED pins as outputs
pinMode(ldrled1, OUTPUT);
pinMode(ldrled2, OUTPUT);
pinMode(ldrled3, OUTPUT);
pinMode(ldrled4, OUTPUT);
pinMode(ldrled5, OUTPUT);
pinMode(ldrled6, OUTPUT);
// Initialize potentiometer pins as inputs
pinMode(potpin1, INPUT);
pinMode(potpin2, INPUT);
// Connect to Blynk
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run(); // Run Blynk process
// Read LDR value
ldrValue = analogRead(ldrpin);
// Read potentiometer values
int potvalue1 = analogRead(potpin1); // For ldrled1 and ldrled2
int potvalue2 = analogRead(potpin2); // For ldrled3 and ldrled4
// Map potentiometer values to brightness (0-255 range for PWM)
int brightness1 = map(potvalue1, 0, 1023, 0, 255);
int brightness2 = map(potvalue2, 0, 1023, 0, 255);
// Send potentiometer values to Blynk
Blynk.virtualWrite(V3, potvalue1); // Send potvalue1 to virtual pin V3
Blynk.virtualWrite(V4, potvalue2); // Send potvalue2 to virtual pin V4
Serial.print("LDR Value: ");
Serial.println(ldrValue);
Serial.print("Potentiometer 1 Value: ");
Serial.println(potvalue1);
Serial.print("Potentiometer 2 Value: ");
Serial.println(potvalue2);
// Control ldrled1 and ldrled2 brightness
if (ledControl1) {
analogWrite(ldrled1, brightness1);
analogWrite(ldrled2, brightness1);
} else {
analogWrite(ldrled1, 0);
analogWrite(ldrled2, 0);
}
// Control ldrled3 and ldrled4 brightness
if (ledControl2) {
analogWrite(ldrled3, brightness2);
analogWrite(ldrled4, brightness2);
} else {
analogWrite(ldrled3, 0);
analogWrite(ldrled4, 0);
}
// Control ldrled5 and ldrled6 based on LDR value
if (ldrValue >= 1000) {
digitalWrite(ldrled5, HIGH);
digitalWrite(ldrled6, HIGH);
} else {
digitalWrite(ldrled5, LOW);
digitalWrite(ldrled6, LOW);
}
delay(100);
}