0

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);
}

} }

Here's how i set my arduino board

And the MIT App inventor code

Would be really great if you could help

ocrdu
  • 1,795
  • 3
  • 12
  • 24
grace728
  • 9
  • 2

1 Answers1

3

A "continuous servo" is one in which it stops rotating when the angle is set to 90 degrees, rotates forward when the angle is more than 90 degrees and rotates in reverse when the angle is less than 90 degrees. The further from the angle of 90 degrees, the faster the continuous servo will rotate.

You can not control the angle of a continuous servo. There is no feed back to know when it has rotated, say, 360 degrees.

You can only guess at the timing and send a command like "go to angle 100" to start rotating a continuous servo slowly forward then send a command like "go to to angle 90" to stop it after your "guessed at" time of how log it took to travel, say, a quarter the way around has elapsed.

Here is a similar Stack Exchange question where continuous servos are discussed as well.

st2000
  • 7,513
  • 2
  • 13
  • 19