I need my 1st servo to go 0 to 190 and come back to 0 then the second servo to go the same 0 to 190 and come back and the third also the same.
3 servos should work one after the other
I need my 1st servo to go 0 to 190 and come back to 0 then the second servo to go the same 0 to 190 and come back and the third also the same.
3 servos should work one after the other
Have you got one servo to move?
Post your code and explain what it supposed to do and what it does instead.
Or do you just want someone to write code for you?
one of my servo is working continuously without stopping
// C++ code
#include <Servo.h>
int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9, 500, 2500);
}
void loop()
{
// sweep the servo from 0 to 180 degrees in steps
// of 1 degrees
for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
for (pos = 180; pos >= 0; pos -= 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
}
That's what the code that you posted in post#3 is supposed to do.
// C++ code
#include <Servo.h>
int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9, 500, 2500);
servo_9.write(0);
delay(60);
}
void loop()
{
servo_9.write(180);
delay(60);
}
that should drive the servo to one end, stop and go to the other end and stop.
the servo is stopping in the first turn
If you want the servo to do more you. Yes YOU, have to write code to make it do more. Or you could pay someone to write code for you.
thank you for your reply greatly appreciated
#include <Servo.h>
Servo servo [ 3 ];
void setup ()
{
for ( byte n = 0; n < 3; n ++ )
{
servo [ n ].attach ( 4 + n, 500, 2500 );
servo [ n ]. write ( 0 );
}
delay ( 1000 );
}
void loop ()
{
for ( byte n = 0; n < 3; n ++ )
{
for ( byte pos = 0; pos < 180; pos ++ )
{
servo [ n ]. write ( pos );
delay ( 20 );
}
for ( byte pos = 0; pos < 180; pos ++ )
{
servo [ n ]. write ( 180 - pos );
delay ( 20 );
}
}
}
Your code doesn't include 3 servos. It only includes one servo. In order to have 3 servos, you have to define 3 servos and what pins they will connect to.
#include <Servo.h>
int pos = 0;
Servo servo_1, servo_2, servo_3;
void setup()
{
servo_1.attach(9);
servo_2.attach(10);
servo_3.attach(11);
}
Then you can control 3 separate servos.
Also, you do not need a for loop to iterate the angle. Simply set the angle and move onto the next servo. But 190 isn't a valid angle for a 180 degree servo. So, are your servos 270 degree servos? Or continuous rotational servos?
270-degree servos
how do I stop the loop of the code?
I need this to work at once
Think a little. I have given you a ready working program and you just need to modify it according to your new condition. Hint - just editing with Cut and Paste is enough.
I have finished my code and it is working properly thank you for your help
greatly appreciated
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.