Sparkfun Proximity Sensor Trouble

System:

Arduino Uno
Monster Moto Shield LINK
Long Range Prox Sensor LINK
Short Range Prox Sensor LINK

Basically, I am trying to create a ballast system for a vehicle that is pulling a large mass. When the front end of the vehicle comes off the ground, an the short IR sensors reads the height. The motor sends the mass of weights forward to return the front wheels to the ground. The long IR sensor keeps track of the position of the weights so it does not run off either end of the track.

I think that is a decent enough description to give you an idea of what the code should accomplish. I realize it is far from finished. See code “Josh_Ballast…”

ISSUE:
The IR sensors are not working. My issue is that they always read the minimum distance (4.00 in and 5.00 in) in the serial monitor. No matter where I place my hand in front of them, the numbers do not change.

This is because the voltage on both A0 and A1 pins stays at 4.49V. I cannot get the voltage to change. However, if I strip the code down to nothing but one IR sensor (to test if each sensor was working) it works somewhat. By this, I mean that I only have one sensor plugged into the Arduino at a time. Theoretically the serial monitor would read one at a specified distance and the other at the minimum distance. However, the monitor shows them both reading the same distance. It’s like the pins are tied together because I get the same voltage on them no matter what I do. See code “IR_test…”

Could the Uno be soldered poorly? It is new, but that doesn’t necessarily mean anything.

Do I not understand correctly how the A# pins work? They should have 0 volts on them unless something is plugged into them, correct?

I got the code working two days ago (by that I mean compile, that is always an accomplishment for me) and have been stuck because these sensors, or me, cannot get over this hump. I was hoping to spend the weekend fine tuning the array tables and motor logic.

Thanks to all in advance. I appreciate any help given.

Josh_Ballast_4.11.2015.ino (8.47 KB)

IR_Test_4.12.2015.ino (341 Bytes)

Look here : http://forum.arduino.cc/index.php?topic=314844.0

Floating ( when it is not connected ) analog pin picks noise and "signals" from other pins.

Thanks, I read that thread.

However, why do they both read the same thing when they are both plugged in? I was very confused when they both read 4.5V no matter what I seemed to do.

These sensor datasheets are written by a noob.

It gives no info about the output pin of the sensor other than voltage.
How much can it source or sink.
Maybe it's even open collector/drain.
Who knows.

I would first connect the sensor to 5volt and ground, and measure the output voltage with a DMM.
Let us know what you get.

Not a programmer, so shoot me if I'm wrong.
I don't see why you use "float" for height and distance.
Analogue inputs can only read 1024 values (0-1023).
IF you want to convert that height/distance number to e.g. milimeters, for humans to understand.
Maybe then you need a decimal place.
Leo..

I can tell you that individually, the sensors are working. The voltage changes with respect to distance and I have verified it for both sensors.

Should I change the height and distance to integers? I am not sure what difference that will make, other than display differently on the serial monitor.

  height = analogRead(heightIR);
  distance = analogRead(distanceIR);

It is unlikely that these sensors output a voltage directly proportional to distance. The analogRead() function returns an int. Storing that int in a float adds no value.

Ok, so sensor is working as it should.
Next I would connect ONE sensor to an analogue input, and write/use a simple program to display the analogue value on the serial monitor.
You should see numbers between ~50 and ~650.

Basic fault-finding is peeling back the layers, and adding one layer at the time.
Leo..

Turns out the Monster Moto shield is using A0 and A1. Or at least, when I have the shield stacked on the Uno, pins A0 and A1 see 4.5V. Not sure why yet.

Moved the sensors to A4 and A5 and works fine now.

One other question:

I'm seeing a lot of noise on the sensors. Datasheet says put a 10uF cap between supply and ground. I am going to try that, but I was wondering why? Shouldn't the supply from the Arduino be a pretty well regulated 5V? I would think the cap should go between signal and ground.