Dear: Element 14
You should know I am trying to drive two servos and one ir sensor with arduino uno. The ir sensor will be used to make my steampunk robot RC while the servos will drive the robot. Also you should know that one servo moves the other one doesn't. The servo connected to pin 12 will not move which is the left servo. I know this servo works because I have tested it several times. Also I think it is a problem of PWM because power and ground pins are clearly working. Can arduino uno drive two servos or not because it says nothing in the datasheet.
From: Noah
#include <Servo.h>
Servo myServoLeft;
Servo myServoRight;
int IRpin = A0;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(9, OUTPUT);
Move(360,360);
}
void loop()
{
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
boolean Signal = digitalRead(IRpin);
Serial.println(Signal);
}
void Move(int LeftDirection, int RightDirection)
{
if (!myServoLeft.attached())
{
myServoLeft.attach(12);
}
myServoLeft.write(LeftDirection);
if (!myServoRight.attached())
{
myServoRight.attach(13);
}
myServoRight.write(RightDirection);
}
void Stop(boolean DetachLeft, boolean DetachRight)
{
if (DetachLeft == true && myServoLeft.attached())
{
myServoLeft.detach();
}
if (DetachRight == true && myServoRight.attached())
{
myServoLeft.detach();
}
}