#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const float GAMMA = 0.7;
const float RL10 = 50;
#define LDR 34
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
pinMode(LDR, INPUT);
Wire.begin(21, 22);
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
}
void loop() {
int analogValue = analogRead(LDR);
float voltage = analogValue / 4095.0 * 3.3;
float resistance = 2000 * voltage / (1 - voltage / 3.3);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA)) / 1.809;
Serial.println("Luminosidad: " + String(lux));
lcd.setCursor(0, 0);
lcd.print("Luminosidad:");
lcd.setCursor(0, 1);
lcd.print(lux);
delay(1000);
lcd.clear();
if (lux < 100) {
Serial.println("Obscuro");
lcd.print("Obscuro");
} else if (lux > 100 && lux < 1000) {
Serial.println("Parcialmente iluminado");
lcd.print("Parcialmente iluminado");
} else {
Serial.println("Totalmente iluminado");
lcd.print("Totalmente iluminado");
}
delay(2000);
}