The Antisocial RobotCar (EAL)

The Antisocial RobotCar moves away from you if you get too close and stops if there is nothing close.

Step 1: Overview

Overview
We wanted to build an antisocial robot car that moves away from obstacles/people.
The way it works is by having 2 Ultra sonic sensors in each end of the car. The car can only move forward and backwards.
If anything get to close to the car <50cm away="" drive="" is="" it="" obstacle="" of="" out="" p="" range.="" the="" until="" will="">It uses 2 DC motors controlled by a L298 DC dual motor controller to move both forwards and backwards.
To power the DC motors we use 3 LIthium batteries cabable to deliver approx 11V to the motors.
Everything is controlled by the Arduino Mega 2560 which all of the components is connected to.

Step 2: Part List

2 X DC Motor, 4 to 24V
1 X Battery Case 3 battery slots
3 X 3,7V Battery
1 X L298N DC Motordriver
2 X Ultrasonic modul hc-SR04
1 X Arduino mega 2560
1 X 9V Battery Cable for Arduino
1 X 9V Battery
3 X Wheels.

Step 3: Building the Car

Building the Car
Start by getting a large piece of plastic board and make holes for you to strap on the components. After having drawn up the holes and made them, attach them to the board.

Use the wiring diagram to connet the components corretly together.
Remeber to make shared ground and wire up the motor driver to the Arduino correctly. If not connected correct, it might not drive or it might drive in the wrong direction.

Remember to secure the connection between the Ultrasonic moduls to the Arduino correctly, or you might have some instable readings.

Step 4: Wiring Diagram

Wiring Diagram
This diragram shows the electrical curcuit in the system.

Step 5: The Code

[code]
//Keyboard Controls: // // 1 -Motor 1 Left // 2 -Motor 1 Stop // 3 -Motor 1 Right // // 4 -Motor 2 Left // 5 -Motor 2 Stop // 6 -Motor 2 Right
// Declare L298N Dual H-Bridge Motor Controller directly since there is not a library to load.
// Motor 1 int dir1PinA = 9; int dir2PinA = 8; int speedPinA = 10; // Needs to be a PWM pin to be able to control motor speed
// Motor 2 int dir1PinB = 5; int dir2PinB = 4; int speedPinB = 7; // Needs to be a PWM pin to be able to control motor speed
int inByteRight; int inByteLeft;
// Ultra-Sound-Sensor 1
#define echoPin1 2 #define trigPin1 3
long duration1, distanceFront;
// Ultra-Sound-Sensor 2
#define echoPin2 11 #define trigPin2 12
long duration2, distanceBack;
void setup() { // Setup runs once per reset
// initialize serial communication @ 9600 baud: Serial.begin(9600);
//Define L298N Dual H-Bridge Motor Controller Pins
pinMode(dir1PinA,OUTPUT); pinMode(dir2PinA,OUTPUT); pinMode(speedPinA,OUTPUT); pinMode(dir1PinB,OUTPUT); pinMode(dir2PinB,OUTPUT); pinMode(speedPinB,OUTPUT);
//Define Ultra-sound-sensor Pins
pinMode(trigPin1, OUTPUT); pinMode(trigPin2, OUTPUT); pinMode(echoPin1, INPUT); pinMode(echoPin2, INPUT);
}
void loop() {
// Ultra-sound-sensor 1 Loop
digitalWrite(trigPin1, LOW); delayMicroseconds(2); digitalWrite(trigPin1, HIGH); delayMicroseconds(10); digitalWrite(trigPin1, LOW); duration1 = pulseIn(echoPin1, HIGH); distanceFront = duration1/58.2;
Serial.print("DistanceFront in cm = "); Serial.println(distanceFront);
delay(10);
// Ultra-sound-sensor 2 Loop
digitalWrite(trigPin2, LOW); delayMicroseconds(2); digitalWrite(trigPin2, HIGH); delayMicroseconds(10); digitalWrite(trigPin2, LOW); duration2 = pulseIn(echoPin2, HIGH); distanceBack = duration2/58.2;
Serial.print("DistanceBack in cm = "); Serial.println(distanceBack);
delay(10);
//Moving Backwards....
if (distanceBack > 25 && distanceFront < 50) { inByteLeft=1; inByteRight=3; } else { Serial.println("Else"); }
//Moving Forwards....
if (distanceBack < 50 && distanceFront > 25) { inByteLeft=3; inByteRight=1; } else { Serial.println("Else"); }
//Stop....
if (distanceBack > 25 && distanceFront > 25) { inByteLeft=2; inByteRight=2; } else { Serial.println("Else"); }
//too close....
if (distanceBack < 25 && distanceFront < 25) { inByteLeft=2; inByteRight=2; } else { Serial.println("Else"); }
switch (inByteLeft) { //______________Motor 1______________
case 1: // Motor 1 Forward analogWrite(speedPinA, 255);//Sets speed variable via PWM digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); Serial.println("Motor 1 Forward"); // Prints out “Motor 1 Forward” on the serial monitor Serial.println(" "); // Creates a blank line printed on the serial monitor break;
case 2: // Motor 1 Stop (Freespin) analogWrite(speedPinA, 0); digitalWrite(dir1PinA, LOW); digitalWrite(dir2PinA, HIGH); Serial.println("Motor 1 Stop"); Serial.println(" "); break;
case 3: // Motor 1 Reverse analogWrite(speedPinA, 255); digitalWrite(dir1PinA, HIGH); digitalWrite(dir2PinA, LOW); Serial.println("Motor 1 Reverse"); Serial.println(" "); break;
default: // turn all the connections off if an unmapped key is pressed: Serial.println(" "); }
switch (inByteRight) { //______________Motor 2______________
case 1: // Motor 2 Forward analogWrite(speedPinB, 255); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); Serial.println("Motor 2 Forward"); Serial.println(" "); break;
case 2: // Motor 2 Stop (Freespin) analogWrite(speedPinB, 0); digitalWrite(dir1PinB, LOW); digitalWrite(dir2PinB, HIGH); Serial.println("Motor 2 Stop"); Serial.println(" "); break;
case 3: // Motor 2 Reverse analogWrite(speedPinB, 255); digitalWrite(dir1PinB, HIGH); digitalWrite(dir2PinB, LOW); Serial.println("Motor 2 Reverse"); Serial.println(" "); break;
default: // turn all the connections off if an unmapped key is pressed: Serial.println(" "); } }
[/code]

Step 6: Extra

Extra
Extra pictures of the car

Step 7: I/O List for the Arduino

Digital Outputs
Motor A
dir1PinA = 9;
dir2PinA = 8;
speedPinA = 10'
Motor B
dir1PinB = 5;
dir2PinB = 4;
speedPinB = 7;
Ultrasonic Front
trigPin1 = 3
Ultrasonic Back
trigPin2 = 12
Digital Inputs
Ultrasonic Front
echoPin1 = 2
Ultrasonic Back
echoPin2 = 11
Power
5v to ultrasonic
2x GND shared
Previous
Next Post »
My photo

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation. I believe everyday can become a Electrician with the right learning materials.
My goal with BLOG is to help you learn Electrical.
Related Posts Plugin for WordPress, Blogger...

Label

KITAIFA NEWS KIMATAIFA MICHEZO BURUDANI SIASA TECHNICAL ARTICLES f HAPA KAZI TU. LEKULE TV EDITORIALS ARTICLES DC DIGITAL ROBOTICS SEMICONDUCTORS MAKALA GENERATOR GALLERY AC EXPERIMENTS MANUFACTURING-ENGINEERING MAGAZETI REFERENCE IOT FUNDAMENTAL OF ELECTRICITY ELECTRONICS ELECTRICAL ENGINEER MEASUREMENT VIDEO ZANZIBAR YETU TRANSDUCER & SENSOR MITINDO ARDUINO RENEWABLE ENERGY AUTOMOBILE SYNCHRONOUS GENERATOR ELECTRICAL DISTRIBUTION CABLES DIGITAL ELECTRONICS AUTOMOTIVE PROTECTION SOLAR TEARDOWN DIODE AND CIRCUITS BASIC ELECTRICAL ELECTRONICS MOTOR SWITCHES CIRCUIT BREAKERS MICROCONTROLLER CIRCUITS THEORY PANEL BUILDING ELECTRONICS DEVICES MIRACLES SWITCHGEAR ANALOG MOBILE DEVICES CAMERA TECHNOLOGY GENERATION WEARABLES BATTERIES COMMUNICATION FREE CIRCUITS INDUSTRIAL AUTOMATION SPECIAL MACHINES ELECTRICAL SAFETY ENERGY EFFIDIENCY-BUILDING DRONE NUCLEAR ENERGY CONTROL SYSTEM FILTER`S SMATRPHONE BIOGAS POWER TANZIA BELT CONVEYOR MATERIAL HANDLING RELAY ELECTRICAL INSTRUMENTS PLC`S TRANSFORMER AC CIRCUITS CIRCUIT SCHEMATIC SYMBOLS DDISCRETE SEMICONDUCTOR CIRCUITS WIND POWER C.B DEVICES DC CIRCUITS DIODES AND RECTIFIERS FUSE SPECIAL TRANSFORMER THERMAL POWER PLANT cartoon CELL CHEMISTRY EARTHING SYSTEM ELECTRIC LAMP ENERGY SOURCE FUNDAMENTAL OF ELECTRICITY 2 BIPOLAR JUNCTION TRANSISTOR 555 TIMER CIRCUITS AUTOCAD C PROGRAMMING HYDRO POWER LOGIC GATES OPERATIONAL AMPLIFIER`S SOLID-STATE DEVICE THEORRY DEFECE & MILITARY FLUORESCENT LAMP HOME AUTOMATION INDUSTRIAL ROBOTICS ANDROID COMPUTER ELECTRICAL DRIVES GROUNDING SYSTEM BLUETOOTH CALCULUS REFERENCE DC METERING CIRCUITS DC NETWORK ANALYSIS ELECTRICAL SAFETY TIPS ELECTRICIAN SCHOOL ELECTRON TUBES FUNDAMENTAL OF ELECTRICITY 1 INDUCTION MACHINES INSULATIONS ALGEBRA REFERENCE HMI[Human Interface Machines] INDUCTION MOTOR KARNAUGH MAPPING USEUL EQUIATIONS AND CONVERSION FACTOR ANALOG INTEGRATED CIRCUITS BASIC CONCEPTS AND TEST EQUIPMENTS DIGITAL COMMUNICATION DIGITAL-ANALOG CONVERSION ELECTRICAL SOFTWARE GAS TURBINE ILLUMINATION OHM`S LAW POWER ELECTRONICS THYRISTOR USB AUDIO BOOLEAN ALGEBRA DIGITAL INTEGRATED CIRCUITS FUNDAMENTAL OF ELECTRICITY 3 PHYSICS OF CONDUCTORS AND INSULATORS SPECIAL MOTOR STEAM POWER PLANTS TESTING TRANSMISION LINE C-BISCUIT CAPACITORS COMBINATION LOGIC FUNCTION COMPLEX NUMBERS ELECTRICAL LAWS HMI[HUMANI INTERFACE MACHINES INVERTER LADDER DIAGRAM MULTIVIBRATORS RC AND L/R TIME CONSTANTS SCADA SERIES AND PARALLEL CIRCUITS USING THE SPICE CIRCUIT SIMULATION PROGRAM AMPLIFIERS AND ACTIVE DEVICES BASIC CONCEPTS OF ELECTRICITY CONDUCTOR AND INSULATORS TABLES CONDUITS FITTING AND SUPPORTS CONTROL MOTION ELECTRICAL INSTRUMENTATION SIGNALS ELECTRICAL TOOLS INDUCTORS LiDAR MAGNETISM AND ELECTROMAGNETISM PLYPHASE AC CIRCUITS RECLOSER SAFE LIVING WITH GAS AND LPG SAFETY CLOTHING STEPPER MOTOR SYNCHRONOUS MOTOR AC METRING CIRCUITS APPS & SOFTWARE BASIC AC THEORY BECOME AN ELECTRICIAN BINARY ARITHMETIC BUSHING DIGITAL STORAGE MEMROY ELECTRICIAN JOBS HEAT ENGINES HOME THEATER INPECTIONS LIGHT SABER MOSFET NUMERATION SYSTEM POWER FACTORS REACTANCE AND IMPEDANCE INDUCTIVE RESONANCE SCIENTIFIC NOTATION AND METRIC PREFIXES SULFURIC ACID TROUBLESHOOTING TROUBLESHOOTING-THEORY & PRACTICE 12C BUS APPLE BATTERIES AND POWER SYSTEMS ELECTROMECHANICAL RELAYS ENERGY EFFICIENCY-LIGHT INDUSTRIAL SAFETY EQUIPMENTS MEGGER MXED-FREQUENCY AC SIGNALS PRINCIPLE OF DIGITAL COMPUTING QUESTIONS REACTANCE AND IMPEDANCE-CAPATIVE RECTIFIER AND CONVERTERS SEQUENTIAL CIRCUITS SERRIES-PARALLEL COMBINATION CIRCUITS SHIFT REGISTERS BUILDING SERVICES COMPRESSOR CRANES DC MOTOR DRIVES DIVIDER CIRCUIT AND KIRCHHOFF`S LAW ELECTRICAL DISTRIBUTION EQUIPMENTS 1 ELECTRICAL DISTRIBUTION EQUIPMENTS B ELECTRICAL TOOL KIT ELECTRICIAN JOB DESCRIPTION LAPTOP THERMOCOUPLE TRIGONOMENTRY REFERENCE UART WIRELESS BIOMASS CONTACTOR ELECTRIC ILLUMINATION ELECTRICAL SAFETY TRAINING FILTER DESIGN HARDWARE INDUSTRIAL DRIVES JUNCTION FIELD-EFFECT TRANSISTORS NASA NUCLEAR POWER SCIENCE VALVE WWE oscilloscope 3D TECHNOLOGIES COLOR CODES ELECTRIC TRACTION FEATURED FLEXIBLE ELECTRONICS FLUKE GEARMOTORS INTRODUCTION LASSER MATERIAL PID PUMP SEAL ELECTRICIAN CAREER ELECTRICITY SUPPLY AND DISTRIBUTION MUSIC NEUTRAL PERIODIC TABLES OF THE ELEMENTS POLYPHASE AC CIRCUITS PROJECTS REATORS SATELLITE STAR DELTA VIBRATION WATERPROOF