#include <LiquidCrystal_I2C.h>
#define led 2
int inputPin = 3;
int pirState = LOW;
int val = 0;
const float GAMMA = 0.7;
const float RL10 = 50;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
pinMode(led, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
int analogValue = analogRead(A0);
//val = digitalRead(inputPin);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
lcd.setCursor(0, 0);
lcd.print("Cahaya: ");
if (lux > 50 ) {
lcd.print("Terang");
digitalWrite(led, LOW);
Serial.println("Gerakan Tidak Terdeteksi!");
pirState = LOW;
///
} else {
lcd.print("Gelap ");
digitalWrite(led, HIGH);
Serial.println("Gerakan Terdeteksi!");
pirState = HIGH;
}
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
lcd.print(" ");
delay(100);
}