I am a student in a robotics class and we are making a line following robot with an arduino . We have ran into the problem that we can only get our servos to run full speed does anyone know how to slow them down I have tried several ways but could not get it ???
Post an example of your code so that we can see what you are writing to the servos and how. I assume that they are not real servos that move to an angle when commanded but servos that have been modified to run continuously. Please confirm that.
Hi, what are you using the servos for?
Usually you use a motor to drive the wheels and use a motor drive shield or driver assembly.
Tom......
A picture of your project and your code would help as UKHeliBob has asked, will help immensely.
Look at the servo sweep example that comes with the Arduino IDE.
...R
#include<Servo.h>
Servo myservo ;
Int Val;
Void setup ()
{
My servo.attach(9);
}
Void loop ()
{
Val = 90 ;
Myservo.write(Val);
}
That is one version that I've tried
once I figure this out. U guys think you could help me with code for my sensors if I post it??
HINT : Try setting val to a number less than 90. Then try setting it to a number greater than 90 but less than 181
Post your sensor code and we will try to help but please use code tags when you do
ok i tried puting it at 10 and 170 for val and it didnt change the speed of the servo any ideas??
Please post a link to the servo that you are using.
How is the servo powered ?
we are using standard parallax modified servos we are powering it throught the arduino at 5 volts.
we are using standard parallax modified servos we are powering it throught the arduino at 5 volts.
Standard and modified do not belong in the same sentence.
Servo can NOT be powered by the Arduino.
how do you recomend that we hook up the servos then and we got the servos pre modified from parallax
how do you recomend that we hook up the servos then
Plus to a separate power supply. Minus to the other power supply and the Arduino. The control pin connects the same way it is now.
do you think i cound use it the way i have it now, powering the 2 servos with the 5 volts from the arduino, because they both are working now but I cant ge the servos to change speed
here is the code i wrote to control the 2 servos with a 7 sensor infrred the code just makes the sensors light up and the servos go on full power not sure what i am missing hope you could help
#include <Servo.h>
Servo myservo;
Servo myservo2;
/-(Servo controls for Robot .. later)-/
#define MOTOR_LEFT 9 = myservo; /-(servo for Left wheel)-/
#define MOTOR_RIGHT 10 = myservo2; /-(servo for Right wheel)-/
//#define LEFT_ZERO_TRIM 0 ;
//#define RIGHT_ZERO_TRIM 2;
/-(Connections to NewWay 7-Way Robot Line Follower Sensor)-/
#define SS1_LEFT_OUT 2
#define SS2_LEFT_IN 4
#define SS3_CENTER 7
#define CLP_BUMP 8
#define SS4_RIGHT_IN 113
#define SS5_RIGHT_OUT 12 // Don't use pin 13 as an input..
#define NEAR A5 // Used as digital, probably
/-----( Declare objects )-----/
byte LeftOut;
byte LeftIn;
byte Center;
byte RightIn;
byte RightOut;
byte Bump;
int Near;
void setup() /----( SETUP: RUNS ONCE )----/
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
Serial.begin(9600);
}/--(end setup )---/
void loop()
{
getSensorData();
showSensorData();
delay(1000);
}/* --(end main loop )-- */
/-----( Declare User-written Functions )-----/
void getSensorData()
{
LeftOut = digitalRead(SS1_LEFT_OUT);
LeftIn = digitalRead(SS2_LEFT_IN);
Center = digitalRead(SS3_CENTER);
RightIn = digitalRead(SS4_RIGHT_IN);
RightOut = digitalRead(SS5_RIGHT_OUT);
Bump = digitalRead(CLP_BUMP);
Near = digitalRead(NEAR);
}
void showSensorData()
{
if (LeftOut == 1) myservo.write(150), myservo2.write(120) ; else {Serial.print("L ");} // left servo going at 150 degrees to go right
if (LeftIn == 1) myservo.write(135), myservo2.write(120); else {Serial.print("l ");} // left servo going at 135 degrees to go right
if (Center == 1) myservo.write(120), myservo2.write(120); else {Serial.print("C ");} // both servos going at 120 degerees
if (RightIn == 1) myservo2.write(135), myservo.write(120); else {Serial.print("r ");} // right servo going at 135 degrees to go left
if (RightOut == 1) myservo2.write(150), myservo.write(120); else {Serial.print("R ");} // right servo going at 150 degrees to go left
if (Bump == 1) myservo.write(90), myservo2.write(90); else {Serial.print("B ");}
if (Near == 1) myservo.write(95), myservo2.write(85); else; {Serial.print("N ");}
}
/* ( THE END ) */
do you think i cound use it the way i have it now, powering the 2 servos with the 5 volts from the arduino, because they both are working now but I cant ge the servos to change speed
No, I don't.
Typically, people use Servo::writeMicroseconds() to control the speed of a not-exactly-a-servo.
Post a link to you not-a-servos.
Code you can try with your modified servos using the serial monitor. Note: the new code box thing seems to break code up when it is pasted in, guess I need more ketchup on the sh*t sandwich.
// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a
// to decrease) and enter to change servo position
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;
void setup()
{
myservo.attach(7, 400, 2600); //servo control pin, and range if desired
Serial.begin(9600);
Serial.println("serial servo incremental test code");
Serial.println("type a character (s to increase or a to decrease)");
Serial.println("and enter to change servo position");
Serial.println("use strings like 90x or 1500x for new servo position");
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) {
if(readString.indexOf('x') >0) {
pos = readString.toInt();
}
if(readString =="a"){
(pos=pos-1); //use larger numbers for larger increments
if(pos<0) (pos=0); //prevent negative number
}
if (readString =="s"){
(pos=pos+1);
}
if(pos >= 400) //determine servo write method
{
Serial.println(pos);
myservo.writeMicroseconds(pos);
}
else
{
Serial.println(pos);
myservo.write(pos);
}
}
readString=""; //empty for next input
}