//******LDR, pin yg dipakai*********************************************
#define LDRanalog 27
#define LDRdigital 26
#define led 33
//******LDR, pengukuran lux*********************************************
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
//*****SERIAL MONITOR, setting baud rate***********************
Serial.begin(115200);
pinMode(led, OUTPUT);
}
void loop() {
//*****LDR, pembacaan analog dan digital***********************
int nilaiDigital = digitalRead(LDRdigital);
int nilaiADC = analogRead(LDRanalog);
//*****LDR, menghitungR V, , LUX (hanya jika menggunakan A0****
float voltage = nilaiADC * 5/4095.0;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
//*****SERIAL MONITOR, menampilkan digital, ADC, lux, voltage**
Serial.print("Nilai Digital = ");
Serial.println(nilaiDigital);
Serial.print("Nilai ADC = ");
Serial.println(nilaiADC);
Serial.print("Lux = ");
Serial.println(lux);
Serial.print("Tegangan = ");
Serial.println(voltage);
if(lux<100){
digitalWrite(led, HIGH);
}
delay(500);
if(lux>100){
digitalWrite(led, LOW);
}
}