#define led 2
#define tombol 3
int status;
void setup()
{
Serial.begin(115200);
pinMode(led, OUTPUT);
pinMode(tombol, INPUT_PULLUP);
}
void loop()
{
status = digitalRead(tombol);
const float GAMMA = 0.7;
const float RL10 = 50;
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));
Serial.println(lux);
Serial.println(status);
if(lux >= 500)
{
digitalWrite(led, 1);
}
if(status == 0)
{
digitalWrite(led, 0);
}
}