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

2
  • 1
    I'm not familiar with the Servo class, but what is its default state? What happens if none of your code in loop() is there? Does the servo still rotate? Is there a command that you need to send to tell the servo not to rotate? If there is then should you be sending this command when the bluetooth is not available, or when c is not a or b? (Hope that makes sense) Commented Jan 4, 2022 at 10:48
  • 1
    do a sweep through all values ... hopefully the servo will stop for some
    – jsotola
    Commented Jan 4, 2022 at 15:50

1 Answer 1

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.

5
  • Doesn't the angle in the Servo library goes from 0 to 180, so that the stopping value for a continuous rotation servo would be 90, just like the OP did? The main problem seems to be that the Servo doesn't stop, even at the start of the program.
    – chrisl
    Commented Jan 4, 2022 at 14:22
  • The angle sent to a normal servo controls the position. But the angle set to a CONTINUOUS servo speed and direction. For example, you would use a normal servo to control the steering of a sumo bot. And you would use CONTINUOUS servos to propel a sumo bot.
    – st2000
    Commented Jan 4, 2022 at 14:31
  • That wasn't my point. The OP wrote that the servo doesn't stop rotating, but with using Servo.write(90) it should, since that is normally the value for a speed of zero for cont. rotation servos. In your answer it sounds as if doing Servo.write(0) will stop the servo.
    – chrisl
    Commented Jan 4, 2022 at 15:09
  • Ohh, I see what you are saying @chrisl. From what I remember, writing a 0 stopped my continuous servos. Maybe I'm not remembering correctly. If writing 90 stops a continuous servo, then writing, say 45 would make them go backwards and writing, say 135 would make them go forwards. Let me know if that is correct and I'll change my answer. Thanks!
    – st2000
    Commented Jan 4, 2022 at 17:27
  • Ah! Found another Stack Exchange question which agrees w/what you said. I'll change my answer and refer to the other answer as well.
    – st2000
    Commented Jan 4, 2022 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.