#define PHOTORESISTOR_AO_PIN 12
#define PHOTORESISTOR_DO_PIN 14
#define BIT_DARK 400
#define DARK 100
//R-19 , G-18 , B-5
const int R = 19;
const int G = 18;
const int B = 5;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
}
void loop() {
int analogValue = analogRead(PHOTORESISTOR_AO_PIN);
float voltage = analogValue * (3.3 / 4095.0); // Convert the raw value to voltage (assuming 3.3V reference)
float lux = map(analogValue, 0, 4095, 0, 10000);
Serial.print("lux = " + String(lux));
if (lux < DARK){
Serial.println(" => DARK");
analogWrite(R, 2);
analogWrite(G, 0);
analogWrite(B, 150);
}
else if (lux < BIT_DARK){
Serial.println(" => BIT_DARK");
analogWrite(R, 0);
analogWrite(G, 20);
analogWrite(B, 20);
}
else {
Serial.println(" => LIGHT");
analogWrite(R, 255);
analogWrite(G, 255);
analogWrite(B, 255);
}
delay(1000);
}