0
votes

I am making a car that is to be controlled by Android app through bluetooth. The problem that I am facing with servo motors is that before bluetooth module hc-05 gets connected to any bluetooth device, the servo motors rotate irrespective of whether it is connected or not.
Here's my arduino code for servo motors:

#include<Servo.h>
Servo servo1;
Servo servo2;
char val;
void setup()
{
  Serial.begin(9600);
  servo1.attach(5);
  servo2.attach(9);
}

void loop()
{
  if(Serial.available())
  {
    switch(Serial.read())
    {
      case 'F':
        servo1.write(180);
        servo2.write(180);
      break;
      case 'B':
        servo1.write(90);
        servo2.write(90);
      break;
    }
  }
}

I don't know why it' rotating. It's very frustating. Plz help. By the way the servo motors that I bought rotates only 180 degree.But I made it 360 degree by removing some part from inside. Plz help and correct me if my code is wrong.

1
Your code looks fine (tested here with one servo). Your modification to the motor is probably the issue. I think you want a continuous rotation servo. But I'm not an engineer. You might get a better answer at Arduino. - Johnny Mopp
Thank you very much Johnny Mopp for your advice. I'll try to test it with continuous rotation servo - Irfan Ansari

1 Answers

0
votes

Try to add here:

switch(Serial.read())
- '0'`

Like here:

switch(Serial.read() - '0')