I'm sure there's a good reason for this but I'm such a noob I can't work it out. I've got an IR reflective optical sensor rigged up to my arduino. The LED side is simply set to high and the input from the detector goes to one of the analogue inputs.
With nothing near the sensor I'm getting a weird input into the board that seems to be some sort of noise. The serial out looks like...
0
0
0
0
0
3
30
74
107
104
50
0
0
0
0
0
1
2
29
72
107
99
77
21
0
0
0
0
etc
Do I need a cap between the detector and the analogue in?
How fast are you reading the analog input? That is, how long are the delays (if any) between calls to 'analogRead()'? I'm thinking that you may have 50Hz (or 60Hz) noise pickup from either a light or by electrical pickup.
But yes, a capacitor might help, wired from the analog input to ground. Start with, oh, say 0.1uF and work upwards...
I had a 150 resistor on the LED side and nothing on the detector side - the max output seemed to be 5V so I dint' think I needed one.
I've now swapped in an 82 ohm on the LED side and a 10k between the detector and the analogue in.
Weirdly the behaviour of the sensor is now the opposite of what I'd expect. The 'regular' noise is still there...
0
0
0
0
1
2
6
7
9
11
12
10
6
1
0
0
0
0
0
0
1
1
4
4
8
10
11
12
7
2
0
0
0
0
0
...but now when an object gets near the output drops to 0.
I've now put a 2.2uF between the detector and the analogue input but I'm still getting the noisy signal...only now all of the values appear to have been increased by 5, i.e. where I was getting zeros before I'm now getting five.