For some-reason the servo library wont work for me. I don't know why but when i try to include the servo library the Servo.h portion doesnt light up and it doesnt work. So i decided to send a manual pulse as an alternate method that may work. Well it did work but when tried to manage the length in time that the servo rotated(it its a continious rotation servo) the servo would just continue running. Anyway is my code...HELP??
I don't know why but when i try to include the servo library the Servo.h portion doesnt light up and it doesnt work.
That really doesn't make any sense. Some servo test code that might be of use.
// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include <Servo.h>
String readString; //String captured from serial port
Servo myservo; // create servo object to control a servo
int n; //value to write to 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 all-in-one test code 12-25-13"); // so I can keep track of what is loaded
Serial.println();
}
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
// attach or detach servo if desired
if (readString == "d") {
myservo.detach(); //detach servo
Serial.println("servo detached");
goto bailout; //jump over writing to servo
}
if (readString == "a") {
myservo.attach(7); //reattach servo to pin 7
Serial.println("servo attached");
goto bailout;
}
n = readString.toInt(); //convert readString into a number
// auto select appropriate value
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
bailout: //reenter code loop
Serial.print("Last servo command position: ");
Serial.println(myservo.read());
Serial.println();
readString=""; //empty for next input
}
}
About the <Servo.h> thing.. I saw on instructional videos that the <Servo.h> portion lit up orange. Well in may case this did not occur. Only the Servo portion did and the .h portion remained black as if it was not recognized for some-reason. Its really annoying because the Servo Library is a quick alternative to having to control servos with a manual pulse like I did in my example code. I know that the arduino/USB cant power the servo with .5 volt but I have 4 AAA batteries running the servo which worked when the servo was running 1700 clockwise. I don't know how to control the servos length of Rotation time and its annoying because that blocks a-lot of cool projects.
Everytime I try to use the servo library it doesn't work I thought maybe that was because the IDE wasn't reconizeing the servo library and I thought that a hint of that was the lack of being lit up. But as I said before the servo will turn constantly and wont stop even when I include a for loop into the manual servo pulse.
Have you tried scanning from, say, 1200 microseconds to 1700 microseconds? The servo should start going one way, slow down, stop, and speed up going the other way.
void loop() {
for (int s=1200; s<1700; s += 10) {
digitalWrite(3, HIGH);
delayMicroseconds(s);
digitalWrite(3, LOW);
delay(20);
}
}
qwertyboi:
Everytime I try to use the servo library it doesn't work
That sentence conveys no useful information.
Does the program compile and upload to the Arduino?
Are you sure it uploaded? How do you know?
If it did compile and upload what happens when it runs?
Post a copy of the code you uploaded.
How is the servo connected to the Arduino?
Does the servo have its own separate power supply? (it should)
Is the servo GND connected to the Arduino GND.