Hi I am new to the arduino world and I am learning it for a class I am currently taking. I am working on a project where I planned to use the Sharp GP2Y0A21YK IR Proximity Sensor to detect objects or movement and according to the different distances to turn diff on colored LEDS. However, my readings on the serial monitor comes out all weird and I have no way of managing it. I uploaded this code that I found
However, the readings I get usually come out like this even without me doing anything to it. It's just currently sitting on my desk. Even if I place my hand in front of it the readings come out not much different.
Does anyone have any suggestions how to fix this? I need to get this up running by Monday afternoon so help would be GREATLY appreciated. I don't have any programming background so this is all rather difficult for me.
I did try that code from the page and strangely enough all of a sudden it doesn't output zeros as sets. I also tried to remove any sort of lighting interference. I even tried it in the dark as I was aiming to use this sensor attached to the front of a pair of glasses to sense objects in the dark.
looks more like this now, but I am still having problems measuring any sort of distance that will allow me to more accurately control 3 different LEDs at different distances:
141
160
188
193
196
219
284
386
452
439
445
478
864
987
726
132
95
259
78
0
0
0
13
0
23
60
106
232
508
708
871
765 < ------------- this is when I put an object near around 50cms
693
629
344
259
177
53
0
0
465
1023
1023 < ------------ this spike shows up after remove the object
1023
962
718
527
349
129
82
42
0
266
1023
990
818
794
881
837
806
764
705
651
587
526
512
464
429
404
397
379
361
340
335
320 < --------------- then slowly progresses back down to around 100-300 when i have nothing in front of it
317
299
303
295
282
276
268
250
248
236
232
219
214
192
194
I'm not sure what the readings should normally look like if it's working properly..but it just looks very off to me.
I've read else where I should add a 100uf capacitor to improve the readings, and I am going to try that tomorrow when I go out to get some. But does anyone have suggestions how I can improve this? I really need to get this to work as well as I possibly can before Monday rolls around as I'm going to be getting graded.
robtillaart: how would I go about doing an average for multiple readings? I currently have the pigtails connected with some wired alligator clips to test. I am not sure if that has been making a difference with my readings.
Chagrin: I'm not sure what you mean by grounding the plastic case. I haven't read that anywhere yet.
I went out trying to find 100uf capacitor but unfortunately both the radioshack and fry's near me are out so as of now that's not an option anymore
The case of the sensors is a conductive plastic material. Don't believe me, check it out with an ohm meter. To insure reliable, noise free measurements, make sure you ground the case. If the case is not grounded and there is no target, or the return signal is weak, the sensor sometimes "thinks" there is a target and that it is wandering around.
int sensorValue = 0;
void loop()
{
sensorValue = (analogRead(A0) + 15 * sensorValue) / 16; // 1x new and 15 times old makes 16 readings)
Serial.println(sensorValue);
delay(1000);
}