#define ldrpin A0
const float gamma = 0.7;
const float rl10 = 50;
#include <LiquidCrystal.h>
#include <IRremote.h>
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
//lcd.print("Hello World!");
receiver.enableIRIn(); // Start the receiver
}
int power = 0;
void loop() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(rl10 * 1e3 * pow(10, gamma) / resistance, (1 / gamma));
if (receiver.decode()) {
switch (receiver.decodedIRData.command) {
case 24:
if (power == 0) {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("POWER OFF");
power = 1;
digitalWrite(LED_BUILTIN, LOW);
} else {
lcd.clear();
lcd.print("POWER ON");
power = 0;
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
}
break;
}
receiver.resume(); // Receive the next value
}
if (power == 0) {
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
digitalWrite(LED_BUILTIN, HIGH);
}
//Serial.println(receiver.decodedIRData.command);
delay(100);
}