Freedominu

Project Zone

Postulate Substantiate Generate Proliferate

4WD Arduino Robotic Car

Resources

MATERIALS:

Arduino Uno

L298N motor controller

Arduino Sensor Shield V5.0

HCSR04 Ultrasonic sensor

Servo Motor with Servo Holder

14 female to female connector wires

4 wheels

4 motors

4 red power wires and 4 black power wires for motor to L298N motor board

TOOLS:

small size phillips head screw driver

hot glue gun with hot glue

Current Issues

1. mounting of sensors past chassis edge allows sensors to be damaged in collisions

2. Infrared sensors not working

3. difficult to moderate car behaviour the closer the side of the car comes to parallel with an object - would benefit from side sensors

4. would benefit from a simple switch in the circuit to turn the power off to save taking a battery out

Lesson Learned

1. mounting of sensors past chassis edge allows sensors to be damaged in collisions

2. Infrared sensors not working

3. difficult to moderate car behaviour the closer the side of the car comes to parallel with an object - would benefit from side sensors

4. would benefit from a simple switch in the circuit to turn the power off to save taking a battery out

Method

Hardware Method

Step 1: take the laminate off all the pieces of plastic

Step 2: line the motors up in the same direction

Step 3: solder the red power wires to the same side on all the motors ( red is positive) you can choose either side to be positive as long as you make sure all the motors are done the same way

Step 4: solder the black power wire to the remaining side of the motors (black is negative)

Step 5: connect the wheels to the motors

Step 6: connect the motors to the plastic chassis

Step 7: connect three female wires to the ultrasonic sensor

Step 8:

Step 9:

Step 10:

Step 11:

Step 12:

Step 13:

Step 14:

Step 15:

Step 16:

Step 17:

Step 18:

Step 19:

Step 20:

Step 21:

Arduino Robot Car Code in programming language C

Arduino Robot Car Ino File
//4WD Arduino Robot Car //Make sure you choose the correct arduino board - This example used an Arduino Uno - but you can choose any Arduino board with enough pins to send and receive signals for your task #include <Servo.h> //Servo motor library. This is standard library #include <NewPing.h> //Ultrasonic sensor function library. You must install this library // motor pins from the L298 // connect motor controller pins to Arduino digital pins // motor one int enA = 5; int in1 = 2; int in2 = 3; // motor two int enB = 6; int in3 = 7; int in4 = 4; //Servo motor for hard ware pins Servo myServo; // creates a servo object for controlling the servo motor //Ultrasonic sensor for hardware pins #define trigPin A4 #define echoPin A3 //servo motor right_front = 45degrees, front = 90 degrees and left_front = 135 degrees int ultra_sense_right_front; int ultra_sense_front; int ultra_sense_left_front; #define maximum_distance 45 NewPing sonar(trigPin, echoPin, maximum_distance); //sensor function #define threshold 45 int action; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); // put your setup code here, to run once: //Serial.begin(9600); // serial / USB port //motor - sets the motor pins to output pinMode(enA, OUTPUT); pinMode(enB, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); // servo motor myServo.attach(8); long duration, distance45, distance90, distance135; //define the front threshold as 30 centimetres } void oneeighty_left(){ //turn 135 degrees to the left //left side back digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // set speed to 200 out of possible range 0~255 analogWrite(enA, 200); //right side forward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(250); } void right_turn(){ //turn right //left side forward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enA, 200); //right side back digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(100); } void left_turn(){ //turn left //left side back digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // set speed to 200 out of possible range 0~255 analogWrite(enA, 200); //right side forward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(100); } void forward(){ //drive forward // turn on motor A digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enA, 200); // turn on motor B digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(300); } void stop_car(){ //turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void loop() { delay(1000); // uS / 58 = centimeters; or: the range = high level time * velocity (340M/S) / 2; //http://apcmag.com/arduino-basics-7-turning-heads-with-arduino.htm/ // Function for calculating the distance measured by the Ultrasonic sensor //sense ultrasonic environment //read voltage from ultrasonic //test ultrasonic sensor front myServo.write(90); delay(200); //waiting 300 microseconds for the slew(servo moving) time long duration, distance90; // Send the value to the Serial Monitor digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance90 = (duration/2) / 29.1; //Serial.println("Distance at 90 degrees = "); //Serial.print(A2); //Serial.print(A3); //Serial.println(" cm"); // Interval between readings 1000 = 1 second delay(500); //test ultrasonic sensor left_front myServo.write(135); delay(200); //waiting 1000 = 1 second for the slew(servo moving) time long distance135; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance135 = (duration/2) / 29.1; //Serial.println("Distance at 135 degrees = "); //Serial.print(distance135); //Serial.println(" cm"); delay(200); myServo.write(45); delay(200); //waiting 1000 = 1 second for the slew(servo moving) time long distance45; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance45 = (duration/2) / 29.1; //Serial.println("Distance at 45 degrees = "); //Serial.print(distance45); //Serial.println(" cm"); //http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/ // Interval between readings 1000 = 1 second delay(200); forward(); delay (1000); if (distance90 < threshold){ stop_car(); //test ultrasonic sensor front myServo.write(90); delay(200); //waiting 300 microseconds for the slew(servo moving) time long duration, distance90; // Send the value to the Serial Monitor digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance90 = (duration/2) / 29.1; //Serial.println("Distance at 90 degrees = "); //Serial.print(A2); //Serial.print(A3); //Serial.println(" cm"); // Interval between readings 1000 = 1 second delay(500); //test ultrasonic sensor left_front myServo.write(135); delay(200); //waiting 1000 = 1 second for the slew(servo moving) time long distance135; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance135 = (duration/2) / 29.1; //Serial.println("Distance at 135 degrees = "); //Serial.print(distance135); //Serial.println(" cm"); delay(200); myServo.write(45); delay(200); //waiting 1000 = 1 second for the slew(servo moving) time long distance45; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance45 = (duration/2) / 29.1; //Serial.println("Distance at 45 degrees = "); //Serial.print(distance45); //Serial.println(" cm"); //http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/ // Interval between readings 1000 = 1 second delay(200); forward(); if (distance135 < threshold){ stop_car(); if (distance45 < threshold){ stop_car(); oneeighty_left(); } else{ stop_car(); right_turn(); } }else{ stop_car(); } } }