I am on a steep learning curve, and a bit bamboozled by my sharp distance sensor (data sheet). I am building a project with two distance sensors that signal an Arduino to operate a servo motor when an object comes into range. This currently works well, except that the sensors are outputting a relatively high voltage all the time, so I have to set a very high cutoff voltage in the Arduino code, or the motor is triggered all the time - eg both sensors are giving the Arduino numbers like 350-450 via the analog Read command (which should be about 1.7 - 2.1V as far as I understand it) all the time. This means that if I set a cutoff of 550 or 600, the setup works, but only if an object is within 12cm of the sensor (which should be able to detect objects as far away as 80cm). The sensors are not optically interfering with each other.

I am using an old computer ribbon cable to connect both sensors to the Arduino and I am suspicious that this is somehow causing noise in the output voltage, but the Arduino never seems to be read values less than about 300 (1.4V), and I would have expected noise to give some low readings sometimes. Any help would be greatly appreciated. I tried posting a circuit diagram, but as a guest user, the site won't let me. Also, I'd post the code, but it is embarrassingly messy. The Arduino and the servo have separate power sources with common ground, the sensors are powered from the regulated 5V Arduino supply, and connected to separate analog pins.

<code>circuit diagram</code>

  • \$\begingroup\$ Do you have a link to the circuit diagram? A picture of the circuit? Preparing for asking a question is always a good moment to polish up your code and I personally like to copy the code to a separate sketch and cut away as much code as possible to effectively reproduce the problem. \$\endgroup\$ – jippie Mar 1 '13 at 10:09
  • 1
    \$\begingroup\$ What are the ambient light conditions? Do you still get this behaviour in a dark room? \$\endgroup\$ – pjc50 Mar 1 '13 at 10:12
  • \$\begingroup\$ Thanks for the reply - I am now able to post a picture - so circuit diagram is now in the original question. As for ambient light - same in dark room. \$\endgroup\$ – Winston Mar 8 '13 at 10:11

If your power supply is indeed the issue, then add a simple low pass filter in your power supply connections as close to the sensor as possible. I'd start with the following configuration to see if it improves the situation. Double check if Vcc at the sensor is 4V5 - 7V.


simulate this circuit – Schematic created using CircuitLab

Assuming that the device is powered by Arduino's 5V and assuming that the device is drawing 30mA of current, the voltage accros R1 will be 0.3V and the supply voltage for the sensor will be 4.7V, sufficient according to the datasheet. R1 and C1/C2 form a simple low pass filter that will suppress high frequency noise from the power supply.

Keep wires as short as possible, keep them as close together as possible. If possible twist the wires for the power supply and twist the wires (V(out) and GND) for the output.

  • \$\begingroup\$ What i also like to add in my setup is pull-down resistor on sensor out line. R~10k. In that way i can detect that sensor is broken or missing and i dont have false readings. \$\endgroup\$ – Gossamer Mar 1 '13 at 11:58
  • \$\begingroup\$ Can I ask what the purpose of the second capacitor is? Is it just to increase the total capacitance to 10.1uF, or is it more subtle than this? Also, what cutoff frequency are you aiming for, and how do you decide? Are there known noise frequencies from the arduino, or is it just a guess? \$\endgroup\$ – Winston Mar 10 '13 at 2:34
  • \$\begingroup\$ The construction of the 10\$\mu\$F capacitor is different from the 100nF capacitor and that causes high frequency response to be different. Electrolytic caps have a relatively poor performance for higher frequencies, whereas the other cap has does much better. It is not to add another 1% to the total capacity, it is to improve the response to high frequencies. \$\endgroup\$ – jippie Mar 10 '13 at 3:26
  • \$\begingroup\$ As I wrote in my answer "I'd start with". It's just my feeling that it should noticable improve the situation. If it doesn't improve enough to your liking you can increase the 10\$\mu\$F electrolytic cap, leave the other components as they are. \$\endgroup\$ – jippie Mar 10 '13 at 3:29

Take a look at the following example on how to filter out the noise from Sharp IR

P.S. this is not quite the answer, but I cant add the comment cause i don't have enough rep.

  • \$\begingroup\$ +1 for that link. I've had really really big noise problems on that sensor until I placed some capacitors directly on the sensor power pins. \$\endgroup\$ – AndrejaKo Mar 1 '13 at 10:46
  • \$\begingroup\$ There are better/cheaper/more reliable ways to filter power supply noise than using a goldcap. You are right however that if power supply is bad, the output will be bad too. \$\endgroup\$ – jippie Mar 1 '13 at 11:09

After reading the answers above, I checked to supply voltage to the IR sensor, and found it was only 4.1V (less than data sheet recommends), and I realised I had a 5V power supply to the arduino, but the voltage regulator had taken some of that away. I have increased the arduino supply to 12V, and the sensor is now getting 4.7V and is much happier. Still some noise, but not the consistently high output voltages of before. Thanks

  • \$\begingroup\$ That makes sense because of the regulator drop-out. You may still have an underlying problem though, 4.7V is a bit low looking at the regulator used you should get 4.95V minimum. But anyway see how it goes. \$\endgroup\$ – PeterJ Mar 8 '13 at 10:36
  • \$\begingroup\$ The set-up currently has pretty long wires to the sensor - I haven't yet worked out what the minimum length I can get away with is. I am trying to get my head around the low-pass filter (above) to give that a go also. \$\endgroup\$ – Winston Mar 10 '13 at 2:36

Final answer - after the voltage issues were corrected, the output was still a little erratic. A low pass filter on the power supply to the sensors (I tried multiple cutoff frequencies) didn't help. Additionally, I started getting odd static electricity like shocks from the casing of the sensors. I then tried 10K pull down resistors on the sensor input to the arduino. Results became consistent and the static type shocks disappeared.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.