Hi, I want to control a motor speedcontroller and a servo (I use 2 servo's for testing), for controlling them I use 2 potentiometers so I can control them separately. But when I'm testing it, the servo's goes crazy. But when I disconnect 1 it works. I think that the potentiometers are interfering. I have here my code:
How are you powering the servo and motor? If you are powering the servo from the Arduino that is a problem! It can cause the Arduino to reset and may even damage it. You must directly connect the servo to a power supply that can provide enough current.
I'm using a micro servo, those little cheap ones. And they are powered via the Arduino.
And this code works. But this is only 1 servo and 1 potentiometer.
#include <Servo.h>
Servo myservo;
int potpin = A0;
int val;
void setup() {
myservo.attach(6);
Serial.begin(9600);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 255);
Serial.println(val);
myservo.write(val);
delay(5);
}
Yes. If you add the other one it goes crazy right? Put a serial print in your setup() function. You may see that when 2 are connected it resets. It is likely 2 servos are pulling too much current causing the voltage to drop.
I have tried multiple names but none of them work.
I also tried a power supply but still they are going crazy. When I look at the serial plotter I get spikes from zero to the point where one of the pots are sitting on.