I am using SHARP GP2Y0A21YK - infrared distance sensor - to sense if a thing is being dropped at the front of the sensor. (for example, detecting somebody throw a thing into a trash can hole)
First few days I remember the sensor worked quite well - although it often misses small objects moving fast. But suddenly it started making problems.
First, it makes arduino (NG and Dec both) board doing erratically. For example, serial print values get messy, and don't regularly send signal. Sometimes the board seems to crash down.
So I searched this forum and added 10ohm at the ground pin of the sensor - then it doen't make the board unstable. Why is it so? According to the sensor's spec., it doesn't seem to need any resistance at all. (more, it worked well without it)
Second, after adding the resistance, sensor output values are not stable. for example, when arduino read V0 value from the sensor, there are big spikes every 10~20 signals (every 1 or 2 seconds).
Why are there these spikes? I should eliminate them, but using an average of last ten values isn't for my application because the real signal will also be missed.
Somebody please help me!!!
ps> if IR distance sensor isn't suitable for my case (catching fast-moving object at 10cm distance from sensor), I'll appreciate other options also!
Make sure that the sensor's supply is decoupled properly. Start with 10 ohm between supply and sensor's 5V and put 47uF across the sensor's supply. If that doesn't do it Google "supply decoupling"
Remove the 10 ohm from the sensor ground, that is an "earth lift" resistor and I wouldn't have thought it would have helped in this situation.
As grumpy mike (and more recent Sharp IR datasheets say), you need to put at least a 10 uF capacitor across the sensor's power supply lines (5 V and ground) somewhere near your sensor (the closer to the sensor unit itself, the better).
You should definitely be averaging your sensor readings. Sharp distance sensors can be quite noisy, and if you simply take one sample the results will be unreliable. Averaging the last ten values will not cause you to miss the real signal, it will give you a filtered version of the real signal. If you're worried that you won't have the most recent distance measurement, don't be. The update rate of your distance sensor is something like 25 Hz (i.e. it updates every 40 ms) with an additional 5 ms delay before the output is reported. What this means is that you are guaranteed to have times when your distance measurement is from 45 ms earlier, so your program needs to be able to handle this level of delay. Averaging ten ADC measurements on the Arduino only takes around 1 ms, so this won't cost you at all given the much greater timing restrictions posed by the sensor itself. I personally suggest you average your readings in 50-sample blocks (so your average will span the last 5 - 6 ms of data).
If for your application you need something more responsive, have you considered using a break-beam sensor? If that's not an option, you should be able to get decent results using a reflectance sensor (IR LED-phototransistor pair), which has a very fast response time. The reflectance sensor won't work well at distances much beyond 15 or 20 cm, though, nor will it work if there is a lot of ambient IR incident on the phototransistor (so you might need to shield the receiver).
One additional question : what determines the size of capacitor? If I used 47uF instead of 100uF, then what's the difference ?
Probably very little difference.
The bigger the capacitor the more noise suppression you get as it acts as a reservoir. Also if your circuit takes a lot of current you need more capacatance to give you the same effect as you would get with a lower current device for a given capacitance.
However, as the capacitor gets bigger you also get more inductance and while it holds more is likely to let higher frequencies through. To get round this often a small capacitor about 10 to 100nF is placed across the big one. Bigger capacitors cost more and are physically more bulky so you want to use as small as you can get away with but anything between 10uF and 220uF will probably suffice in this application.
This is a great post about the Sharp distance sensors.
Dave tested different options for capacitance , grounding the case, tested the actual distance numbers, etc. check out his article: