Introduction: SainSmart Car With Bluetooth

In this instructible I continue on the project in SainSmart Car Kit Instructions and I added a HC-06 Bluetooth Module to the Shieldv5.0.

Tips for Building:
- Build the car (metal pieces in the kit) around the wires built in SainSmart Car Kit Instructions
- Make sure the wires are secure (with electrical tape or solder) before putting everything together
- Keep the Car "on blocks" when testing (so it does not roll away)

Materials needed are:
- The materials listed in the Car Kit Instructions before
- HC-06 Bluetooth Module (or HC-05)
- At least four Female to Female Jumper Wires
- Some Female to Male wires
- Three 10K Ohm resistors
- A breadboard
- 9V battery and connection for ir

Step 1: Connect the HC-05 (Power and Ground) to the Shieldv5.0

     To connect the first part follow the wire diagram above.  Start by connecting the + and - pins on the Shieldv5.0 to the VCC and GND and HC-06.  Then connect a male to male jumper wire to the GND and VCC on the Shield to the  end + and - slots in the breadboard (as seen in the diagram).

Step 2: Connect the HC-05 Rx to the Breadboard

     Continue to follow the wire diagram for the Bluetooth.  First, connect a female to female wire from the Rx on the Shield to the Tx on the HC-06.
     To connect the Rx connect a female to male wire into the Tx pin on the Shield and connect the other end into the breadboard.  Then connect a 10K Ohm resistor right above that slot a couple slots away and connect the other end into a slot parallel to that slot.  Connect another female to male right above that slot and connect the female end to the HC-06.  Then make the voltage devider by connecting to 10K resistors or a 20K resistor (like in the diagram) and then use a male to male jumper wire and connect it to the ground row in the breadboard.

Step 3: Coding for the Bluetooth

To connect the HC-06 with the computer download Tera Term or Putty and follow this tutorial http://english.cxem.net/arduino/arduino4.php and to connect the Arduino with an Android download the SENA BTerm on Android.  (Also look at the tutorial at http://www.youtube.com/watch?v=35tQBdpNXH0)

Use this code to program the Bluetooth module:

#include <SoftwareSerial.h>

//Declaring constants for the IN pins
const int rightForwardPin = 4;
const int rightBackwardPin = 2;
const int leftBackwardPin = 7;
const int leftForwardPin = 5;

char incomingByte;

void setup() {
  // put your setup code here, to run once:
  pinMode(rightForwardPin, OUTPUT);
  pinMode(rightBackwardPin, OUTPUT);
  pinMode(leftForwardPin, OUTPUT);
  pinMode(leftBackwardPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //Checks to see that the Serial port is available (In putty/Tera Term/SENA BTerm)
  if (Serial.available() > 0) {
    //Reads the char coming in
    incomingByte = Serial.read();
    if(incomingByte == 'w'){
      forward();
      Serial.println("Going forward");
    } 
    if(incomingByte == 'x'){
      backward();
      Serial.println("Going backward");
    }
    if(incomingByte == 's'){
      stopCar();
      Serial.println("Stopping");
    }
    if(incomingByte == 'd'){
      right();
      Serial.println("Going right");
    }
    if(incomingByte == 'a'){
      left();
      Serial.println("Going left");
    }
  } 
}

//Setting the wheels to go forward by setting the forward pins to HIGH
void forward(){
  digitalWrite(rightForwardPin, HIGH);
  digitalWrite(rightBackwardPin, LOW);
  digitalWrite(leftForwardPin, HIGH);
  digitalWrite(leftBackwardPin, LOW);
}

//Setting the wheels to go backward by setting the backward pins to HIGH
void backward(){
  digitalWrite(rightForwardPin, LOW);
  digitalWrite(rightBackwardPin, HIGH);
  digitalWrite(leftForwardPin, LOW);
  digitalWrite(leftBackwardPin, HIGH);
}

//Setting the wheels to go right by setting the rightBackwardPin and leftForwardPin to HIGH
void right(){
  digitalWrite(rightForwardPin, LOW);
  digitalWrite(rightBackwardPin, HIGH);
  digitalWrite(leftForwardPin, HIGH);
  digitalWrite(leftBackwardPin, LOW);
}

//Setting the wheels to go left by setting the rightForwardPin and leftBackwardPin to HIGH
void left(){
  digitalWrite(rightForwardPin, HIGH);
  digitalWrite(rightBackwardPin, LOW);
  digitalWrite(leftForwardPin, LOW);
  digitalWrite(leftBackwardPin, HIGH);
}

//Setting the wheels to go stop by setting all the pins to LOW
void stopCar(){
  digitalWrite(rightForwardPin, LOW);
  digitalWrite(rightBackwardPin, LOW);
  digitalWrite(leftForwardPin, LOW);
  digitalWrite(leftBackwardPin, LOW);
}

Step 4: Any Problems

If there are any problems look at these tips:
- If the light is not on on the L298N or Arduino check that all the wires inside are attached correctly
-  If the wheels will not move first check that the light on the HC-05 is not blinking (meaning that it is connected. Then, if it is not        blinking then check the code.
- Make sure that the 9 volt battery is connected to the Arduino UNO and the battery pack is connected to the L298N (otherwise the connection will not work)