Professional Documents
Culture Documents
Instrucciones Montaje
Instrucciones Montaje
Instrucciones Montaje
ARDUINO, VIDEO
In this tutorial you will learn to make a 4WD robotic car with built-in obstacle
avoidance. This project involves building a 4WD car with an ultrasonic sensor that can
detect nearby objects and change its direction to avoid these objects. The ultrasonic
sensor will be attached to a servo motor which is constantly scanning left and right
looking for objects in its way.
4WD
autonomous robotic car
You can extend this project by adding more sensors such as ultrasonic sensor to the rear
so that the car doesn’t reverse into objects, speed detection sensors to determine speed,
line following sensors, and LED brake lights. You could even add light sensors and
LEDs to turn headlights on in low-light conditions or a Bluetooth connection to control
the car through a mobile app.
Parts required
Here is what you will need:
Video Player
00:00
15:59
Wiring it up
Now that the chassis is assembled and the wheels and motors are attached, you will
need to wire up all of the components. You can watch the video below or scroll down
for the step-by-step instructions and wiring diagram.
Video Player
00:00
18:38
1. Connect the red wire (voltage) from the battery enclosure to VCC on the L298N Motor
Module.
2. Connect the black wire (ground) from the battery enclosure to GND on the Motor Module.
3. Connect the red wire from Motor A1 (rear left) and the red wire from Motor A2 (front left)
to OUT1 on the Motor Module (both wires can be twisted together and will go into OUT1 –
the wiring diagram further down this page shows how to do this).
4. Connect the black wire from Motor A1 (rear left) and the black wire from Motor A2 (front
left) to OUT2 on the Motor Module.
5. Connect the red wire from Motor B1 (rear right) and the red wire from Motor B2 (front
right) to OUT3 on the Motor Module.
6. Connect the black wire from Motor B1 (rear right) and the black wire from Motor B2 (front
right) to OUT4 on the Motor Module.
7. Connect a female-to-female end wire from ENA (Engine A) on the Motor Module to signal
pin 1 on the Sensor Shield (the #2 pin in the S row. There are three rows – S stands for
Signal, V for Voltage and G for Ground).
8. Connect a female-to-female end wire from 5V (next to ENA) on the Motor Module to
voltage pin 1 on the Sensor Shield (it doesn’t really matter which pin for voltage as long as it
is in the V row).
9. Connect a female-to-female end wire from IN1 on the Motor Module to signal pin 2 on the
Sensor Shield.
10. Connect a female-to-female end wire from IN2 on the Motor Module to signal pin 3 on the
Sensor Shield.
11. Connect a female-to-female end wire from IN3 on the Motor Module to signal pin 4 on the
Sensor Shield.
12. Connect a female-to-female end wire from IN4 on the Motor Module to signal pin 5 on the
Sensor Shield.
13. Connect a female-to-female end wire from 5V (next to ENB) on the Motor Module to
voltage pin 6 on the Sensor Shield (it doesn’t really matter which pin for voltage as long as it
is in the V row).
14. Connect a female-to-female end wire from ENB (Engine B) on the Motor Module to signal
pin 6 on the Sensor Shield.
15. Connect the signal wire from the servo motor to signal (S) pin 7 on the Sensor Shield, the
voltage wire from the servo motor to the voltage (V) pin 7 on the Sensor Shield, and the
ground wire from the servo motor to the GND (G) pin 7 on the Sensor Shield.
16. Attach the Ultrasonic Sensor to the servo motor and then attach the servo motor to the front
of the car so that it can scan left and right looking for objects in its path.
You can use sticky tape, blu-tack, glue or a 3D printed/laser cut mount or whatever you like
to attach everything, as long as everything is firmly mounted.
17. Use female-to-female end plugs to connect the Ultrasonic sensor to the Sensor Shield.
Firstly, attach the TRIG pin from the Ultrasonic sensor to signal (S) pin 8 on the Sensor
Shield. Attach the ECHO pin from the ultrasonic sensor to signal (S) pin 9 on the Sensor
Shield. Attach the VCC pin from the Ultrasonic Sensor to the voltage (V) pin 10 on the
Sensor Shield. Lastly, attach the GND pin from the Ultrasonic Sensor to the GND (G) pin 11
on the Sensor Shield.
18. Now attach the Sensor Shield on top of the Arduino Uno board making sure to not bend any
pins. Connect a 9V Battery Barrel Jack Connector to a 9V battery and then plug this in to the
Arduino’s barrel jack (see diagram below).
19. That’s it! Now all you need is batteries and the code!
Please note: There are several variations of the sensors and modules and several
different ways to wire this up. For example, you can add a charging component to
charge batteries and you can also add different switches. There may be other better
methods to use, but I have gone for the simplest way I know of to set this up.
Wiring diagram
Click for larger image
Finishing up
Once you have the code you will need to verify it and then upload it to your Arduino
Uno board. Make sure you have either the Arduino disconnected from the Sensor
Shield or all batteries disconnected when uploading the code to prevent any errors
while uploading.Make sure to also arrange the different components carefully in the
chassis to prevent any short circuits.
And that’s it! There is so much more that can be done with this project. Try extending
your project by adding the following features:
Line following
Low-light activated headlights (using light sensors and LEDs)
Brake lights
Speed measuring
Bluetooth/mobile app control
More ultrasonic sensors to avoid reversing into objects or falling off edges
The video below shows a demo of the 4WD autonomous car using an Arduino and the
ultrasonic sensor attache to a servo motor. Six AA batteries power the motors while the
Arduino board is powered using a separate 9V battery.
Video Player
00:00
00:21
More photos
4WDARDUINOAUTONOMOUSCCARCODELANGUAGEPROJECTROBOTROBOTICSELF-
DRIVINGTUTORIALVIDEO
ARDUINO, VIDEO
This tutorial will show you how to use an Arduino to build a 2WD robotic car. You can
extend this project by using sensors to measure wheel speed (for improved accuracy
when steering or maintaining a straight line) or sensors to avoid objects or follow a line.
Parts required
Here is what you will need:
1. Assemble all chassis parts and attach the motors to the wheels (if not already assembled).
2. Connect the red wire from the battery enclosure to VIN on the Motor Shield.
3. Connect the black wire from the battery enclosure to GND on the Motor Shield.
4. Connect the red wire from Motor A to A+ on the Motor Shield, and the black wire from
Motor A to A- on the Motor Shield.
5. Connect the red wire from Motor B to B+ on the Motor Shield, and the black wire from
Motor B to B- on the Motor Shield.
6. Attach the Motor Shield to the top of the Arduino Uno board – be careful not to bend or
damage any of the pins!
7. Connect the Arduino Uno board to the computer via the USB cable and upload the code
using the Arduino IDE software.
8. Insert four AA batteries in the battery enclosure.
9. Test your robot! If your robot goes in the wrong direction or doesn’t move, check that you
have the Motor pins in the correct places and make sure no pins are loose.
Extra challenges:
Control your robotic car using an Android app on a smartphone via Bluetooth (refer to the
Controlling an LED by Bluetooth tutorial for instructions on how to make an app using App
Inventor and how to attach a Bluetooth module).
Add code that will control the speed of the motors using the encoder discs and infrared
sensors.
The code to test your robot
Use this code to test that your wheels spin and that your robot is wired up correctly.
void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
//Setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel B pin
pinMode(8, OUTPUT); //Initiates Brake Channel B pin
}
void loop(){
//Motor A forward @ full speed
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins the motor on Channel A at full speed
//Motor B backward @ half speed
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
analogWrite(11, 123); //Spins the motor on Channel B at half speed
delay(3000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(8, HIGH); //Engage the Brake for Channel B
delay(1000);
//Motor A forward @ full speed
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 123); //Spins the motor on Channel A at half speed
//Motor B forward @ full speed
digitalWrite(13, HIGH); //Establishes forward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
analogWrite(11, 255); //Spins the motor on Channel B at full speed
delay(3000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(8, HIGH); //Engage the Brake for Channel B
delay(1000);
}
Click here if you would like a PDF copy of these instructions.
2WDARDUINOBUILDBUILDINGCARCODEIDEPROJECTROBOTROBOTICUNO
ARDUINO, VIDEO
ARDUINO WEATHER STATION
PROJECT
SEPTEMBER 1, 2015
This tutorial will show you how to take temperature readings using the Freetronics
temperature sensor and an Arduino Uno.
Note that there are two different module types: the temperature sensor module and the
humidity & temperature sensor module. If you have the humidity & temperature sensor
module you will need to download a library for the Arduino IDE and use different
wiring and code – follow the instructions for that module
here: http://www.freetronics.com.au/pages/humid-humidity-temperature-sensor-
module-quickstart-guide
Parts required
Here is what you will need:
Attach the temperature sensor module to your breadboard. The GND pin should connect
the GND pin on the Arduino board, the VCC pin should connect the 5V pin on the
Arduino board, and the DATA pin should connect to the digital I/O pin 2 on the
Arduino board – all these are connected via the breadboard using male-to-male jumper
wires.
Arduino code
Here is the code for the Arduino sketch (you can also copy it
from http://www.freetronics.com.au/pages/temp-temperature-sensor-module-quickstart-
guide). Make sure you scroll down to see how to test the sensor.
#define REF_PIN 2
void getCurrentTemp( int *sign, int *whole, int *fract);
char temp_string[10];
void setup(){
Serial.begin(9600);
// initialize DS18B20 datapin
digitalWrite(REF_PIN, LOW);
pinMode(REF_PIN, INPUT); // sets the digital pin as input (logic 1)
pinMode(15, INPUT);
}
void loop(){
getCurrentTemp(temp_string);
Serial.println(temp_string);
delay(1000);
}
void OneWireReset (int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite (Pin, LOW);
pinMode (Pin, OUTPUT); // bring low for 500 us
delayMicroseconds (500);
pinMode (Pin, INPUT);
delayMicroseconds (500);
}
void OneWireOutByte (int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for (n=0; n<8; n++) { digitalWrite (Pin, LOW); pinMode (Pin, OUTPUT); delayM
delayMicroseconds (50); d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return (d);
}
void getCurrentTemp (char *temp)
{
int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
OneWireReset (REF_PIN);
OneWireOutByte (REF_PIN, 0xcc);
OneWireOutByte (REF_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset (REF_PIN);
OneWireOutByte (REF_PIN, 0xcc);
OneWireOutByte (REF_PIN, 0xbe);
LowByte = OneWireInByte (REF_PIN);
HighByte = OneWireInByte (REF_PIN);
TReading = (HighByte << 8) + LowByte;
sign = TReading & 0x8000; // test most sig bit
if (sign) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
whole = Tc_100 / 100; // separate off the whole and fractional portions
fract = Tc_100 % 100;
if (sign) {
temp[0] = '-';
} else {
temp[0] = '+';
}
if (whole/100 == 0) {
temp[1] = ' ';
} else {
temp[1] = whole/100+'0';
}
temp[2] = (whole-(whole/100)*100)/10 +'0' ;
temp[3] = whole-(whole/10)*10 +'0';
temp[4] = '.';
temp[5] = fract/10 +'0';
temp[6] = fract-(fract/10)*10 +'0';
temp[7] = '\0';
}
Testing
Upload the code once you connect the Arduino to the computer with a USB cable. In
the Arduino IDE, click on Tools > Serial Monitor. Make sure you change the baud rate
to 9600 baud. The temperature sensor should have a constant blue light and the Serial
Monitor should display the temperature readings every second.
Think about how you could use the temperature sensor. You can connect the Arduino
to a dot-matrix or LCD display to display the temperature. It could also be used for
climate control inside a room. How else could you use it?
Click here if you would like to download a PDF copy of these instructions.
ARDUINOCODEIDEPROJECTSENSORSTATIONTEMPERATURETUTORIALUNOWEATHER
ARDUINO, VIDEO
CONTROLLING AN LED USING AN
ANDROID PHONE VIA BLUETOOTH
SEPTEMBER 1, 2015
This tutorial will show you how to make an Android app that can control an LED on an
Arduino using a Bluetooth wireless connection.
Parts required
Here is what you will need:
You must pair the Bluetooth device with your Android phone in the Bluetooth settings
on the phone. The password for pairing is usually 1234. Then in the app you have made,
you will need to connect to the Bluetooth device. NOTE: It is important to remove the
Bluetooth module from the Arduino while the sketch is uploaded to the Arduino board.
Wire it up!
Rx on Bluetooth module connects to Tx on Arduino board. Tx on Bluetooth module
connects to Rx on Arduino board. GND on Bluetooth module connects to GND on
Arduino board and the VCC wire on the Bluetooth module connects to 3.3V on Arduino
board. The LED can be connected to a breadboard with a 470 Ohm resistor. The LED
should be connected to Pin 13 and GND on Arduino.
Arduino code
Here is the code for the Arduino sketch:
App design
Here is the basic screen design of the Android app on App Inventor but you can create
your own interface with more graphics and larger buttons.
That’s it! Now you just need to click on Build > App (Save .apk to my computer) and
send the app to an Android phone. Install the app and upload the Arduino code to the
Arduino board, making sure all wires are set up correctly. Make sure you disconnect the
Bluetooth module from 3.3V before uploading the Arduino code to the board as it can
cause some issues during the upload.
Click here to download a printable PDF copy of these instructions.
ANDROIDAPPARDUINOBLUETOOTHCONTROLCONTROLLINGIDELEDLIGHTMOBILEPHONETUTORIA
LUNO
ARDUINO, VIDEO
The project
This project involves green and red LED lights which flash in an alternating pattern. In
this project, you will use two LEDs but you can add as many as you want if you have
enough jumper wires and LEDs.
Scroll down to view the instructions or click here to download a PDF copy of the
instructions.
What you need:
1 x Arduino Uno or compatible board
1 x red LED
1 x green LED
2 x 470 Ohm resistor (yellow-violet-black-black-brown, or yellow-violet-brown-gold)
1 x Solderless breadboard
3 x jumper wires
Photos
Wiring it up
The code
Here is the Arduino sketch code:
/*
Christmas lights - blinking red and green LEDs
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int redLED = 13;
int greenLED = 12;
ARDUINOCHRISTMASCODECODINGLEDLIGHTSSKETCHTUTORIAL
ARDUINO, VIDEO
This video tutorial explains how to use an Arduino Uno to make an LED night light.
The project involves an Arduino Uno board, an LED, a light sensor which can detect
different levels of light and return a value, a breadboard with jumper wires and resistor.
Basically the way the project works is as follows. Use the light sensor to get light
readings constantly. You can specify a value which, when the light is less than this
value an LED light will be turned on, and when the light is greater than this value the
LED light will be turned off.
This project allows you to work with getting readings from a sensor (input), use if
statements to test conditions, and use an LED to produce some form of output.
00:00
09:53
Downloads:
LED Night Light Printed instructions, code and schematic (pdf)
LED Night Light actual Arduino INO file (.INO file download)
The source code is also available here:
int lightLevel;
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(38400); // Go to Tools > Serial Monitor and change to 38400 bauds to see light value readings
}
// this loop will turn the light on when light reading is below value of 10
// there is a delay of 1 second between checking the light value
void loop()
{
lightLevel = analogRead(A0);
Serial.println(lightLevel, DEC); // this shows the light level reading in Arduino IDE (go to Tools > Serial Mon
if (lightLevel < 50) // change this value to suit light conditions. Ranges from 0 (very dark) to 1023 (very bright).
{
digitalWrite(led, HIGH); // turns the light on
}
else
{
digitalWrite(led, LOW); // turns the light off
}
delay(1000);
}
Photos
Light sensor readings
ARDUINOAUTOMATICBOARDCODINGGUIDEHOWTOLEDLIGHTNIGHTPROGRAMMINGPROJECTSEN
SORTUTORIALUNOVIDEO
ARDUINO, VIDEO
This video tutorial has been designed for those just starting out with Arduino. For this
beginner project you will need an Arduino Unoboard (or compatible board), an LED of
any colour, a 470-Ohm resistor, two jumper wires, a breadboard, a male A-B USB
cable, and a computer (Mac/Windows) with the Arduino IDE softwareinstalled.
This project involves programming your Arduino Uno to make an LED light blink on
and off. To get started, watch the video below or click here to view it on YouTube.
Access the links below to get a copy of the code, printed instructions, schematic, and a
guide to resistors.
Video Player
00:00
17:06
Downloads:
Blinking LED printed instructions, code and schematic (pdf)
Blinking LED actual Arduino INO file (.INO file download)
The source code is also available here:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
*/
TAGS
code coding colour conditional csharpcss
2d 3d add adobe android animation app arraysc
css3 data design developmenteffect flash game guide html html5 illustratorimage input j
avascript maya mobile objects phonephp player programming source statementsstyle text tu
torial unity video webxamarin
Learn to code today!
RECENT POSTS
So you want to make a smart car? Don't know where to start? How about
learning with ICStation team.
Major Parameter:
1>.Motor parameter:
Power apply:6V-9V;
Reduction gear ratio:1:48;
2>.Selection L298N module driver motor,segregate form CPU.
3>.Three tracking modules,detection white and black line.Available with
fall prevention control.
4>.Infrared remote communication module,composition of remote control
system of smart car.
5>.Bluetooth wireless module,can match with mobile phone to control smart
car.
6>.Input voltage 7V-12V,can connect to different kinds of sensor.The more
sensors ,the more functions.
Components:
1>.stepper motor x4
2>.wheel x4
3>.motor fixed block x4
4>.100x213x5mm perspex sheet x1
5>.100x213x5mm perspex sheet x1
6>.L298N driver board x1
7>.Arduino uno 328 controller x1
8>.Arduino sensor shield V5 x1
9>.PTZ x1
10>.Servo motor x1
11>.Ultrasonic module x1
12>.Three channel tracking module x1
13>.Infrared receive sensor x1
14>.Transducer x1
15>.18650 battery holder x1
16>.18650 battery x2
17>.18650 battery charger x1
18>.Bluetooth module x1
19>.Dupont wire x30
20>.USB cable 1M x1
21>.Copper cylinder M3*20mm x3
22>.Copper cylinder M3*35mm x6
23>.Copper cylinder M3*20mm x3
24>.Copper cylinder M3*6mm x6
25>.M3 3mm screw and nut
Outline:
1.PTZ and servo motor Installation
2.Ultrasonic Installation
3.Car Chassis
4.Introduction of L298N motor driver module, Tracking module principle,
Ultrasonic obstacle avoidance intelligent car, Mobile phone bluetooth intelligent
car
ENA(yellow in picture):
1(5V/PWM):enable motor A
0(GND/PWM):disenable motor A
IN1 to 5V,IN2 to GND,motor A corotation IN1 to GND,IN2 to 5V,motor A
rollback ENB(yellow in picture):
1(5V/PWM):enable motor B
0(GND/PWM):disenable motor B
IN3 to 5V,IN4 to GND,motor A corotation
IN3 to GND,IN4 to 5V,motor A rollback
5V_EN(green in picture):
If use the jumper, chip 78 m05 provide power supply for modules
If do not use jumper, need to use 5v-pin & GND-pin provides power supply
module for modules
CSA/CSB(green in picture):
Current test pins for motor A/B,can series connection resistance
If do not use jumper, detection of the current
If use the jumper,not detect current
UR1-UR4(green in picture):
Choose whether to use pull-up resistor
For I/O port driver ability of microcontroller, can short circuit, using pull-up
resistor
If use the jumper, Do not use the pull-up resistor. If do not use jumper ,use the
pull-up resistor
NOTE:You can use other code to driver motor.
Let's learn the Arduino bluetooth remote control programmable intelligent car.
Through bluetooth control forward, backward, turn left, turn right, buttons,
computers and mobile phones, two kinds of control mode. (mobile phone
operating system support Android 2.3.7 above. The computer must bring their
own bluetooth)
When used for the first time to mobile phone with bluetooth car matching
(pairing for the first time after the later don't have in wireless location), first take
a look at the following steps:
1>>.Remember to open mobile phone bluetooth oh, open the software will
remind users open the bluetooth
2>>.Then the text as shown in figure tips, connect a bluetooth device, scan
matching bluetooth oh, otherwise not be able to connect to the car.
3>>.Match the car, the password is "1234" try it
Should you meet any problem, please feel free to contact us.
ICStation Team
Comments
ino Robots You Can Build for Less than $125READ MORE
To get started, we’ll attach the motors and the H bridge (the card that delivers power to
the motors) to the lower part of the chassis. First, attach the four metal brackets (they’re
rectangular, drilled blocks of metal) to each motor using two long bolts and two nuts.
You’ll need to make sure that they’re attached correctly, so check out the image below
to make sure that the side of the block with two drilled holes will face downward. Note
that the wires on each motor are pointing toward the center of the chassis.
Now each motor can be attached to the chassis by using two short bolts in the bottom of
each metal bracket. Here’s a view of the bottom of the chassis so you can see where the
bolts need to be:
The next step is to secure the H bridge (that’s the red board, in my kit) to the
chassis. You may want to wait until all of the wires are attached to the H bridge before
doing this, but that’s up to you (I found it to be easier). A quick note: my kit was
missing a number of fasteners, so I used electrical tape to secure the bridge. However,
you can see here where the bolts and nuts would have gone:
Now that the H bridge has been attached, you can start wiring up the power
supply. Because the six-AA battery holder comes with a DC adapter, you’ll need to
either cut off the end (which I did) or run jumper wires to the batteries themselves.
No matter how you decide to do it, you’ll run the positive wire to the port labelled
“VMS” and the negative wire to the one labelled “GND” on the bridge. Screw down the
fasteners and make sure they’re secure. Then, you’ll connect the motor wires. On both
sides, there’s a set of two ports; one is labelled “MOTORA” and the other
“MOTORB.” Both red wires on each side will go into the centermost green port, and
both black wires will go into the outermost. This picture should make it more clear:
I found that I had to strip some of the housing off of the motor wires to get this to
work. Now that you have the motors and the power supply all wired up, slide the wheels
onto the motor drive shafts, and attach the four copper shafts in the locations show in
the picture below (each copper shaft needs one small bolt). This robot is starting to take
shape!
Now, set that part of the chassis aside and grab the other one which will sit on top. The
next step is to attach the Arduino—again, I had to use electrical tape, but you should be
able to better secure yours with some bolts and nuts.
The next step requires the micro servo, the black crosspiece, the servo holder (which
consists of three black plastic pieces), and some small screws. Use one of the larger
sharp screws in the kit to attach the black crosspiece to the micro servo:
Then flip the servo upside down into the black plastic ring of the holder. Make sure that
the wires coming out of the servo are facing in the same direction as the longer part of
the holder (again, see the image below), and use four tiny screws to secure the crossbar
(there are four holes in the holder that align with the holes on the crossbar).
Here’s what it looks like after it’s attached:
Finally, take the other two pieces of the servo holder and snap them onto the servo
(there are grooves in the side pieces that match the plastic tab on the servo).
Now that the servo holder is complete, it can be mounted to the chassis.
Here’s where the bolts go:
It’s time to give our robot some eyes. Attach the ultrasonic sensor to the servo holder
using two zip ties.
If you’re working from the same kit as I am, you’ll have received an Arduino sensor
shield. We won’t be using it in this build, but you can pop it on top of the UNO now if
you want (as I have in the image below). Just align the pins on the bottom of the shield
with the I/O ports on the Arduino and press down to connect them. You don’t need it at
the moment, but shields can come in handy.The Top 4 Arduino Shields To
Superpower Your Projects The Top 4 Arduino Shields To Superpower Your
ProjectsYou’ve bought an Arduino starter kit, you’ve followed all the basic guides, but now
you’ve hit a stumbling block - you need more bits and bobs to realise your electronics
dream. Luckily, if you have...READ MORE
Whether you connect a sensor shield or not, you’ll now need four wires to connect the
ultrasonic sensor to the Arduino. There are four pins on the sensor, VCC, GND, TRIG,
and ECHO. Connect VCC to the 5V pin on the Arduino, GND to GND, and TRIG and
ECHO to I/O pins 12 and 13.
Now grab the lower part of the chassis, and connect six jumper wires to the I/O pins of
the H bridge (they’re marked ENA, IN1, IN2, IN3, IN4, and ENB). Take note of which
color wires are connected to which ports, as you’ll need to know later.
Now it’s time to start putting this thing together. Grab the upper part of the chassis and
set it on top of the copper shafts connected to the lower part, and pull the wires attached
to the H bridge through the hole in the center of the chassis. Connect the six wires to I/O
ports as follows:
The first thing we’ll do is test to make sure that the bridge and motors are hooked up
correctly. Here’s a quick sketch that will tell the bot to drive forward for half a second,
drive backward for half a second, then turn left and right:
That’s a lot of code for a simple test, but defining all of those functions makes it
easier to tweak later. (Big thanks to Billwaa for his blog post on using the H-
bridge for defining these functions.) If something went wrong, check all of your
connections and that the wires are connected to the correct pins. If everything
worked, it’s time to move onto the sensor test. To use the ultrasonic sensor,
you’ll want to download the NewPing library, and then use Sketch > Include
Library > Add . ZIP Library… to load the library.
Make sure that you see the include statement at the top of your sketch; if you don’t,
hit Sketch > Include Library > NewPing. Once you’ve done that, load up the
following sketch:
#include <NewPing.h>
//Tell the Arduino where the sensor is hooked up
NewPing sonar(12, 13);
long inches;
void setup() {
//Activate the serial monitor so you can see the output of the
sensor
Serial. begin (9600);
}
void loop() {
delay (50);
//Ping the sensor to determine distance in inches
inches = sonar. ping_in();
//Print the distance in inches to the serial monitor
Serial. print (inches);
Serial. print (" in.");
Serial. print ("\n");
}
view rawnewping_demo.ino hosted with ❤ by GitHub
Upload the sketch, and open up the serial monitor using Tools > Serial Monitor. You
should see a rapidly updating sequence of numbers. Hold your hand in front of the
sensor and see if that number changes. Move your hand in and out, and you should get a
measurement of how far away your hand is from the sensor.
If everything worked correctly, it’s time to put it all together and let this thing
run! Here’s the code for the robot now. As you can probably tell, this is basically the
two test sketches put together with an added if statement to control the robot’s
behavior. We’ve given it a very simple obstacle-avoidance behavior: if it detects
something less than four inches away, it will backup, turn left, and start moving
again. Here’s a video of the bot in action.
Let us know if you decide to build this robot or another one, and tell us how you decide
to customize its behavior or looks. If you have any questions about this robot, post
them in the comments below, and I’ll see if I can help!