/*This program increases luminosity of a LED when ambient luminosity is decreasing. It is necessary
to regulate the higher and lower value in function of the place where you are meassuring*/
int ldr = 0; //define a pin for Photo resistor
int led = 11; //define a pin for LED
int higher = 945;
int lower = 660;
void setup()
{
Serial.begin(9600); //Begin serial communcation
pinMode( led, OUTPUT );
}
void loop()
{
int value = analogRead(ldr);
Serial.println(value); //Write the value of the photoresistor to the serial monitor.
//If the limits are exceeded value is equal to the maximum or minimum
if (value >= higher) {
value = higher - 1;
}
if (value <= lower) {
value = lower + 1;
}
value = map(value, higher, lower, 0, 255);//Change the range and invert it to
//increase the intesity of led when resistance
//of ldr is increasing.
analogWrite(led, value); .
delay(20); //short delay for faster response to light.
}