hey guys i am trying to make an autonomous car from a rc car. i am currently working on the servo for the steering control. i have it wired to an arduino uno board to ground 3.3v and pin 11. im trying to get some basic code to center it and be able to control it but whatever i do the servo seems to be reacting differently and chaotically. this is the code im using. any help would be appreciated.
#include <SoftwareServo.h>
SoftwareServo myservo; // create servo object to control a servo
int val; // variable to read the value from the analog pin
int ServoPin = 11;
void setup()
{
myservo.attach(11); // attaches the servo on pin 11 to the servo object
pinModeServoPin, OUTPUT);
}
thanks for the reply. i meant pinMode and i realized i copied the code before i edited it but i didnt get around to changing. im using software servo because a friend i was talking to recommended it and it didnt seem like i had anything to lose. why do you recommend against it?
i have it wired to an arduino uno board to ground 3.3v and pin 11.
Note that using the board 3.3v probably will NOT work. Hobby servos usially require a mimimum voltage of 4.5v and a power source capable of ~1a current.
Below is some simple servo test code you can experiment with when you get an appropriate power supply for the servo.
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 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.attach(7); //the pin for the servo control
Serial.println("servo-test-21"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(10);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n;
char carray[6]; //converting string to number
readString.toCharArray(carray, sizeof(carray));
n = atoi(carray);
myservo.writeMicroseconds(n); // for microseconds
//myservo.write(n); //for degees 0-180
readString="";
}
}