#define LDR_PIN 12
#define ledMerah 2
#define ledBiru 4
#define ledPutih 15
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
// put your setup code here, to run once:
pinMode(LDR_PIN, INPUT);
pinMode(ledMerah, OUTPUT);
pinMode(ledBiru, OUTPUT);
pinMode(ledPutih, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(12);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print(lux);
if (lux < 100){
digitalWrite(ledBiru,HIGH);//untuk lampu indicator untuk cahaya pagi dan sore
digitalWrite(ledMerah,LOW);
digitalWrite(ledPutih,LOW);
}else if (lux > 1000) {
digitalWrite(ledMerah,HIGH);//untuk lampu uindicator cahaya siang
digitalWrite(ledPutih,LOW);
digitalWrite(ledBiru,LOW);
}else {
digitalWrite(ledMerah,LOW);
digitalWrite(ledPutih,HIGH);
digitalWrite(ledBiru,LOW);
}
delay(1000);
}
// just change the LDR innput sensor went you wanna test it while you play it
// it need a little bit time to process but it works