Professional Documents
Culture Documents
Table of Contents
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
http://www.instructables.com/id/Arduino-motor-drives-cheap-toy-car/
Intro: Arduino motor drives cheap toy car
NOTE: This Instructable replaces a previous one titled "Automate cheap toy car with Arduino." For some strange reason, I was unable to insert photo slides and
add explanations to the first one. I hope to fix this by re-creating the original Instructable here.
I have bought a cheap toy car for a few Euros then rigged it with Arduino Uno, Motor Shield, IR sensor. Not too shabby.
I divided this project into two parts. In Part I, I take the cheap toy car apart then place the Arduino Uno + Motor Shield on the platform that contains 2 motors, one in the
back for locomotion and the other in the front to turn car left and right by turning a pinion.
For Part II, I added a Sharp IR sensor then programmed the Arduino to avoid obstacles. Since electronic parts are expensive in Jordan and are subject to arbitrary tariffs
and in some cases confiscations, it was necessary to scavenge parts from locally available products.
In future videos, I will add more sensors and enhance the robot's intelligence. I am also considering rewiring the robot as a differential steering robot since the bulk of
entry level robots seem based on it. This should give me access to tons of sample code as well as make my code of use to more designers.
This is my first robot ever. Actually it's my first Arduino project ever. Heck it's my first electronics project ever. Love Arduino :)
This code tests the Arduino Uno and the Motor Shield's which drives a gutted 6 Euro toy car I got from Gardens.
The toy car has two DC motors, one to drive the car's back wheels and the front motor to turn fron wheels gear left or right.
The Arduino is powered from a 9v battery while the Motor Shield, motorDrive, and motorTurn are powered
from the toy car's 4.5v (3 X AA) batteries.
*/
#include <AFMotor.h>
AF_DCMotor motorDrive(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm, to drive rear wheels forward and reverse
AF_DCMotor motorTurn(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm, to turn front wheels L and R
/* Sonar settings */
const int SonarPin = 0;
long anVolt, inches, cm;
int sum=0; //Create sum variable so it can be averaged
int avgrange=60; //Quantity of values to average (sample size)
int DistanceToObject = 6; // distance to obstacle before reverse - in inches
int TurnPause = 500; // delay between changes in turn
int AvgDelay = 6;
void setup() {
pinMode(SonarPin, INPUT); // set Sonar pin for input
void loop() {
Serial.println("Forward/Straight move...");
anVolt = analogRead(SonarPin);
sum += anVolt;
delay(AvgDelay);
}
inches = sum/avgrange/2;
cm = inches * 2.54;
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
motorDrive.run(FORWARD); // turn motor on going Forward which will spin rear wheel in Reverse
}
else {
motorDrive.run(FORWARD);
}
http://www.instructables.com/id/Arduino-motor-drives-cheap-toy-car/
Image Notes Image Notes
1. I bough this El Cheapo car from for less than 10 Euros. It's actually an RC toy 1. El Cheap car < 10 Euros
car. I figured since most robot fans in Jordan are too poor to buy high end robot 2. This motor drives the back wheels.
parts, it's better for me to work on scavenged parts this way my workshop 3. This motor moves front wheels left and right but does not move car forward.
students will be able to sustain their hobby on their own. 4. This is where 3 AA batteries are held.
5. Arduino Uno
6. Arduino Motor Shield Kit. I soldered this kit together and I did a terrible job
because I did not read the instructions carefully. my El cheapo 3 Euros solder
stick was also a factor. But i the end, it worked.
7. PIR sensor. I did not use it in this project but I have plans for it in future
robots.
8. Ultrasonic sensor. This wan also was not used in this project.
9. This is the Sharp IR sonar.
10. 9V to drive Arduino.
11. 9V battery holder to plug into Arduino
12. AA batteries.
13. Imagine in this spot 10uF by-pass capacitor I placed between VCC and
GND on the IR sensor. Without it, the readings on the sensor were so erratic to
the point of uselessness.
http://www.instructables.com/id/Arduino-motor-drives-cheap-toy-car/
Image Notes
1. IR sensor
2. This motor turns front wheels left and right. it was connected to M2 on motor
shield.
3. I believe this is a 0.1uF capacitor between terminals of each motor to protect
circuit from motor noise.
4. This is one ugly MF robot.
File Downloads
SonarCar.pde (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'SonarCar.pde']
Related Instructables
http://www.instructables.com/id/Arduino-motor-drives-cheap-toy-car/