Dear friends!
The code for this project is pretty simple, but… I need a help.
Project:
-The resistance value becomes smaller when there is much light in the room. So in the dark the led remains off because the resistance has become very big. It’s also called light-dependent resistor (LDR).
The LED on the Arduino does not turn on and does not turn on when the condition is met. Why? What to fix?
#define CAYENNE_PRINT Serial
#define led_pin 14
#include <CayenneMQTTESP8266.h>
char ssid = “”;
char wifiPassword = “”;
char username = “”;
char password = “”;
char clientID = “”;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(led_pin, OUTPUT);
}
void loop() {
Cayenne.loop();
Cayenne.virtualWrite(2, analogRead(A0));
delay(1000);
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(0, millis());
}
CAYENNE_IN_DEFAULT() {
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
int i=getValue.asInt();
digitalWrite(led_pin,i);
if (i < 800) {
digitalWrite(led_pin, HIGH);
}
else if (i > 820) {
digitalWrite(led_pin, LOW);
}
}