1

I'm using the GP2Y0A21YK Sharp IR Sensor in a ball and beam system where I'm trying to balance the ball in the center of the beam using the IR Sensor as a distance locator and a servo motor to tilt the beam. I'm using a PID Controller for the system. However, something odd happens when I apply the code. When the servo motor is disconnected, I'm getting accurate readings of the location of the ball. However, as soon as I plug in the servo motor, the distance reading is completely off and inaccurate. I've read that powering the Arduino using both the USB port and Plug will make the readings more stable. However, I've tried that and it only improved the readings by a small bit. What can be causing this problem? Since the code and the schematic would take a bit of a space, kindly let me know if they are needed and I'm happy to provide.

1 Answer 1

1

It is likely your power source supplies insufficient current to power both the servo and the Arduino reliably.

It is also possible that the motor in the servo is creating noise on the power rails and inducing unexpected behavior in the Arduino. But the former is more likely.

Consider using a power source which can supply more current. For instance, D size cell batteries can supply much more current than a small 9 volt battery.

Also consider using a separate power source for the Arduino and the motor. Many resort to this option for such projects as you describe here.

2
  • Thank you for your reply. How do you suggest I power the motor separately? Since it's plugged to the 3.3V port on the Arduino. Would two AAA batteries do the job?
    – Zelreedy
    Commented Sep 2, 2021 at 12:44
  • With out knowing more about the servo it is difficult to tell. However, Alkaline Primary AAA batteries provide less current than AA sized, and those less than C sized. The same can be said for D size. This is why I suggested the largest commonly available battery. To address a possible and likely problem you are having. For common servos only the controlling wire is connected to the Arduino. The ground is common to both the Arduino and servo. The power leads of each can be connected to one sufficiently large or two smaller power sources. Usually these need to be the same voltage.
    – st2000
    Commented Sep 3, 2021 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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