Our first project: A car of our own (Part 3 Manual Control)

One day, it would be good to let it do full self driving. For now, we’ll be working with manual control where your mobile phone is the controller.

Quick rundown of serial communication: It’s when you send data (communicate) to things using serial. USB (Universal Serial Bus) has become the most common lately, the different heads are just to connect to things of different sizes.

Parts:

  • The ‘tank’ previously made
  • Bluetooth module
  • Android phone with Bluetooth -> Arduino app installed

I made a (very simple) Android app that allows you to send data to Arduino via Bluetooth. Technically you can send data to anything that uses Bluetooth (Raspberry Pi for example) but the focus is with Arduino. I’ve released it 100% free, no ads and open source.

I’m going to be working on it and improving it over time, however you can find it on the Google Play Store here.

Assembly:

Another diagram!

Very similar, only addition is the Bluetooth module. To make it obvious how to wire everything up, here’s what you do:

  • VCC -> 5v
  • GND -> GND
  • RXD -> TXD
  • TXD -> RXD

Unless you are using an Arduino Leonardo or another that has multiple serial ports (if you don’t know for sure, assume you only have one serial port) you will need to disconnect and unplug the Bluetooth module completely whenever you are uploading new code to the Arduino.

Code:

Here is the code you will want on your Arduino:

byte serialA;
int RF = 11;
int RR = 10;
int LF = 9;
int LR = 6;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT); //RF
pinMode(10, OUTPUT); //RR
pinMode(9, OUTPUT); //LF
pinMode(6, OUTPUT); //LR
}

void loop()
{
if (Serial.available() > 0) {serialA = Serial.read();Serial.println(serialA);}

switch (serialA) {
case 49: //Forward on text 1 through serial
digitalWrite(RF, HIGH);
digitalWrite(LF, HIGH);
digitalWrite(LR, LOW);
digitalWrite(RR, LOW);
break;
case 50: //LEFT on text 2 through serial
digitalWrite(LF, LOW);
digitalWrite(LR, HIGH);
digitalWrite(RF, HIGH);
digitalWrite(RR, LOW);
break;
case 51: //RIGHT on text 3 through serial
digitalWrite(LF, HIGH);
digitalWrite(RF, LOW);
digitalWrite(LR, LOW);
digitalWrite(RR, HIGH);
break;
case 52: //Reverse on text 4 through serial
digitalWrite(LF, LOW);
digitalWrite(RF, LOW);
digitalWrite(LR, HIGH);
digitalWrite(RR, HIGH);
break;
}
Serial.print("Received the following: ");
Serial.println(serialA);
}

The switch looks at serialA and depending on what it is will do different cases. The reason for case 49 is because ASCII 1 gets translated to decimal 49 while being sent/received (I’m surprised it isn’t translated to 39 which is 1 in hex but whatever)

Anyway, by now you have your code uploaded, you have the app installed on your phone. Plug the Bluetooth module in and the little red light should start blinking on it. That shows it’s ready to be paired and connected.

Pair it with your phone (the pin should be 1234. If it isn’t, try 0000. If it still isn’t working, double check everything) and then open the app, find the Bluetooth module and then send data to it. Best to send 1 and watch your tank/car/whatever take off.

Leave a comment

Your email address will not be published. Required fields are marked *