Hi, I am trying to control a servo wireless with the help of a bluetooth module. I am quite sure that my servo is not ruined because the sweep sketch does work (and also a sketch I made to make it go to 60,90,120,90 degrees). Here is my sketch:
#include <Servo.h>
Servo myservo;//name my servo
char val; //variable to store input value from bluetooth module
int bt = 2; //pin that is feeding the bluetooth module
void setup() {
// put your setup code here, to run once:
pinMode(bt,OUTPUT); //set bt pin as output...
digitalWrite(bt,HIGH); //and put it high.
Serial.begin(9600); //begin serial communication
myservo.attach(6); //attach the servo to pin 6
delay(2000); //wait for servo to reach position
myservo.write(90); //put servo in center(0_90_180) position
delay(2000); //wait for servo to reach position
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()>0) //while serial connection with bluetooth is available...
{
val = Serial.read(); //assign the serial input to val...
Serial.println(val); //and print the val to the serial monitor.
}
if(val == 'r'){ //if val is r (which means right)...
myservo.write(120); //put the servo to 120 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'l'){ //if val is 'l' (left)...
myservo.write(60); //set servo to 60 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'c');{ //if val is 'c' (center)...
myservo.write(90); // set servo to 90 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
}
[/code][code]
#include <Servo.h>
Servo myservo;//name my servo
char val; //variable to store input value from bluetooth module
int bt = 2; //pin that is feeding the bluetooth module
void setup() {
// put your setup code here, to run once:
pinMode(bt,OUTPUT); //set bt pin as output...
digitalWrite(bt,HIGH); //and put it high.
Serial.begin(9600); //begin serial communication
myservo.attach(6); //attach the servo to pin 6
delay(2000); //wait for servo to reach position
myservo.write(90); //put servo in center(0_90_180) position
delay(2000); //wait for servo to reach position
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()>0) //while serial connection with bluetooth is available...
{
val = Serial.read(); //assign the serial input to val...
Serial.println(val); //and print the val to the serial monitor.
}
if(val == 'r'){ //if val is r (which means right)...
myservo.write(120); //put the servo to 120 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'l'){ //if val is 'l' (left)...
myservo.write(60); //set servo to 60 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'c');{ //if val is 'c' (center)...
myservo.write(90); // set servo to 90 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
}
[/code][code]
#include <Servo.h>
Servo myservo;//name my servo
char val; //variable to store input value from bluetooth module
int bt = 2; //pin that is feeding the bluetooth module
void setup() {
// put your setup code here, to run once:
pinMode(bt,OUTPUT); //set bt pin as output...
digitalWrite(bt,HIGH); //and put it high.
Serial.begin(9600); //begin serial communication
myservo.attach(6); //attach the servo to pin 6
delay(2000); //wait for servo to reach position
myservo.write(90); //put servo in center(0_90_180) position
delay(2000); //wait for servo to reach position
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()>0) //while serial connection with bluetooth is available...
{
val = Serial.read(); //assign the serial input to val...
Serial.println(val); //and print the val to the serial monitor.
}
if(val == 'r'){ //if val is r (which means right)...
myservo.write(120); //put the servo to 120 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'l'){ //if val is 'l' (left)...
myservo.write(60); //set servo to 60 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
else if(val == 'c');{ //if val is 'c' (center)...
myservo.write(90); // set servo to 90 degrees.
delay(1200); //wait for servo to reach position
val='n'; //put val to 'n' to prevent this block from repeating
}
}
The "val" does get printed to serial monitor correctly. (r for right, l for left) but nothing happens with the servo.(The servo does go to 90 degrees when the arduino is turned on),
I'd greatly appreciate some help.