Hi! I am working with nodemcu, LDR, and an AC bulb. I want the Blynk to switch on the bulb when I press the allocated button and the bulb lightens up after detecting the LDR value but when I run the code after compilation of code the bulb lightens up without detecting the LDR. Here is my code. Please suggest me what should I do as soon as possible. Thanks in advance!
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = “1827835455ae4845b3bb53da474338dc”;
// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “NTC Offfice”;
char pass[] = “ntcswl00001”;
String relay1State = “off”;
String relay2State = “off”;
String relay3State = “off”;
String relay4State = “off”;
const int relay1 = 5; // GPIO5 D1
const int relay2 = 4; // GPIO4 D2
const int relay3 = 0; // GPIO0 D3
const int relay4 = 2; // GPIO2 D4
int LDR = A0;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(LDR, INPUT);
}
void loop() {
int LDRValue = analogRead(LDR);
Serial.print("sensor = ");
Serial.print(LDRValue);
if (LDRValue <=15 )
{
Blynk.virtualWrite(D1 , HIGH );
Blynk.virtualWrite(D2 , HIGH );
Blynk.virtualWrite(D3 , HIGH );
Blynk.virtualWrite(D4 , HIGH );
Serial.println(“It’s Dark Outside; Lights status: ON”);
}
else
{
Blynk.virtualWrite(D1 , LOW);
Blynk.virtualWrite(D2 , LOW );
Blynk.virtualWrite(D3 , LOW );
Blynk.virtualWrite(D4 , LOW );
Serial.println(“It’s Bright Outside; Lights status: OFF”);
}
}