Introduction: Arduino Controlled Car

Picture of Arduino Controlled Car

This project is a car that is programed to avoid any objects in front of it automatically, and then turn away from that object and keep on going.

Step 1: Gather All the Parts

After gathering all the parts needed (tired, motor shield, AC motors, etc) design and 3-D print the designed desired by you.

Step 2: Soldering the Motor Shield

Picture of Soldering the Motor Shield

Start off with soldering three wires to the +5V, Ground, and the A0-5 inlets on the motor shield. Also attache the tires to the motors and make sure they are tight in. Note: Make sure your 3-D printed part is thin enough for the shaft of the motor to go through it and still have space to the tire to fit.

Step 3: More Soldering

Picture of More Soldering

Solder the wires to the ends of the AC motors. Make sure not to put a lot of material since the top of the motor have plastic on it and might burn due to heat of the soldered piece. Make sure they are all tight

Step 4: Batteries

Picture of Batteries

Attach the batteries to the motor shield and make sure to tight them in carefully.

Step 5: Programing

To make the car work program upload this code to your Arduino:

#include

AF_DCMotor motor1(1, MOTOR12_8KHZ); AF_DCMotor motor2(2, MOTOR12_8KHZ); AF_DCMotor motor3(3, MOTOR12_1KHZ); AF_DCMotor motor4(4, MOTOR12_1KHZ); const int pingPin = 19; // ------------------------------------------------------------------------------ void setup() { Serial.begin(9600); // set up Serial library at 9600 bps motor1.setSpeed(150); // Sets the speed for all the motors 1 - 4 (255 is the maximum speed) motor2.setSpeed(150); motor3.setSpeed(150); motor4.setSpeed(150); } // ------------------------------------------------------------------------------ float ping() // This is the code that runs the PING ))) Sensor { long duration, inches; pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH); long microsecondsToInches(long microseconds); inches = microsecondsToInches(duration); return inches; } // ------------------------------------------------------------------------------ void forward() // This function moves all the wheels forward { motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD); } // ------------------------------------------------------------------------------ void backward() // This function moves all the wheels backwards { motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD); } // ------------------------------------------------------------------------------ void haltMotors() // This function stops all the motors (It is better to stop //the motors before changing direction) { motor1.run(RELEASE); motor2.run(RELEASE); motor3.run(RELEASE); motor4.run(RELEASE); } // ------------------------------------------------------------------------------ void turnRight() // This function turns the robot right { motor1.run(FORWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(FORWARD); } // ------------------------------------------------------------------------------ void loop() { // This is the main program that will run over and over long duration, inches; // Declare the variables "duration" and "inches"duration = pulseIn(pingPin, HIGH); inches = ping(); // Set the inches variable to the float returned by the ping()function Serial.print(inches); Serial.print("in, "); Serial.println();

while (inches >8){ // While the robot is 8 inches away from an object. inches = ping(); forward(); // Move the robot forward. } haltMotors(); // Stop the motors for 2 seconds, before changing direction. delay(1000); while (inches < 10){ // Until the robot is 10 inches away from the object, go backward. inches = ping(); backward(); // Move the robot backward. } turnRight(); // Once the robot is done moving backward, turn the robot right. delay(1500); // Note! Change this value (greater or smaller) to adjust //how much the robot turns right haltMotors(); delay(1000); } long microsecondsToInches(long microseconds){ return microseconds / 74 / 2; }

Step 6: Motor Shield and Arduino

Picture of Motor Shield and Arduino

Attach the motor shield careful on the Arduino and make sure all the pins are attached.

Step 7: Wiring

Picture of Wiring

Attach the wires from the motors to the motor shield. The wires might get tricky to attach since they might get attached in reverse and the tires will move in a different direction. If this happened all you need to do it to test which tires are rotating in a different direction and switch the wires.

Step 8: Sensor

Picture of Sensor

Attach the wires that you soldered earlier from the motor shield to the PING sensor. Attach the 5V from the motor shield to the 5V from the sensor, the ground from the motor shield to the ground of the sensor, the A0-5 from the motor to the SIG pin for the sensor.

Step 9: Last Step

Attach the top cover to the car that you already designed and 3-D printed to finish up the car and it should be ready to work :)

Comments

Swansong (author)2017-05-04

It looks good :) Do you have the stl files for the case you printed?

About This Instructable

339views

4favorites

License:

More by AsaadA9:Arduino Controlled Car
Add instructable to: