Hi,
I was doing project 5 from the arduino starter kit and once everything was set up and the code was written and uploaded, the servo motor would twitch, but the arm would not move.
Here is my code:
#include<Servo.h>
Servo myServo;
int const potPin=A0;
int potVal;
int angle;
void setup() {
// put your setup code here, to run once:
myServo.attach(9);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
potVal=analogRead(potPin);
Serial.print("potVal: ");
Serial.print(potVal);
angle=map(potVal,0,1023,0,179);
Serial.print(",angle: ");
Serial.println(angle);
myServo.write(angle);
delay(30);
}
How do I get the motor to move to the appropriate angle?
//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
Serial.println("servo-test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
Serial.println(n); //so you can see the integer
myservo.write(n);
readString="";
}
}