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);
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?
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.
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.