#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
Servo myservo;
int LDR = 14;
int Poten = 12;
int lcdColumns = 21;
int lcdRows = 22;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
int ledpin = 13;
int freg = 1000;
int channel = 0;
int resolution = 8;
DHTesp dhtSensor;
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(115200);
ledcSetup(channel,freg,resolution);
ledcAttachPin(13, channel);
pinMode(14, INPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(Poten, INPUT);
myservo.attach(18);
}
void loop() {
int p = map (analogRead(12),32,4063,255,0);
int n = map (analogRead(14),32,4063,100,0);
int m = map (analogRead(14),32,4063,180,0);
//int ldr = map (m,0,180,0.1,100000);
int ldr;
if(m <= 91 && m>=0){
ldr = map (m,0,180,0,400);
}
if(m <= 152 && m>=92){
ldr = map (m,0,180,0,1000);
}
if(m <= 180 && m>152){
ldr = map (m,0,180,100,100000);
}
ledcWrite(channel,p);
Serial.print("\nLDR : " );
Serial.println(analogRead(12));
Serial.print("Servo : " );
Serial.println(m);
Serial.println("");
Serial.println("\n----------------------------------");
lcd.setCursor(0, 0);
lcd.print("LDR : ");
lcd.print(ldr/1000);
lcd.print("k LUX ");
if(m>=0 && m<100){
lcd.setCursor(0, 1);
lcd.print("Servo : ");
lcd.print(m);
lcd.print(" % ");
}
if(m>=100 && m<=180){
lcd.setCursor(0, 1);
lcd.print("Servo : ");
lcd.print(m);
lcd.print(" % ");
}
myservo.write(m);
if(n<=10 && n>=0){
lcd.setCursor(0, 1);
digitalWrite(2, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
}
if(n<=30 && n>=10){
lcd.setCursor(0, 1);
digitalWrite(2, 1);
digitalWrite(4, 0);
digitalWrite(5, 0);
}
else if(n<=60 && n>=30){
lcd.setCursor(0, 1);
digitalWrite(2, 1);
digitalWrite(4, 1);
digitalWrite(5, 0);
}
else if(n<=100 && n>=60){
lcd.setCursor(0, 1);
digitalWrite(2, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
}
delay(1000);
}