I want to use Bluetooth to control my continuous servo motor to rotate 360° once, and I used MIT app inventor for the UI to control it.
My continuous servo motor won't stop rotating even though I tried myservo.write(90).
I was wondering if anything is wrong with my hardware, or whether the problem is in my code as I am a beginner at coding and I put different functions together that I found on the internet (I was trying to make the MIT to send letters to the Arduino code where the letter would activate a command to the servo).
Here's my code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library
Servo myservo; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
myservo.attach(9); // attach servo signal wire to pin 9
// Setup usb serial connection to computer
Serial.begin(9600);
myservo.write(90); // set servo to mid-point
// Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop() {
// Read from bluetooth and write to usb serial
if (bluetooth.available() > 0 ) { // receive number from bluetooth
int servopos = bluetooth.read(); // save the received number to servopos
Serial.println(servopos); // serial print servopos current number received from bluetooth
char c = Serial.read();
if (c == 'a') {
myservo.write(180);
delay(1000);
myservo.write(90);
}
else if (c == 'b') {
myservo.write(90);
}
}
}
Would be really great if you could help

