1

There are two problems to control digital servo(HD-1810MG) and HC-06 bluetooth module connection.

  1. When I put a specific number to servo(in the video, I put 45), it shakes too much and shows useless movements before get to the right angle. I have no clue why this happens. Should I add more code to control it correctly?

This is my code.

#include SoftwareSerial.h
#include Servo.h

Servo myServo;
int TxD = 10;
int RxD = 11;
SoftwareSerial bluetooth(TxD, RxD);

void setup() {
  myServo.attach(9);
  Serial.begin(9600);       // start serial communication at 9600bps
  bluetooth.begin(9600);
}

void loop() {
  if (bluetooth.available()>0)
  {
    int servopos = bluetooth.read();
    Serial.println(servopos);
    myServo.write(servopos);
    delay(100);
  }
}
  1. I used Nexus 5X and apk app to pair with HC-06. It pairs well at the first time of connection, but it loose connection after servo moved once. Application said it is connected with bluetooth, but HC-06's LED is blinking(which means disconnected). How can I maintain connection with HC-06?

This is my board. arduino board image

And I made apk app using MIT App Inventor 2.

I'm so new to arduino and I'm not in major of engineering. Please give me an advice!

  • The Servo you are using, its a standard servo or continuous servo? – ARK Apr 19 '16 at 17:29
  • Definitely not enough power for the servo. Insufficient power causes the BT module to reset, and can also be a good reason for unexpected servo movements. Power the servo from a separate set of batteries (keep the GND of the battery connected to the GND of Arduino). – Gee Bee Apr 19 '16 at 18:10
  • @ARK: I think it might be a standard servo. There is no item description about continuous property. – monobear Apr 21 '16 at 2:27
  • @Gee Bee: Yes, the power source was coming from USB on PC, so as you referred the power problem might have occurred. I bought alternative power source(case for 4 AA batteries, 5V, 1A) for test. I would try again using it. Thank you! – monobear Apr 21 '16 at 2:28
1
  1. let have a look at following line of code:

    int servopos = bluetooth.read();
    

    I think that you are thinking that if you type in 1 in your Bluetooth application. bluetooth.read() will pass that 1 to sevopos. But, that's what not happens. What actually happens is that it will pass the ASCII value of whatever you type in you app, to integer. So, if you have typed in 1, it will pass 49 to servopos.

    I put 45

    Now, think about it. when you type in 4 of this 45,

    bluetooth.available()>0
    

    becomes true.

    int servopos = bluetooth.read();
    

    bluetooth.read() will pass 52 (ASCII of 4) to servopos. Next,

    myServo.write(servopos);
    

    myservo will move your servo to lets say 52 degrees. and then there will be a delay.

    Now, when you type in 5 of this 45, the procedure will be repeated and your servo will be moved again by 53 degrees.

    Now, you might be wondering that why 4 and 5 sepratly? Well, all these intructution are being executed in MHzs. and secondly, you, yourself has programmed that if loop you read just once character. Yes, it will read character by character.

  2. but it loose connection after servo moved once

    I think your servo is drawing too much current from Arduino Board which results in a drop in net voltage. And hence your HC-05 (kind of) tuns off. This is what happens most of the time.

-1

It is not a problem in serial connection. I have experienced this problem when I was trying to make a biped robot using 12 servos. It is the programming bug where Arduino does not use its timers properly. You can say that it is arduino limitation. There are two main solutions : 1). Use Raspberry Pi instead of arduino. 2). Secondly you can make a small servo controlling shield of TLC5940 IC + servo controlling library... Here is he Link: http://bildr.org/2012/03/servos-tlc5940-arduino/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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