Hi everyone I am just learning arduino. My code is very simple, I am moving a micro servo to 10 degrees when I press button 1 and moving to 60 degress when I press button 2. The code works great for the analog servo, but if I keep the code identical and just unplug the analog and plug in the digital the digital servo just kind of hums and doesn't respond. Per my research I thought that I could address analog and digital servos the same way, but am I missing something? This is all on pin 9 and I am not debouncing the switch in software.
Guess we will never know.
Unless of course, you read the instructions and post your code.
p7aymak3r:
Per my research I thought that I could address analog and digital servos the same way
That's my understanding also but this....
the digital servo just kind of hums and doesn't respond.
.... indicates that there might be a power problem. Perhaps it has nothing to do with being a digital servo, but with it requiring more power?
Thanks guys, but I did read the instructions, I'm not sure what I did wrong in that post?
I tried it with my own code and also with this code I found online and get the same behavior, analog works fine, digital just hums and kind of stutters
#include <Servo.h>
Servo rightleft;
int right = 7;
int left = 8;
int right_state;
int left_state;
int servo_val;
void setup()
{
Serial.begin(9600);
pinMode(right, INPUT);
pinMode(left, INPUT);
rightleft.attach(6);
servo_val = rightleft.read();
}
void loop()
{
right_state = digitalRead(right);
left_state = digitalRead(left);
if(right_state == HIGH)
{
rightleft.write(servo_val - 1);
delay(14);
servo_val = rightleft.read();
Serial.println("Right HIGH");
}
if(left_state == HIGH)
{
rightleft.write(servo_val + 1);
delay(14);
servo_val = rightleft.read();
Serial.println("Left HIGH");
}
}
The power consumption thing might be it. I'm using a lipo, but this website said it might not be enough. Maybe you need more power and separate motor controller for digital servos?
Or maybe it's a bigger servo, and just draws more current- you didn't say.
Nor have you shown us your circuit. I hope you're not powering (as distinct from controlling) either of them from the Arduino....