I'm making a project involving a servo motor. I know what a servo motor is and how it works. I just cannot understand how to program it to rotate to a specific location. I have watched video tutorials on this but they don't quite seem to help.
My project is basically a movie theater in which the servo motor will move at the start of the movie, the same number of degrees the movie elapses in seconds. I am using a standard servo motor that comes with the Arduino starter kit.
P.S. Please explain it in a simple and concise language because I am actually a 10 year old kid(I know it sounds surprising, but it's true).
P.S.S Any suggestions for displaying the movie (using a 16 by 2 LCD display) would be very much appreciated!
I just cannot understand how to program it to rotate to a specific location.
Servo test code you can experiment with.
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// 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.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7, 500, 2500); //the pin for the servo control, and range if desired
Serial.println("servo-test-22-dual-input"); // 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
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
readString=""; //empty for next input
}
}