Introduction: SainSmart Car Kit Instructions

These instructions are for the wiring for the SainSmart C98 on the inside of the car.  This product could be found on Amazon for around $90.  The SainSmart Kit did not come with sufficient instructions, so I decided to post some.  Follow the Wire Diagram above when following each of the steps for wiring.

The materials in the kit include:
     - Arduino Mega
     - Distance Sensor
     - L298N Module (Driver Module)
     - SainSmart Sensor Shieldv5.0
     - Various wires
     - Toggle Switch
     - Charging Interface
     - Four Motors and Wheels
     - Power Supply Box
     - Metal Pieces and various nuts and bolts
Other materials needed are:
     - Electrical tape
     - Screw Driver

Step 1: Wiring the Charge Switch

     Follow the wiring diagram shown.  When wiring the charge switch strip the wires and wrap the stripped ends around the hole in the metal prong. After looping the wire in the hole wrap electrical tape around the wire and prong (as seen in the second picture down).  If any of these wires make contact with each other it could start an electrical fire (it made a small one with me).
     Also, when connecting the wires from the battery pack to the Switch and Charging Socket make sure to use the wires that are coming out of the battery pack, so you do not have to do any extra taping with the electrical tape.

Step 2: Connecting the Switch to the L298N Module

     When, connecting the switch to the L298N Module start by unscrewing the screw and slide the stripped wire into the slot underneath where the screw was and then tighten the screw again.

Step 3: Connecting the L298N to the Shield

     Start by Snapping the Sensor Shield into the Arduino Uno or Mega (seen in the first picture).  Then use the Female-Female wires to connect the IN1 to IN4 to the pins shown in the top wire diagram.  Connect IN1 to D7, IN2 to D5, IN3 to D4, and IN4 to D2.  Then connect the VCC and GND on the Sensor Shield to the 5V and GND on the L298N.

Step 4: Connecting the Motors to the L298N

     To connect each motor to the L298N Module take a red wire and connect it from OUT1 to a prong on the motor.  Then connect a black wire from OUT2 to the other prong on the motor.  Do this for the other motor by connecting the red and black wires to the OUT3 and OUT4.

Step 5: Coding for the Motors

To get the code to work you must first go through these steps:
     1. Go to http://learn.adafruit.com/adafruit-motor-shield/library-install
     2. Click on "First, grab the library from github" and download the "adafruit-Adafruit-Motor-Shield-library-4bd21ca.zip" file
     3. Go to Libraries --> Documents --> Arduino --> libraries and then drag the zip file in
     4. Unzip the file and rename the new unzipped file "AFMotor" (or something you will remember)
     5. Close and reopen the Arduino Software (if already open)
     6. Go to Scetch --> Import Library --> AFMotor

Then copy this code to test if the wheels work :

//declaring the pins for the IN pins on the L298N
const int rightForwardPin = 4;
const int rightBackwardPin = 2;
const int leftBackwardPin = 7;
const int leftForwardPin = 5;

int runTime = 5000;

void setup() {
  //Stating that the pins are OUTPUT
  pinMode(rightForwardPin, OUTPUT);
  pinMode(rightBackwardPin, OUTPUT);
  pinMode(leftForwardPin, OUTPUT);
  pinMode(leftBackwardPin, OUTPUT);
}

//Looping to test the wheels of the car
void loop() {

  forward();

  stopCar();

  backward();

  stopCar();

  left();

  stopCar();

  right();

  stopCar();
}

//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);
  delay(runTime);
}

//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);
  delay(runTime);
}

//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);
  delay(runTime);
}

//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);
  delay(runTime);
}

//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);
  delay(1000);
}

Then modify the code to make your robot work with distance sensors or other sensors.

Step 6: If the Motor Is Not Working

If the motor is not moving after connecting everything do the following:
     - Check to see if the button next to the VCC, GND, and  5V side f the L298N is pushed down because if it is not the circuit will not             be on
     - Recheck the circuit with the Wire Diagram at the top of this page
     - Check to see if you,re batteries have enough power 
     - Check that the code is correct
     - Make sure you were on the right COM when downloading the code

Some References:
     - At the following site I found the code that worked for the car     
http://books.google.com/books?id=yZKRDrdthRQC&pg=PA68&lpg=PA68&dq=AF_DCMotor+Motor_Left_Front(4,+MOTOR34_1KHZ);