Hi there,
I'm lost
I want to make an animation with a Uno / Adafruit MotorShield / 2 servo's / 1 stepper (4 wires)
with USB power on the Uno and a 9v external power supply at the Uno
First I'm explaining what I want to reach.
-First servo1 must go turn from 0 to 90, back to 0.
-Then the stepper must turn a few turns forwards
-Then Servo 2 must turn 90 to 0 left and 0 to 90 right turn
-Then the stepper again a few turns backwards
-Then servo1 must go turn from 0 to 90, back to 0 again.
After a lot of days testing, this code was working on a low voltage stepper, now I exchanged it with a 9 volt Lego stepper motor that's looks like to work but the stepper takes a run at the end.
Can you people check my code please or have a idea what is going wrong?
I like to hear from you.
Code:
#include <Servo.h>
Servo myservo1; // licht aan,licht uit
Servo myservo2; // hand zwaait
int pos = 0;
#include <AFMotor.h>
AF_Stepper motor(50, 2); // zwaai arm omhoog en omlaag
const int LED = 3;
void setup(){
Serial.println("Licht aan");
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Zwaai arm beweegt omhoog");
motor.setSpeed(10); // 10 rpm
motor.step(10, FORWARD,SINGLE);
delay(50);
Serial.println("Hand zwaait");
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
{
}
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
} myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
} myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
} myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
} myservo2.attach(10); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; 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(5); // waits 15ms for the servo to reach the position
}
for(pos = 190; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Zwaai arm beweegt omlaag");
motor.setSpeed(10); // 10 rpm
motor.step(10, BACKWARD, SINGLE);
delay(50);
}{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
void loop()
{
}