#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHT22PIN 32
DHT dht(DHT22PIN, DHT22);
int i =0;
float GAMMA = 0.7;
float RL10 = 33;
int light = 25;
LiquidCrystal_I2C lcd1(0x27, 16, 2);
LiquidCrystal_I2C lcd2(0x3F, 16, 2);
byte customChar[] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
void setup() {
lcd1.init();
lcd2.init();
pinMode(light, INPUT);
dht.begin();
lcd1.createChar(0, customChar);
}
void loop() {
//light
int lux = analogRead(light);
float voltage = lux / 4096. * 3.3;
float resistance = 2000 * voltage / (1 - voltage / 3.3);
float val = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
lcd1.setCursor(0, 0);
lcd1.print(val);
if (val < 100) {
lcd1.setCursor(0, 1);
lcd1.write(byte(0));
}else if (100<val<500){
for(i;i<2;i++){
lcd1.setCursor(i, 1);
lcd1.write(byte(0));
}
}
//dht
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd2.setCursor(0, 0);
lcd2.print("Nhiet Do:");
lcd2.setCursor(11, 0);
lcd2.print(t);
lcd2.setCursor(0, 1);
lcd2.print("Do Am:");
lcd2.setCursor(11, 1);
lcd2.print(h);
delay(800); // this speeds up the simulation
}