Anyone use AnalogReference() to increase accuracy of pin reads?

Hello fellow geeks/geekets!

This is my first forum post here at Arduino. I have been learning arduino/3d printing like a madman over the last three months and now I have here stood on my workbench a set of robot legs(12DOF) that use ir light sensors at the joints to give accurate position data to my arduino mega 2560.

I have a 5V voltage regulator chip providing the power to the mega 2560 and also the supply for the phototransistors which give voltage readings to the analog pins. My question is this:

Given that I have the same regulated 5V supply to the phototransistors and to the arduino board, would using analogReference() give me any more accuracy over my reads?

My code polls 12 analogue pins continuously to give real time info about limb positions, so would the analogReference function update quicker than 2kb worth of code looping, to deal with small voltage fluctuations and give more accurate reads?

I notice that voltage reads (0-5v) divided over a scale of roughly a thousand seems to fluctuate randomly ~ 30 points or so between reads and wondered if analogRead() function would deal with this fluctuation and stop my legs buzzing and trembling.

However if analogRead function is much slower, it would probably work against stability as it would create delayed reactions.

Sorry if this all sounds like gobbledy-goop. Thanks for any input :slight_smile:

Hi, welcome to the forum.

The internal reference voltage is often more reliable than the 5V. Sometimes the analogReference() can be useful. For example to measure absolute voltages, the internal reference is better.

However, if you read an resistive value which is powered by the 5V, then using the internal reference voltage could be worse. For example, a LDR or a IR phototransistor (with a resistor) have an output that changes if the 5V changes. If the Arduino uses 5V as reference, also the reference changes, and thereby eliminating the inaccuracy.

What kind of circuit do you use for the phototransistor ? Perhaps you have to filter some noise with a capacitor.

Hi Peter,

Thanks for the insight! That's really helpful. I've been working on my shaky legs today and I realise a lot of it was because of how long the digital pins were being written to when controlling the legs instead of some inaccuracy on the analog read side. Plus I tided all of the cabling and soldered all of the connections that I possibly could and I have all but eliminated any noise on the analog reads. I can now do multiple reads over time and get within ~2 points (on a scale of 1024) when the batteries are fully charged. BTW the phototranistor is a photoreflector, with the transistor emitter outs connected to the A0 - A11, but also to their own 4.7k pull down resistors to adjust the sensitivity. I experimented with this value to get the best scale to the analog reads. I'm probably going to stick to the internal reference now. I realise I just need to make the legs more mechanically stable and perhaps make the feet wider ( which I did not want to do because I see that as a cop out).

Cheers. Might try to post a video if I can.

here is my project so far. The focus is trying to use the processing power of arduino to use cheap motors to make controlled movements so that eventually robotics will be available to kids who can't afford £30 servos, which is most of them. Got a long way to go. But getting there.

Thanks for the video. I was expecting something else, but those are indeed robot legs :P There is a lot going on.

When you tidy the cables, keep wires with current to/from motors away from sensor wires.

Keep also wires to motors next to the wire with returning current. Suppose a motor has a power '+' wire and '-' wire to GND. The '-' wire is the returning ground current so to speak. When those two wires are close to each other, they don't produce a lot of electrical noise. But when there is a few millimeter space between them, those wires spread electric noise around them.

Yep, I'm not quite at asimo level yet. I do wonder what you pictured when I said 'robot legs'. ha ha. Thanks for the recommendations. Unfortunately my eagerness led me to cable 6 of the sensor wires directly next to the motor wires. In the back of my mind I knew that EM interference would be an issue to the sensor wires but this is the very first revision, so I will design in some distance and cable management when I next load up google sketchup to do a V2 of the legs. Very interesting point you made about the motor wires being cabled in close proximty together to avoid amplification of EM fields. Hadn't considered that at all. The sensors have a common ground, but the motors have two cables each which are essentially ~ directly out of the L298 drivers. Will also look at designing cable management to increase proximity of motor drive wires along their length.