Arduino Autonomous Vehicle

by NoahT11 in Circuits > Microcontrollers

874 Views, 2 Favorites, 0 Comments

Arduino Autonomous Vehicle

IMG_3348.JPG

This is a car. More coming soon!

Cut Out Body.

Cut out a piece of 8th inch (or 16th) plywood. Make sure it has a slit in the middle to accommodate the gears and wheels and that it is large enough to fit everything.

Glue on Motor.

Glue on the motor with hot glue.

Add Gears and Axles.

Use ring screws that are small enough to be snug on the axle. Screw the ring screws into the wood first, put the gear in between them, and slide in the axle. Make sure the gears are snug enough that they mesh but not too snug that they don't turn. Secure the gears on the axles with hot glue.

Attach Wheels to the Axle.

We found 3D printed wheels about the right size. You can 3D print your own or salvage them from a toy car etc.

Drill through the hole in the center of the wheel so that it is snug on the axle. Then, bend part of the axle that remains outside the wheel with two wrenches in a 90 degree bend. The now vertical part of the axle should be parallel with the outside face of the wheel. Glue the vertical part of the axle to the outside face of the wheel with hot glue.

Wire Up Relays.

Screen Shot 2016-06-01 at 11.23.49 AM.png
Screen Shot 2016-06-01 at 11.20.49 AM.png

Wire up two relays on perfboard (or a breadboard) in the configuration shown.

This configuration allows the motor to spin both directions. When only one green wire is high (connected to the arduino's 5V), one relay switches from ground to high while the other stays at ground. One motor terminal is now connected to 12v while the other is connected to ground. When we connect 5V to the other green wire and connect the first one to ground, the reverse happens. The other relay output is now at 12V while the first one is now connected to ground. This causes the motor to turn the other way. When both green wires are high or both are low, the motor will not spin because both of its terminals are connected to the same voltage.

Make Steering System.

Attach any wheel to the front axle (it doesn't have to be firmly secured on the axle this time, but it shouldn't fall off), feed it through the straw, and attach the other wheel to the side of the axle outside of the straw in the same way. After this, hot glue the straw to the servo rotor.

Attach Steering System to Body.

Screw the back of the servo to the front of the body with wood screws.

Connect Everything Together

Connect the arduino to the two relay wires and to the servo.

Make the Case.

Make the case out of cardboard, foam core, wood, whatever! Make sure the on/off switch is screwed on to the case securely and is accessible.

Code.

Here's my code.

//////////////////////////////////////////////////////

#include
Servo servo;

int servoPin = 5;

const int RELAY1 = 10;

const int RELAY2 = 11;

const int STRAIGHT = 30, LEFT = 55, RIGHT = 5;

const int FORWARD = 1, BRAKE = 0, BACKWARD = -1;

void setup() {

servo.attach(servoPin);

servo.write(30);

pinMode(RELAY2,OUTPUT);

pinMode(RELAY1,OUTPUT); }

void loop() {

go(1,RIGHT, 500);

go(0,STRAIGHT, 500);

go(-1, LEFT, 500);

go(0, STRAIGHT, 500);

}

void go(int n, int direction, int duration){

servo.write(direction);

if(n == FORWARD){

digitalWrite(RELAY2,HIGH);

digitalWrite(RELAY1,LOW);

}

if(n == BACKWARD){

digitalWrite(RELAY2,LOW);

digitalWrite(RELAY1,HIGH);

} if(n == BREAK){

digitalWrite(RELAY2,LOW);

digitalWrite(RELAY1,LOW);

}

delay(duration);

}