/*
. . ........ .... .. ...... ........
MMMM MMMMM MMMMMMMMMMMMMMMMMMM MMMMMMMMMM. MMMMMMMMM
MMM.MMMMMMM MMM MMM .MM.MMM MMM ......... .... ... . . .
MMM MMMMMMM . .MM. MM. MMM MM. . MMM MMMMMMMMM MMMM MMMMM.MM MM
MMMMMMMMMMMM. .MMM MMM. .MMM.MMMMMMMMM ........ MMM MM . M .MMMMMMMM.
MMM .MMM MMMMMMMM.MMMMMMM. MM .MMM. MMMMMMMM. MMM .MMMM MMMM MMMMMM.
. ... . . ......
*/
int photocellPin = 2;//define the LDR to D2;
int ledPin =12;
int val =0; //val to store the data;
void setup(){
pinMode(ledPin,OUTPUT);//set the ledPin to output;
Serial.begin(9600);
}
void loop(){
val = analogRead(photocellPin);
Serial.println("current light is");
Serial.println(val);
if (val<350){
//512 =2.5V, you can modify this to adjust the sensitivity;
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
delay(1000);
}