Help! Science project and struggling to get it to work

We are trying to get three servo motors to work and be controlled by three different potentiometers. However, only the first one is working correctly. The other two controllers are not controlling their servo motors. When we move one servo, the other moves slightly and I know there is a way to adjust this, but can't remember what I read. Help please!

Here is the code we have:

#include <Servo.h>

// create servo object to control a servo 
Servo servo1;  
const int servo1PotPin =A0;
const int servo1Pin = 3;
int servo1Value;

Servo servo2;  
const int servo2PotPin =A1;
const int servo2Pin = 6;
int servo2Value;

Servo servo3;  
const int servo3PotPin =A2;
const int servo3Pin = 10;
int servo3Value;
 
void setup() {
  servo1.attach (servo1Pin);
  servo2.attach (servo2Pin);
  servo3.attach (servo3Pin);
}

void loop () {
  servo1Value = analogRead(servo1PotPin);
  servo1Value = map(servo1Value, 0, 1023, 0, 180);
  servo1.write(servo1Value);

  servo2Value = analogRead(servo2PotPin);
  servo2Value = map(servo1Value, 0, 1023, 0, 180);
  servo2.write(servo2Value);

  servo3Value = analogRead(servo3PotPin);
  servo3Value = map(servo1Value, 0, 1023, 0, 180);
  servo3.write(servo3Value);

  delay(5);
}

Please show us your schematic and good images of the actual wiring.

show schematic

savvy?

You map servo1Value for all 3 servos!

All 3 use the same pot ?

fixed that back to Servo1PotPoin, Servo2PotPin, and Servo3PotPin. Think I changed that to test it. Uploaded it with the change and still nothing on the second or third controls and motors.






Put a delay, (+- 10 ms) , between each analogread() and then tell us the result.

Each ADC spends 65 to 260µs conversion time.

Time for a math lesson. What's the sum of three servos drawing default current? Compare that to the current output of the Mega. See a minor problem?

As one wag says regularly, An Arduino is not a Power Supply!

We have a 9 volt battery for power. Also, only one motor is being used at a time. We are not using all at the same time.

Ahh. Didn't see that in your schematic, sorry! Nor did I see the battery. Oh well.

Could you show me how the line of code should look? I am getting errors compiling each way i try to add this.

Try like this:

1 Like

This really helped! However, the motor just wants to vibrate back and forth. Any ideas why it is doign that? When I switch it to the first potentiometer on A0, it stops and works correctly, but on A3 it isn't working right...any ideas?

Use a 6V AA battery pack, positive 6V to the servo + pins, common GND to the Arduino GND.

This helped so much! Just have some shaking as the motors move now that we have to figure out.

Remember, powering motors from the Arduino 5V pin will damage your Arduino.