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

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


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.

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!

user19513: 
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.

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.


20320: <p>There are two problems to control digital servo(HD-1810MG) and HC-06 bluetooth module connection.</p>

<ol>
<li>When I put a specific number to servo(in the <a href="https://youtu.be/L5o_dVs9VUc" rel="nofollow noreferrer">video</a>, 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?<br></li>
</ol>

<p>This is my code.</p>

<pre><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()&gt;0)
  {
    int servopos = bluetooth.read();
    Serial.println(servopos);
    myServo.write(servopos);
    delay(100);
  }
}
</code></pre>

<ol start="2">
<li>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?</li>
</ol>

<p>This is my board.
<a href="https://i.stack.imgur.com/T2Wt4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T2Wt4.png" alt="arduino board image"></a></p>

<p>And I made apk app using MIT App Inventor 2.</p>

<p>I'm so new to arduino and I'm not in major of engineering. Please give me an advice!</p>
 19513: <ol>
<li><p>let have a look at following line of code:</p>

<pre><code>int servopos = bluetooth.read();
</code></pre>

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

<blockquote>
  <p>I put 45</p>
</blockquote>

<p>Now, think about it. when you type in <strong>4</strong> of this <strong>45</strong>,</p>

<pre><code>bluetooth.available()&gt;0
</code></pre>

<p>becomes <strong>true</strong>. </p>

<pre><code>int servopos = bluetooth.read();
</code></pre>

<p><strong>bluetooth.read()</strong> will pass <strong>52</strong> (ASCII of <strong>4</strong>) to <strong>servopos</strong>. Next,</p>

<pre><code>myServo.write(servopos);
</code></pre>

<p><strong>myservo</strong> will move your servo to lets say <strong>52</strong> degrees. and then there will be a <strong>delay</strong>.</p>

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

<p>Now, you might be wondering that why <strong>4</strong> and <strong>5</strong> sepratly? Well,
all these intructution are being executed in <strong>MHz</strong>s. and secondly,
you, yourself has programmed that <strong>if</strong> loop you read just <strong>once
character</strong>. Yes, it will read <strong>character by character</strong>.</p></li>
<li><blockquote>
  <p>but it loose connection after servo moved once</p>
</blockquote>

<p>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.</p></li>
</ol>
