/* Project UAS
Nama: I Putu Wisnu NOvayana
Nim :190010078
Keals:VA191
*/
#include <LiquidCrystal_I2C.h>
const float GAMMA=0.7;
const float RL10=50;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
// put your setup code here, to run once:
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
int analogValue=analogRead(A0);
float voltage=analogValue/1024.*5;
float resistance=200*voltage/(1-voltage/5);
float lux=pow(RL10*1e3*pow(10,GAMMA)/resistance,(1/GAMMA));
lcd.setCursor(2,0);
lcd.print("==> ");
if(lux>150){
lcd.print("Terang ");
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
else if(lux>100){
lcd.print("Redup ");
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
tone(5, 430, 150);
delay(2000);
}else{
lcd.print("Gelap ");
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
tone(5, 430, 150);
delay(100);
}
lcd.setCursor(0,1);
lcd.print("Nilai lux");
lcd.print(lux);
lcd.print(" ");
delay(100);
}