I've been trying to setup a laser tripwire as a fantasy project. The sketch I'm using looks like this
int ldrPin = A4; // the cell and 10K: pulldovn are connected to a0
int sirenPin = 11; //pin 3 selected!!
int ledPin = A0;
long ldrValue1, ldrValue2;
void setup(void) {
pinMode (sirenPin, OUTPUT); // set the siren pin as output
pinMode (ledPin, OUTPUT); // set the siren pin as output
pinMode (ldrPin, INPUT); // set the siren pin as output
//Serial.begin(9600);
}
void loop(void) {
ldrValue1 = analogRead(ldrPin);
delay(10);
ldrValue2 = analogRead(ldrPin);
if (ldrValue1 - ldrValue2 > 20) {
digitalWrite(sirenPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(1000);
}
else {
digitalWrite(sirenPin, LOW);
digitalWrite(ledPin, LOW);
}
//Serial.print("Analog reading = ");
//Serial.println(ldrValue1); // the raw analog reading
}
[/code]
My issue seems to be with the hardware. I was told a 1k resistor would suffice for the ldr I'm using .It all worked for an hour, then I attempted to extend the ldr with jumper wires and it stopped functioning. Any ideas?