The sensor isn't perfect, if you aim even a really, really good sensor (Better than the, um, 'classic' Sharp IR sensors) at the same spot on the wall and take a few readings, there will be some variation. If you discard some number of least significant bits, it's possible to get the same reading every time, but your readings will be more granular. You should probably keep the maximum precision, and then try to fix errors in software (i.e., change your data so that an almost straight line really is straight).
What sensor are you using, and what range of measurement do you expect? The output of the sensor is very much nonlinear. This graph (from the datasheet) compares the output voltage on a linear scale with the distance:
You'll notice that it looks a lot like the graph of y=1/x, i.e volts=k(1/distance). This can be used to get a decent first approximation, but division on an Arduino is expensive. You'll have better luck calibrating the sensor and storing the voltage/distance pairs in a look-up table (in program memory, of course). This one comes calibrated from the factory such that a measurement at precisely 24cm measures to 24cm +/- 3cm. Unfortunately, they don't give you a way of knowing what the voltage at 24cm should be except by squinting at this graph.
The sensor will have higher precision at certain ranges. Imagine that there is a random variation of, say, +/- 250mV in your readings (Gaussian if you like, but random is easier). It's hopefully a lot smaller than that, but it makes it easy to visualize. The variation means that your readings with this sensor at, say, 50cm or 70cm will vary over 20 or 30cm, but measurements at 15cm should be within a few cm. This sensor is rated for 10-80cm, but you'll get more accurate readings if you only trust it for 10-25cm or so. If you're controlling the robot, you should be able to move to these distances and get the best readings.
The sensor draws current in large bursts and is probably mounted on a fairly long cable. A capacitor will help stabilize the readings. Don't jam it into the JST; solder it to the PCB on the back. It's drawing a lot of current and it's pretty slow, so small capacitances traditionally used for decoupling (0.1uF) probably won't work. I'd use a 10uF 1206 or 1210 ceramic SMD cap in parallel with a 100uF electrolytic. If you find that high frequency noise is still present, add a 0.1uF 1206 on top of the 10uF. Here's a picture of the locations for soldering (original image from Sparkfun):
You could also try adding a small capacitance on the Vo line to smooth the output. You should experiment to see whether or not that helps. I'd keep it below 100pF, starting at around 10pF. This will create a moving average of the readings in hardware. More circuitry (a series resistor) would enhance the effect, post a comment or another question if you want to build a more complex low-pass filter system for this purpose. Note: The Sharp sensor may not handle driving into a large capacitance well, and might balk or break if asked to change the voltage quickly. It's also possible that it's a single-sided output, and might require a resistor to ground to discharge the capacitor if you add more capacitance than is currently present in the parasitics.
Twisting the cables together will help reduce noise coupled on from external sources like 60Hz mains. Keeping them short will also help mitigate noise.
YOu are entering a world where Electro Magnetic Compatibility is at risk. Pay attention to the stray current spikes that radiate noise (Egress) and their influence on other circuits of high impedance (Ingress). YOu probably also have ripple or the conducted egress and ingress as well.
For radiated noise a handy tool is a small AM radio (not FM) nearby, to locate such noise issues if you dont have a scope.
Noise suppression management may include some common mode chokes to the track or pot lines. Perhaps some supply rail filtering may need to be added around the track.
I would use ferrite beads for each driver with caps after the bead and then use twisted pairs to send the current after going thru a ferrite torroid or similar common mode choke, like those used in Video cables.
Its good to have a kit of parts for such issues.
Add decoupling caps to the breadboard for both sides.
Best Answer
The cheapest dodgiest thing you can do is use a low-side current-sense resistor (0.1ohm will do) and use the Arduino's ADC input with a 1-10K series resistor, over-voltage clamp, and ensure the servo is clamped too.
Let me make some assumptions/recommendations first:
Power your Arduino and the rest of your system from a rechargable Lipo/NiMH battery pack over 7V volts (which means a 2 cell Lipo or ~4 cell NiMH). The battery can power the Arduino Uno as it has an onboard regulator for it's own 5V needs, but I suggest you put the servo on it's own 7805 or better/newer technology linear regulator in order to separate it from the Arduino's supply a little bit, and also in general to have more reliable and safer results from the servo. Most hobby servos are 5-6V recommended input anyway.
The general premise is to use a low-side current shunt resistor, of a low value as to not be too limiting to the system you are measuring, but enough that you can sense the current stress from the stall condition reliably enough with the 5V 10-bit ADC on the Arduino.
simulate this circuit – Schematic created using CircuitLab
I have shown in the schematic above a 2-cell fully charged (8.4V, 4.2V per cell, with 2 in series) Lithium Ion battery, going to a 7805 (or if you can find a better one, please do. LDO style would give better long-term results as the batteries drain into the drop-out region of older models like the 7805) with appropriate input and output capacitors, and then off to the servo. The servo has "close by" a 100uF and 1000uF (1mF) capacitors so that large amounts of current can be provided without tanking the 7805 or the battery too much for short periods of time. Obviously a continuous short/stall it will still affect the system "up stream".
There is a clamping/flyback schottky diode D3, parallel across the servo + and - connections. Not shown is the servo's signal/control input, but you should know how that works. By the way, I suggest you use Arduino's Servo library, not "standard" PWM as the frequencies are too high.
The clamping diode D4 is to protect the Arduino's ADC pin from negative voltages. The series resistor R1 is input current limiting combined with filter cap C5 to form a little bit of low-pass passive filtering, helping avoid false positives for current spikes during the normal operation of the servo.
As current through the servo increases, the voltage across our sense resistor R2 will increase. I set the resistor to 100mOhm, which will allow us to use Ohm's law to see what voltage will be across it during an arbitrary current.
I actually looked at it from the Arduino and code viewpoint, thinking the ADC is 10-bit, meaning 1024 steps. The reference is usually 5V, so 5000mV/1024 is 4.88mV per "unit" of the ADC in the code. Lets say to avoid detecting something small, lets aim for an ADC reading of 20+ to trip the stall current detection code.
Lets say for a value of 25 read on the ADC, 25 Units * 4.88mv/Unit is 122mV on the ADC input in the real world. The required current through the sense resistor to get 122mV across it follows Ohm's law. V = IR, so 0.122V = I * 0.1, which is 1.22 Amps.
I believe that 1.22 Amps is reasonable enough for a stall current on a hobbyist servo, and it may be more than this, but certainly normal movement will not be anywhere near this.
The last thing to note is, if you find the ADC values with 0.1Ohm are not good/high enough, you can easily just double the resistor to 0.2Ohms. Remember that you do not want to limit the servo from normal operation though, but 5V/0.2Ohm is still allowing a short circuit of the servo of a hefty 25 Amps so we are not anywhere near affecting it's operation yet.
The ADC reading code should have some kind of timer/time-out period where if the ADC values are consistently above 20->25 or whatever you choose as your limit (you can tune it later), perhaps for 5 samples in a row, taken at 5ms intervals gives you a response time of just over 25 milliseconds to a legitimate stall condition. That should be plenty! Remember every time a servo starts up, or changes direction, it WILL draw this amount of current for short periods. Try to avoid tripping the "stall" condition too fast.