After that was fixed, I changed the code so that the LED would blink in a loop unless the value of the LDR was less than 400, in which case it would turn off. Through this experimentation is how I was inspired to create an alarm that alerts me when my cat is on the counter.
//Constants
const int pResistor = A0; // Photoresistor at Arduino analog pin A0
const int ledPin=9; // Led pin at Arduino pin 9
//Variables
int value; // Store value from photoresistor (0-1023)
void setup(){
pinMode(ledPin, OUTPUT); // Set lepPin - 9 pin as an output
pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)
}
void loop(){
value = analogRead(pResistor);
if (value >= 400){
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
}
else{
digitalWrite(ledPin, LOW); //Turn led off
}
}
No comments:
Post a Comment