Arduino R3, servos and AIO conflicts

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
raygeeknyc
 
Posts: 64
Joined: Wed Sep 06, 2006 12:15 am

Arduino R3, servos and AIO conflicts

Post by raygeeknyc »

Howdy all
I am trying to control 2 5g microservos with 2 (10K) potentiometers using an Arduino R3.
(Circuit diagram attached).
circuit (1).png
circuit (1).png (19.1 KiB) Viewed 65 times
After some debugging, I have stripped down my code to the following copy of the "knob" demo with 2 pots and 2 servos.
Here's the issue: when one servo and pot are connected, all works as expected. When I connect a second servo, there are two problems:
1) The range of the pots is reduced to ~100:~900 (rather than 0:1023)
2) Rotating either pot affects the reading of the other pot.

My suspicion: this is a matter of drawing too much power from the Arduino's 5V pin?

Code: Select all

#include <Servo.h>

Servo myservo1, myservo2; 

int potpin1 = A0; 
int val1; 
int potpin2 = A1;
int val2;

void setup() {
  myservo1.attach(5);
  myservo2.attach(6);
  Serial.begin(9600);
}

void loop() {
  // pot-servo 1
  val1 = analogRead(potpin1);       
  Serial.print("pot1: ");
  Serial.print(val1);             
  val1 = map(val1, 0, 1023, 0, 180);   
  myservo1.write(val1); 
  
  // pot-servo2               
  val2 = analogRead(potpin2);          
  Serial.print(", pot2: ");
  Serial.println(val2);             
  val2 = map(val2, 0, 1023, 0, 180);   
  myservo2.write(val2); 
  delay(15);                        
}

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino R3, servos and AIO conflicts

Post by adafruit_support_bill »

Servos are pretty power hungry devices. So you may be overloading the regulator on your UNO.
They are also very electrically noisy. And since they are sharing power and ground with your analog circuits, those are likely to get polluted with that noise.

A separate power source - as well as entirely separate power & ground wiring for your servos is recommended. You do need to have a common ground. But it should go directly to the Arduino ground pin and not share any wiring with your analog circuits.

User avatar
raygeeknyc
 
Posts: 64
Joined: Wed Sep 06, 2006 12:15 am

Re: Arduino R3, servos and AIO conflicts

Post by raygeeknyc »

Thanks
To recap/verify: Use separate power supplies and connect the two grounds (servo PS GND to Arduino GND pin)?

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino R3, servos and AIO conflicts

Post by adafruit_support_bill »

Yes. That should avoid any interference and power shortage issues.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”