Right now i got two servos,servo A and servo B. I want servo B to run after servo A ends. This is the code i have right now. So the servos will run in a loop. I've tested it but servo B does not run after servo A. Is there anything i missed out?
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards
int pos = 10; // variable to store the servo position
int pos1 = 10;
void setup() {
//myservo.attach(9); // attaches the servo on pin 9 to the servo object
//myservo2.attach(10);
}
void loop()
{
//myservo2.detach();
//delay(100);
myservo.attach(9);
delay(100);
for (pos = 10; pos <= 170; pos += 1)
{ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
for (pos = 170; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
myservo.detach();
delay(100);
myservo2.attach(10);
delay(100);
for (pos1 = 5; pos1 <= 175; pos1 += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
for (pos1 = 175; pos1 >= 5; pos1 -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
myservo2.detach();
delay(1000);
}
The board used is an arduino nano. The gnd of nano is connected to the gnd of the servos. The reason for running a servo one at a time is due to power consumption. I am making a dual axis solar tracker project. However I want it to reduce the total power consumption at a time, hence I want to divide the power consumption into two parts. For additional info, there is a forum chat i had going on(do forgive me if this is a duplicate question) but for time sake, the specs of my system,
10W solar panel , 17.5V (able to give 1.1A max , tested outdoor by myself with a buck converter)
5V buck
Arduino nano and two 946R servos
As you can see from the output available, only a mere 1A-ish. You can proceed to my other chat question for more info and ask for additional information there. Thanks! and stay safe!
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards
int pos = 10; // variable to store the servo position
int pos1 = 10;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}
void loop()
{
delay(100);
for (pos = 10; pos <= 170; pos += 1)
{ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
for (pos = 170; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
delay(100);
for (pos1 = 5; pos1 <= 175; pos1 += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
for (pos1 = 175; pos1 >= 5; pos1 -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
delay(1000);
}
Not sure if this the most efficient way to do it , but it does the job!
#include <Servo.h>
Servo myservo;
Servo myservo2;// create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() { //myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void movemotorA()
{
myservo.attach(9);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
void movemotorB()
{
myservo2.attach(10);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
void loop()
{
movemotorA();
delay(2000);
movemotorB();
exit(0); //exit loop after 1 iteration. You can remove if need to run infinite loops
}
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2;
// twelve servo objects can be created on most boards
int pos = 10; // variable to store the servo position
int pos1 = 10;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}
void loop()
{
delay(500);
for (pos = 10; pos <= 170; pos += 1)
{ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(75); // waits 15ms for the servo to reach the position
}
for (pos = 170; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(75); // waits 15ms for the servo to reach the position
}
delay(1000);
for (pos1 = 5; pos1 <= 175; pos1 += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(75); // waits 15ms for the servo to reach the position
}
for (pos1 = 175; pos1 >= 5; pos1 -= 1) { // goes from 180 degrees to 0 degrees
myservo2.write(pos1); // tell servo to go to position in variable 'pos'
delay(75); // waits 15ms for the servo to reach the position
}
delay(1000);
}
Things happen a bit slower in this one.
Can you please post a picture of your project, so we can see your component layout?
There is no reason you can't track sun by sequentially moving the steppers.
Azimuth changes at 15 degrees per hour so that one will move all day every few minutes, Elevation is only a once a day move if that. Move the Azimuth stepper first then the Elevation (if needed). no need to divide power anywhere,