user86511: My robot car won’t respond to my command. The code below worked before however, this time there is no response. I’ve tried experimenting with the code in the first while loop. I’ve tried different code from other projects similar to this. I’ve played with the schematics however, nothing seems to work.
This is my code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library 
Servo myservo1, myservo2, myservo3; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
int motorOne = 4;
int motorOne2 = 5;
int motorTwo = 6;
int motorTwo2 = 7;
int enA = 3;
int enB = 2;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);


//initial motors pin

char command; 
char Value;

void setup()
{
  myservo1.attach(2); // attach servo signal wire to pin 9
  myservo2.attach(8);
  myservo3.attach(12);
   
  //Setup usb serial connection to computer
  Serial.begin(9600);
  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}
void loop()
{
  while (bluetooth.available() > 2) {
    Value = bluetooth.read();
    Serial.println(Value);
  }

  if ( Value == 'F') {
    // Robo Pet Run Forward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'B') {
    //Robo Pet Run Backward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, HIGH);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, HIGH);
  } else if (Value == 'L') {
    //Robo Pet Turn Left
    digitalWrite(enA, 255);
    
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'R') {
    //Robo Pet Turn Right
    
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'S') {
    //Robo Pet Stop
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  }

  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);
    if (realservo >= 1000 && realservo <1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println("Servo 1 ON");
      delay(10);
    }
    if (realservo >= 2000 && realservo <2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println("Servo 2 ON");
      delay(10);
    }
    if (realservo >= 3000 && realservo <3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println("Servo 3 ON");
      delay(10);
    }
    
  }
}

I’m using this app:
https://play.google.com/store/apps/details?id=com.giumig.apps.bluetoothserialmonitor&hl=en&gl=US
And here are the schematics:


user70020: In short, among whatever other problems you might have, you've wired your TX and RX connections backwards according to your diagram and code.
Swap them either in hardware or in software.

According to the documentation:
SoftwareSerial var_name(rxPin, txPin)





SS Operation




RX


TX




You've constructed your SoftwareSerial object as:
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);





SS Operation
Pin Variable




RX
bluetoothTx


TX
bluetoothRx




Defined your pin variables to these pins:
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin





SS Operation
Pin Variable
Arduino Pin




RX
bluetoothTx
10


TX
bluetoothRx
11




Connected them as:





SS Operation
Pin Variable
Arduino Pin
BT Operation




RX
bluetoothTx
10
RX


TX
bluetoothRx
11
TX




So, you have them backwards. Connecting their RX (inputs) which is is harmless but not helpful and connecting their TX (outputs) which may damage something.
In case this isn't clear, the RX and TX on the HC-05 are labeled from its perspective and not from the perspective of the Arduino. Except for some things like an old external modem, RX and TX on device are nearly always labeled from that device's perspective.

A variable name like bluetoothTx can be confusing if you're not sure which thing is doing the transmitting. Is this the pin number for transmitting to Bluetooth or the pin that will be connected to the Bluetooth transmitter (in other words, for receiving)?
In some cases I just describe the situation in the variable name:
static const int PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX = 11;
static const int PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX = 10;
/// ...
SoftwareSerial bluetooth(
  PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX,
  PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX
);

I dunno that I'd go with a name quite that long, but you get the idea.
I'm swapping them in software here, leaving your physical connections as they were in the diagram mostly because I don't feel like redrawing your diagram. Though, if it were my project I would swap the wires (and defined pin numbers above), because the convention is to have SoftwareSerial receive on 10 just like hardware receives on pin 0 and to have SoftwareSerial transmit on 11 just like hardware transmits on pin 1; in order words, keeping the relative order of the pin numbers.
So this is what you have with the above code:




SS Operation
Pin Variable
Arduino Pin
BT Operation




RX
PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX
11
TX


TX
PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX
10
RX




Transmitters connected to receivers.
If you get confused build your own table and make sure your variable names make sense.
This has nothing to do with our question really, but: Most Arduino users, new ones anyway, are better off with an Arduino that has connectivity that displaces the need for SoftwareSerial. A minimal change from the Nano for what you're doing is a Micro or Pro Micro board. That board has native USB support which it uses to send "Serial" to the computer. That leaves the one actual hardware serial peripheral on the (Pro) Micro available for you to to connect to HC-05 (or whatever). There are a pile of options, including ones that just do Bluetooth also (without need of HC-05). Anyway, there are lots of ways to not use SoftwareSerial.

86511: <p>My robot car won’t respond to my command. The code below worked before however, this time there is no response. I’ve tried experimenting with the code in the first while loop. I’ve tried different code from other projects similar to this. I’ve played with the schematics however, nothing seems to work.</p>
<p>This is my code:</p>
<pre><code>#include &lt;SoftwareSerial.h&gt; // TX RX software library for bluetooth
#include &lt;Servo.h&gt; // servo library 
Servo myservo1, myservo2, myservo3; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
int motorOne = 4;
int motorOne2 = 5;
int motorTwo = 6;
int motorTwo2 = 7;
int enA = 3;
int enB = 2;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);


//initial motors pin

char command; 
char Value;

void setup()
{
  myservo1.attach(2); // attach servo signal wire to pin 9
  myservo2.attach(8);
  myservo3.attach(12);
   
  //Setup usb serial connection to computer
  Serial.begin(9600);
  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}
void loop()
{
  while (bluetooth.available() &gt; 2) {
    Value = bluetooth.read();
    Serial.println(Value);
  }

  if ( Value == 'F') {
    // Robo Pet Run Forward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'B') {
    //Robo Pet Run Backward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, HIGH);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, HIGH);
  } else if (Value == 'L') {
    //Robo Pet Turn Left
    digitalWrite(enA, 255);
    
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'R') {
    //Robo Pet Turn Right
    
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'S') {
    //Robo Pet Stop
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  }

  //Read from bluetooth and write to usb serial
  if(bluetooth.available()&gt;= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);
    if (realservo &gt;= 1000 &amp;&amp; realservo &lt;1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println(&quot;Servo 1 ON&quot;);
      delay(10);
    }
    if (realservo &gt;= 2000 &amp;&amp; realservo &lt;2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println(&quot;Servo 2 ON&quot;);
      delay(10);
    }
    if (realservo &gt;= 3000 &amp;&amp; realservo &lt;3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println(&quot;Servo 3 ON&quot;);
      delay(10);
    }
    
  }
}
</code></pre>
<p>I’m using this app:
<a href="https://play.google.com/store/apps/details?id=com.giumig.apps.bluetoothserialmonitor&amp;hl=en&amp;gl=US" rel="nofollow noreferrer">https://play.google.com/store/apps/details?id=com.giumig.apps.bluetoothserialmonitor&amp;hl=en&amp;gl=US</a></p>
<p>And here are the schematics:
<a href="https://i.stack.imgur.com/IToLw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IToLw.png" alt="schematic" /></a></p>
 70020: <p>In short, among whatever other problems you might have, <strong>you've wired your TX and RX connections backwards according to your diagram and code.
Swap them either in hardware or in software.</strong></p>
<hr />
<p>According to the <a href="https://docs.arduino.cc/learn/built-in-libraries/software-serial#softwareserial" rel="nofollow noreferrer">documentation</a>:</p>
<pre class="lang-cpp prettyprint-override"><code>SoftwareSerial var_name(rxPin, txPin)
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SS Operation</th>
</tr>
</thead>
<tbody>
<tr>
<td>RX</td>
</tr>
<tr>
<td>TX</td>
</tr>
</tbody>
</table>
</div>
<p>You've constructed your <code>SoftwareSerial</code> object as:</p>
<pre class="lang-cpp prettyprint-override"><code>SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SS Operation</th>
<th>Pin Variable</th>
</tr>
</thead>
<tbody>
<tr>
<td>RX</td>
<td><code>bluetoothTx</code></td>
</tr>
<tr>
<td>TX</td>
<td><code>bluetoothRx</code></td>
</tr>
</tbody>
</table>
</div>
<p>Defined your pin variables to these pins:</p>
<pre class="lang-cpp prettyprint-override"><code>int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SS Operation</th>
<th>Pin Variable</th>
<th>Arduino Pin</th>
</tr>
</thead>
<tbody>
<tr>
<td>RX</td>
<td><code>bluetoothTx</code></td>
<td>10</td>
</tr>
<tr>
<td>TX</td>
<td><code>bluetoothRx</code></td>
<td>11</td>
</tr>
</tbody>
</table>
</div>
<p>Connected them as:</p>
<p><a href="https://i.stack.imgur.com/speYU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/speYU.png" alt="Serial connections" /></a></p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SS Operation</th>
<th>Pin Variable</th>
<th>Arduino Pin</th>
<th>BT Operation</th>
</tr>
</thead>
<tbody>
<tr>
<td>RX</td>
<td><code>bluetoothTx</code></td>
<td>10</td>
<td>RX</td>
</tr>
<tr>
<td>TX</td>
<td><code>bluetoothRx</code></td>
<td>11</td>
<td>TX</td>
</tr>
</tbody>
</table>
</div>
<p><strong>So, you have them backwards. Connecting their RX (inputs) which is is harmless but not helpful and connecting their TX (outputs) which <em>may</em> damage something.</strong></p>
<p>In case this isn't clear, the RX and TX on the HC-05 are labeled from its perspective and not from the perspective of the Arduino. Except for some things like an old external modem, RX and TX on device are nearly always labeled from that device's perspective.</p>
<hr />
<p>A variable name like <code>bluetoothTx</code> can be confusing if you're not sure which thing is doing the transmitting. Is this the pin number <em>for transmitting</em> to Bluetooth or the pin that will be connected to the Bluetooth transmitter (in other words, <em>for receiving</em>)?</p>
<p>In some cases I just describe the situation in the variable name:</p>
<pre class="lang-cpp prettyprint-override"><code>static const int PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX = 11;
static const int PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX = 10;
/// ...
SoftwareSerial bluetooth(
  PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX,
  PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX
);
</code></pre>
<p>I dunno that I'd go with a name <em>quite</em> that long, but you get the idea.</p>
<p>I'm swapping them in software here, leaving your physical connections as they were in the diagram mostly because I don't feel like redrawing your diagram. Though, if it were my project I would swap the wires (and defined pin numbers above), because the convention is to have SoftwareSerial receive on 10 just like hardware receives on pin 0 and to have SoftwareSerial transmit on 11 just like hardware transmits on pin 1; in order words, keeping the relative order of the pin numbers.</p>
<p>So this is what you have with the above code:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SS Operation</th>
<th>Pin Variable</th>
<th>Arduino Pin</th>
<th>BT Operation</th>
</tr>
</thead>
<tbody>
<tr>
<td>RX</td>
<td><code>PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX</code></td>
<td>11</td>
<td>TX</td>
</tr>
<tr>
<td>TX</td>
<td><code>PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX</code></td>
<td>10</td>
<td>RX</td>
</tr>
</tbody>
</table>
</div>
<p>Transmitters connected to receivers.
If you get confused build your own table and make sure your variable names make sense.</p>
<p>This has nothing to do with our question really, but: Most Arduino users, new ones anyway, are better off with an Arduino that has connectivity that displaces the need for SoftwareSerial. A minimal change from the Nano for what you're doing is a Micro or Pro Micro board. That board has native USB support which it uses to send &quot;Serial&quot; to the computer. That leaves the one actual hardware serial peripheral on the (Pro) Micro available for you to to connect to HC-05 (or whatever). There are a pile of options, including ones that just do Bluetooth also (without need of HC-05). Anyway, there are lots of ways to not use SoftwareSerial.</p>
