#define LIGHT_SENS 6
#include <Servo.h>
Servo myservo;
int pos = 0;
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
Serial.begin(9600);
pinMode(LIGHT_SENS, INPUT);
myservo.attach(6);
}
void loop() {
int analogValue = analogRead(LIGHT_SENS);
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);
if (lux < 400) { pos=0;}
if (lux > 400 && lux < 2000) { pos=70;}
if (lux > 2000 && lux < 10000) { pos=120;}
if (lux > 10000) { pos=180;}
myservo.write(pos);
delay(150);
}