IR Reciever and Emitter as a tripwire

Hello everybody,

I need to make an automated street light for school, for this I needed to use an IR Emitter and Reciever.
It needs to function so that when someone walks past, the lights go from dimmed to fully lit.
I already have a program, but it doesn't function properly. It only works when I press my finger fully against the IR Reciever. The readed value in the serial monitor then changes from about 1020 to 990. But when I try it with a paper or my hand at a longer distance, value doesn't change.

This is the program I'm currently using;

int ledPin = 9;

void setup() {
pinMode(A0, INPUT);
pinMode(A1, OUTPUT);
analogWrite(A1, 820); //512 is uit 614 aan
Serial.begin(9600);

}
void loop() {
Serial.println(analogRead(A0));
if (analogRead(A0) < 1000)
{
for (int fadeValue = 25 ; fadeValue <= 255; fadeValue += 5) {
analogWrite(ledPin, fadeValue);

}
}
else
{
for (int fadeValue = 25 ; fadeValue >= 25; fadeValue -= 5) {
analogWrite(ledPin, fadeValue);
delay(30);
}

}
}

I hope someone can help me.

I needed to use an IR Emitter and Reciever.

There are many kinds of IR emitters and many kinds of IR receivers. Which ones are you using?

The readed value in the serial monitor then changes from about 1020 to 990. But when I try it with a paper or my hand at a longer distance, value doesn't change.

If you are using the proper hardware, and it is properly connected, and powered, you should see much larger variations than that.

  pinMode(A0, INPUT);

It is pointless to set the digital nature of a pin you have a analog device connected to.

  pinMode(A1, OUTPUT);
  analogWrite(A1, 820); //512 is uit     614 aan

Same here. What IS connected to pin A1, and what does analogWrite()ing to it accomplish?

    for (int fadeValue = 25 ; fadeValue <= 255; fadeValue += 5) {
      analogWrite(ledPin, fadeValue);
     
    }

How long do you think this loop will take to execute? You might just as well use digitalWrite(ledPin, HIGH).

There are many kinds of IR emitters and many kinds of IR receivers. Which ones are you using?

Im using this set; http://www.dx.com/p/mini-38khz-infrared-transmitter-ir-emitter-module-infrared-receiver-sensor-module-for-arduino-327293#.WJNCdNfhC1s

It is pointless to set the digital nature of a pin you have a analog device connected to.

Then what should I use? Btw, the Reciever is connected to A0 and the Emitter to A1

How long do you think this loop will take to execute? You might just as well use digitalWrite(ledPin, HIGH).

This is just to set the brightness higher when something crosses.

From the posted link.

The Infrared Receiver is based on HL-A838 integrated infrared receiver modules, IR transmitter module can receive incoming 38KHz modulated infrared signal, and demodulated into logic level, When it receives the modulated infrared signal then output low level, otherwise output high level. IR

So that means that the transmitter must send a 38KHz signal that the receiver can detect. Maybe the tone() function could be used to generate the 38KHz signal. Unmodulated IR will not be received correctly.

analogWrite(A1, 820);

A1 is not a PWM capable pin so analogWrite won't work.

Then what should I use?

To do something pointless? How about the delete key, and stop doing pointless things?

This is just to set the brightness higher when something crosses.

I understood that. But, how fast are the steps changing? The for loop will complete in a few microseconds, at which time the pin will be on fully, so you might as well just turn it on.

In the fading down code, where you have a delay() between steps, the brightness will gradually change. In the fade up code, it will change gradually, too. It's just that the gradient going up is damned near vertical. Might as well just jump to the top.

And, yeah, that's the wrong kind of hardware for a trip wire application. Google laser trip wire. There are some really cheap devices that do exactly what you want.