OK Guys Check this out i need ya really help maybe it was allready discussed but i dont know what to do:
Ive got a Project where i Controll a Servomotor directly connected to a µC.
At first i used the ATmega2560 with an XbeeShield and a bluetooth module. I wrote the Code Connected everything and tested it, it worked. The Servo is moving to the Positions i decide.
Now im putting the same Code on an Leonardo with a bluetooth module. The Servo cant reach any of my positons!!
I dont know what to do i tried on the Leonardo following pins 9,11,3;
#include <Servo.h>
#define step_1 10
#define step_2 20
#define step_3 30
#define step_4 40
#define step_5 50
#define step_6 60
#define step_7 70
#define step_8 80
#define step_9 90
Servo myservo; //create servo object
int pos = 90;
int pos_A = 165;
int pos_E = 0;
double scale = 0;
int menu_pos = 0;
char input;
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
myservo.attach(3); // attaches the servo on pin 9 to the servo object
myservo.write(pos); //moving servo to init pos (90)
delay(10); //time to move for servo 10 ms
scale = (165 - 0)/100;
myservo.write(pos_A); //moving servo to init pos (90)
delay(100); //time to move for servo 10 ms
}
void loop(){
if (Serial.available()){
input = Serial.read();
switch (input){
case 'A': //Go to pos_A
myservo.write(pos_A); //moving servo to init pos (90)
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case 'E': //Go to pos_E
myservo.write(pos_E); //moving servo to init pos (90)
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '9':
menu_pos = (scale * step_1); //Opening 10%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '8':
menu_pos = (scale * step_2); //Opening 20%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '7':
menu_pos = (scale *step_3); //Opening 30%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '6':
menu_pos = (scale *step_4); //Opening 40%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '5':
menu_pos = (scale *step_5); //Opening 50%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '4':
menu_pos = (scale *step_6); //Opening 60%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '3':
menu_pos = (scale *step_7); //Opening 70%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '2':
menu_pos = (scale *step_8); //Opening 80%
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
case '1':
menu_pos = (scale *step_9); //Opening 90%
Serial.println(menu_pos,DEC);
myservo.write(menu_pos); //moving servo to menupos
delay(50); //time to move for servo 10 ms
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
break;
}
}
Yes i see the LED and, the Code is working on the leonardo too, BUT it seems like the Servo is getting to low current or a wrong PWM signal because hes doing wrong positioning