Assembled Rover |
There were a few problems with this kit. I wouldn't recommend getting this kit unless you have some experience. Some of the screw holes in the metal frame don't line up very well, but that was pretty minor. The biggest problems are that it doesn't come with enough wire and several of the parts in the kit were bad. In my kit, the Mega 2560 wouldn't accept code uploads and the reset button on it didn't work at all. Also, the battery pack had a short so when I hooked it up it started smoking.
Fortunately, I was able to use an Arduino Mega, some 9 volt battery connectors, and extra wire I already had. Hopefully SainSmart will send me a functional Mega to replace the non-working board in my kit. There is also nothing to mount the distance sensor and no hook up wires for it, so you'll have to get creative if you want to use it.
Parts List from the Kit:
4 wheels4 motors
2 rounded metal plates fro the front and back
2 side plates
2 flat plates for the top and bottom of the case
A bunch of screws
2 wires (1 red, 1 black)
1 4-wire female to female connection harness
1 battery pack
1 toggle switch
1 re-charge connector
1 USB cable
1 SainSmart MEGA 2560 R3
1 SainSmart Sensor Sheild V5
1 SainSmart L298N Dual H Bridge DC motor driver
1 HC-SR04 Distance Sensor
Other Items you'll need:
2 9 volt batteries2 9 volt battery connectors
extra wire
solder and a soldering iron
electrical tape
wire strippers
A volt meter
Build it ..
STEP 1: Hook up the Toggle Switch and connect the battery leads to the L298N Motor Driver
- Place the toggle switch in one of the holes on the top plate and use the washer and nut (only one fits) to secure it in place.
- Secure the L298N Motor Driver to the bottom plate using the screws provided. (The wholes in the plate should line up pretty will with the mounting wholes on the board.)
- Connect the battery connectors together in series by soldering the ends of the black lead on one connector to the red lead on the second connector. Use electrical tape to cover the connection.
- Connect/solder the remaining red lead on the first battery connector to the center lead on the toggle switch.
- Connect the remaining black lead on the other battery connector to the screw connector on the Motor Driver labeled Gnd (The ground pin).
- Cut a 4 inch piece of the red wire that came in the kit and strip away the sheath on the end to expose the wire on the cut side. Connect one side of this wire to one of the side leads on the toggle switch. Connect the other end to the to the screw connector labeled Vcc on the Motor Driver board.
- Test the toggle switch connections and make sure it works.
With the switch in the off position, connect the batteries. Then flip the switch to the on position. If your connections are good, the red led on the Motor Driver board should light up. if it doesn't, check the connections and try again. - Turn the switch off and disconnect the batteries.
STEP 2: Connect the Motors to the Motor Driver
- Cut 2 4 inch wires from the red wire, and 2 4 inch wires from the black wire.
- Cut 2 6 inch wires from the red wire and 2 6 inch wires from the black wire.
- Strip the ends of each of the wires.
- Solder the 4 inch black wire to one of the leads on the first motor, and the 4 inch red wire to the other lead on the first motor.
- Solder the the 6 inch wires (one red and one black) to the second motor for the same side as shown in the picture. Caution: Take care to make sure that the wire colors match the orientation in the picture so that the wheels will both spin in the same direction.
- Secure The motors to the side plate and secure the side plate to the bottom plate using the screws provided.
- Connect the red leads for the two motors to one of the screw connection ports on the Motor Driver board labeled out.
- Connect the black leads for the two motors to the other out port on the same side of the Motor Driver board.
Repeat this process for the remaining two motors on the other side.
STEP 3: Connect the remaining wires to the Motor Driver board
- Cut and strip two wires (black and red preferred) to be used as ground and voltage supply wires for the Arduino. These wires will need to be about 6-7 inches long.
- Connect the black wire to the ground on the Motor Driver board using the screw connector.
- Connect the red wire to the 5V screw connector on the Motor Driver board.
- Using the 4 wire harness, connect the wires to the INT pins on the Motor Driver board as follows:INT1 -> Red
Switch and INT pin Connections INT2 -> BrownINT3 -> BlackINT4 -> White
- Re-connect the batteries, but leave the switch off for now.
- Fish the power, ground and 4 wire harness wires through the top plate from the bottom side.
- Place the top plate on top of the two sides where it will eventually be screwed on.
STEP 4: Program the Mega Using the Arduino IDE
The great thing about the Motor Driver board, is that for on and off control of the motor, you don't need any external libraries, just set the pins HIGH and LOW to control the direction of the motors.
Copy the following code upload it to the Mega board using the Arduino IDE.
const int rightForwardPin = 4;
const int rightBackwardPin = 2;
const int leftBackwardPin = 7;
const int leftForwardPin = 5;
int runTime = 1000;
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);
}
STEP 5: Connect the Sensor Shield and Mega to the Circuit
- Place the sensor shield on the Mega making sure the connection pins are placed in the correct slots.
- Connect the 5V power line to the Vcc screw connection terminal on the Sensor Shield.
- Connect the Ground line to the GND ground screw connection terminal on the Sensor Shield.
- Connect the 4 wire harness to the following pins on the Sensor Shield:
Red - > pin 7
Brown -> pin 5
Black -> pin 4
White -> pin 2
Sensor Shield Connections |
STEP 6: Test It
Now with all the connections made, it's time to see if works.
- Secure the top plate and secure the Mega board to the top plate (using the small screws).
- Turn the switch to the ON position.
- The motors should start to turn soon after it is turned on.
- The green LED on the Mega board should come on and a red LED may be lite or flashing on the Sensor Shield, indicating that is has power. If there is no power, try pushing the button on the Motor Driver board to turn on the external power.
- Verify the direction that the motors are turning in. Both motors on any given side should always turn in the same direction.
If everything is working, Attach the wheels and finish securing the front and back metal plates.