Vous êtes sur la page 1sur 63

5/18/2017 arduino-info - RobotKitAbout

RobotKitAbout
print this page

ABOUT THE YOURDUINO BASIC ROBOT KIT Version 2


Detailed How-To pages start HERE:
Unpacking Your Robot Kit (Click HERE):
The OLDER Version 1 Info (Click HERE):
Educators' Teaching Materials (In Progress) Click HERE:

We have done much research and had many discussions with suppliers to offer a Robot kit with
this many parts and capabilities at the $45 price. We have also improved some things that were
problems with the earlier version, such as including a small screwdriver for the terminal strips
and screws, and a sturdy bracket for the Ultrasonic Sensor. The YourDuino Basic Robot Kit
Version 2 adds these new features:
Your Robot is Controlled by the YourDuino RoboRED Microcomputer board, compatible
with Arduino UNO with added features:

ALL I/O pins are brought to 3-pin (Ground-Voltage-Signal) connectors


Advanced Switch-mode power supply provides up to 2 Amps at 5V
Very direct wiring with supplied ribbon cables, easier motor wiring.
Sturdy Ultrasonic Sensor Bracket.
Improved thicker plastic baseplate.
A high quality screwdriver that fits screws and terminal blocks.

This kit has many small parts and detailed electrical connections. The builder needs good fine-
motor hand skills. This is not appropriate for most small children. We suggest 10-12 years old,
and some hands-on help from an older person is very valuable.

http://arduino-info.wikispaces.com/RobotKitAbout?f=print 1/2
5/18/2017 arduino-info - RobotKitAbout

The YourDuino Robot Kit Version 2 is available from YourDuino.com HERE:


PLEASE email questions, updates, comments to terry@yourduino.com

Educational Resources for integrating Robotics into the regular curriculum are
available HERE

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitAbout?f=print 2/2
5/18/2017 arduino-info - RobotKitMenu

RobotKitMenu
print this page

Get the Kit HERE:


Educational Resources for integrating Robotics into the regular
curriculum are available HERE
Step-By-Step Instructions: The YourDuino Basic Robot Kit,
Version 2 (Wait for Menu below..)

http://arduino-info.wikispaces.com/RobotKitMenu?f=print 1/2
5/18/2017 arduino-info - RobotKitMenu-2

RobotKitMenu­2
print this page
BACK to MENU

MICROCOMPUTER SOFTWARE:
Editing and trouble-shooting Software Sketches

SOFTWARE TIME & WRITING ARDUINO SKETCHES


You have the Arduino IDE software installed and you have run and edited BLINK,
right? You're getting there!
Now let's get used to writing Arduino Software, and then we'll come back and start
connecting your Robot kit parts and making more interesting things. We will give you
software examples to test each part of the Robot kit.
I know all this and I want to just Build The Robot! (SKIP AHEAD)
On your desktop you should now have the Arduino ICON like this:
Click on it, if you haven't already, and you should see the "Arduino IDE
Window" pop up like this:

You'll use this IDE (Integrated Development Environment) to make Software


VISIBLE! With it you will develop your own software to make Arduino into what you
want it to be.

FIRST, YOU MUST SET THE CORRECT BOARD TYPE AND SERIAL
PORT:
In the Arduino IDE top menu click <Tools> and then <Board>. You will see
a drop-down menu that looks like this (left).
NOTE: For the YourDuino RoboRED in all current kits, pick "Arduino UNO". For
the older YourDuinoRobo1 click Arduino Duemilanove. (Same for PC and MAC)
SERIAL PORT: Now click <Tools> and then <Serial Port>. On the PC There will usually
be only one choice. But you may have COM1 and then some higher number which is

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 1/7
5/18/2017 arduino-info - RobotKitMenu-2

Arduino.

On the MAC, see the example on the


right. Pick the entry that has both "tty"
and "usbserial" in it.

OK, you're ready to upload software


sketches to your YourDuino or
Arduino!

SKETCHES:
The visible text of an Arduino
software program is
called a SKETCH. But the Sketch becomes alive when you upload it to your Arduino.
Let's walk through

Editing a Sketch and Verifying it and


Uploading it:

Click on FILE and then move your


mouse (slowly.. It's Fussy!) over
EXAMPLES to BASICS and then to
BLINK so it looks like this (On the right):
And CLICK. There are lots of examples that come with the free Arduino software
system, and we will look at some of them later, as well as make our own very soon.
A new IDE window should pop up and look like this:

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 2/7
5/18/2017 arduino-info - RobotKitMenu-2

Wow.. A bunch of new stuff.

Let's slow down and "Watch


Closely Now"!

Notice that a lot of the text is


GRAY. All of that is just
"Comments" for you to read to
help understand the Sketch.
When you write software, you
should also use "Comments" to
explain to others what you are
doing. (Arduino itself totally
ignores these comments).

Now, let's go through Editing


software, Verifying it, and Uploading it to see Arduino DO it. We will use the
YourDuino version of Blink: YourDuinoStarter_Blink . Click on the link to see it's page.
It will open in a separate window, so you can keep going on this page also.

Now, highlight all the code (in the gray area) , do <Ctrl>C to Copy.
In the IDE, click the New button to get a blank page and do <ctrl>V to Paste it in.

NOTE: Newer versions of the IDE may fill in the New page with an example sketch.
Delete that before you paste your new sketch in..

Now, click Verify to make sure it's OK.

NOTE Again: Newer versions of the IDE may pop you to a "Save" option. Just type in
a name like "myblink" and click Save.
You should see "Compiling Sketch" and then "Compiling Done". Now look at the sketch
in detail. Take some time to read it slowly.

STRUCTURE OF ARDUINO SOFTWARE:


Every Arduino Software Sketch has two main parts:

SETUP - Runs Once at the beginning


LOOP - Runs over and over again, forever

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 3/7
5/18/2017 arduino-info - RobotKitMenu-2

You will read a LOT of program "Code" that other people wrote, in the future. You
HAVE to "Watch Closely Now" and really see the details. Read the
YourDuinoStarter_Blink example through carefully, a couple of times. Note the
colored special words that are Instructions. These are unique words that tell Arduino
what to do. They have to be spelled perfectly!

What SETUP does: Tells Arduino about things that need to be done once. Arduino
Digital Pins can be either INPUT or OUTPUT. You have to tell Arduino when a Pin will
be used as an OUTPUT. In this example, there is one line that tells Arduino that Pin
13 must be an OUTPUT.

Note the COLOR of the lettering. The Arduino IDE changes the color of words as it
recognizes them as special instructions. Let's mess with them:

pinMode: Note that when Instructions are two words run together, like pinMode, the
beginning of the SECOND word is Capitalized. Change the Capital "M" to "m". Note

the color changes to black. Hmmm. Click the VERIFY button.

You will get an ERROR message:

Fussy, Fussy, Fussy! Yep, every letter has to be correct and also correct upper or
lower case.

Change it back. Check the color. Click Verify again. OK??

What LOOP does: Loop contains all the active parts of your Sketch that continue to
run after SETUP is finished. It will run over and over again, forever, or until you stop
it or power down.

What does VERIFY do??

A LOT! More details later, but Verify is a program in your main computer that goes
through every Instruction in your Sketch (Ignoring "Comments") and checks it against
the list of valid Instructions, and checks that the structure and sequence of the
statements in the Sketch are correct. Fussy, Fussy! If they're OK, then it "compiles"
http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 4/7
5/18/2017 arduino-info - RobotKitMenu-2

or "translates" the sketch into the machine code that Arduino actually runs on. It
saves that 'ready-to-run' code for you to Upload to Arduino and run. Other systems
would call this process "Make" or "Compile". Arduino refers to it as "Build" and if you
want the gory details (Click Here) .

What does UPLOAD do??

First, Upload runs Verify to check and compile your program. Then it communicates to
your Arduino over the USB connection, resets the Arduino chip, and talks to software
already on Arduino (called the BOOTLOADER(W) ) to load your new program into the
Arduino's memory. Then it restarts Arduino and your program runs it's SETUP
section and then repeats the LOOP section.
[NOTE: The (W) Means this is a Wikipedia link.]

Start Making Changes:

Ok, let's make a few changes to the YourDuinoStarter_Blink program:

The LOOP section of your program does all the instructions in the section, and then
"loops" back to the top and starts it again, over and over.

NOTE: the "Brackets" { and }

Notice that the beginning and end of the section is "inside brackets". You will see
many sections of bigger programs that are grouped by these "brackets".

Now, let's look in detail at the instructions:


Instruction: digitalWrite

This instruction sets an OUTPUT PIN to either HIGH (connects it to +5 V) or LOW


(Connects it to GND). Lots of new words will be thrown about here!

Thing To Remember: HIGH = 1 = ON = 5 Volts and LOW = 0 = OFF = 0.0 Volts

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 5/7
5/18/2017 arduino-info - RobotKitMenu-2

So, the first line in LOOP sets PIN 13 to HIGH. This means Pin 13 is connected to +5
Volts, and current flows through a resistor and LED that are already connected to pin
13 on the Arduino board. The LED lights up.

Instruction: delay

The delay instruction just waits for a period of time. The VALUE used with delay is in
Milliseconds (1/1000 second). So delay(1000); waits for 1000/1000 seconds (1 second).
We'll change that soon.

NOTE: the ";" (Semi-Colon)

Notice that every instruction is followed by the character " ; " which is like a period
that tells the end of a sentence. Run-on sentences will make you stay after school to
fix your error messages!

Change the delay so that the LED blinks differently:

Time to mess about and try some things! Maybe we'll break it. Then we'll fix it..

Suggestion: Save your own version of BLINK so you can always go back to the original
one. Go to File and Save As and call it something like MyBlink. This will go in your
SKETCHBOOK where you'll save your own programs.

Now go change the VALUE in a delay statement to change the way the LED blinks.
Think about the 4 instructions in LOOP. What's happening??
Turn the LED on. Wait and look at the LED.
Turn the LED off. Wait and look at the dark.
So, let's change the ON time to be short. Maybe 50 Milliseconds. That's 1/20 of a
second. Change the first delay instruction to be delay(50);

Then try 10 milliseconds. The LED is only on 1/100 of the time. Can you still see it
blink? How about 1 millisecond?

Each time you make a change, click Upload which will first Verify and Compile
your program and then send it to Arduino. Notice that each time you do this the LEDS

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 6/7
5/18/2017 arduino-info - RobotKitMenu-2

on the Arduino board that are marked "Tx" (Transmit) and "Rx" (receive) flash as
your main computer communicates with your Arduino.

Try out some combinations of ON and OFF delay() times. Like ON 1000 and OFF 50.

Try making both ON and OFF times shorter and shorter. If you make the ON and
OFF times short enough your eye will no longer see blinking, because of "Persistence
of Vision"(W) which happens when there are more than about 25 blinks per second.
So, hmmm.... if you make the LED be ON for 1/50 of a second and OFF for 1/50 of a
second that should do it. So try 1000/50= 20 Milliseconds. Put 20 for both the ON
and OFF times. What do you see?? How about 10 Milliseconds each? Depending on
your personal eye's physiology, at some speed you will not see any more blinks. Young
people can usually see faster blinks than old codgers like me :-)

All right. You are hacking code. You're the Programmer! You can save any of the
sketches for use later on. Go to File>Sketchbook and you'll see them.

Next, we'll start hooking up the Parts in your Robot Kit! And we'll give you example
Software Sketches for each one of them.
Go To the Next Section: Physical Computing Concepts
OR back to the Main Menu:

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 

Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitMenu-2?f=print 7/7
5/18/2017 arduino-info - RobotKitMenu-3

RobotKitMenu­3
print this page
BACK to MENU

PHYSICAL COMPUTING CONCEPTS:

Physical Computing [W] connects to the real world beyond your keyboard, mouse and
display. It connects to many different things, makes decisions and makes things
happen.
I want to just Build The Robot!(SKIP AHEAD)
Arduino [W] is a tool for making computers that can sense and control more of
the physical world than your desktop computer. Arduino is intended for use by both
non-technical people with no previous programming experience and seasoned pros who
love to tinker.
We'll look at it this way:

http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 1/7
5/18/2017 arduino-info - RobotKitMenu-3

OK, let's look at that closely. There are 3 main parts to any "Intelligent System" that
connects to the real world:
1. SENSORS: That 'feel the world' and give us data about Temperature,
Pressure, Location, Light, Sound, Time, Position, Speed and much more. They
are INPUTS to the system.
2. DECISION MAKING: After checking what is being Sensed, decisions are made
to decide what to do about the situation. Like: Too Cold: Turn on the Heat, Too
Close: Back Up, etc. This is Software Sketch CODE.
3. ACTUATORS: Devices that can take actions like turn other things on and off,
Light LEDs, make sounds, control motors etc. They are OUTPUTS from the
system.

You will be building a Robot that does these things. The Physical Computing devices
you will have on your robot are:

SENSOR: Ultrasonic Distance Sensor


ACTUATORS: ServoMotor and DC Motors with Motor Driver, and maybe
Buzzer.

The software you will use and perhaps later change does these things, over and over
again:
Check SENSORS
Make DECISIONS
Take ACTIONS
Every automatic system, from your home heating system to the Mars Rovers, does
these same things. If you can make a simple thing work, you can start to make more
and more interesting things, including things that no one else has made.

Some simpler things just follow a set of instructions to take Actions (they don't have
Sensors), like the BLINK program. You will also be able to decide on a sequence of
instructions that your Robot will use to do a set of Moves that you decide.

Physical World Connections:


You will be putting together wires and connections, batteries, motors, servomotor,
distance sensor etc. So this is Electricity and Electronics (AKA Detailed Electricity).

Making things with Electronics and MicroComputers is different than Woodworking


or Metalworking. There are a couple of little problems: Uh Oh!
http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 2/7
5/18/2017 arduino-info - RobotKitMenu-3

Electricity is INVISIBLE !
AND, Software is INVISIBLE !

Not to worry! We will show you the ways to make these powerful tools Visible so you
can use them. You've already seen the Arduino IDE which makes Software Visible. But
we need to think about Wires and Circuits and Components like resistors and
capacitors and stuff.

Again, "Watch Closely Now" (You may like the Kris Kristofferson version HERE)

RealityCheck: Most electronics stuff runs on 5 Volts Direct Current. A USB cable
puts out .. 5 Volts. Arduino runs on 5 Volts (let's abbreviate that to "5V"). Oh: Some
stuff these days runs on 3.3V.
Let's look at the graphic below:
Top Red Rail: This is the 5V that runs Arduino and most attached devices.
Bottom Blue Rail: This is the Ground connection for Arduino and most attached
devices.
Everything Else: (Almost) is connected in between +5V and Ground.

OK, Time to Learn some Nerdy Names!


PINS...
BITS...
ONES and ZEROS...
HIGH and LOW...
... YOU'LL KNOW!!

OK, Fans, it's ELECTRICITY Time ! And, the weird thing about electricity is it's
INVISIBLE! So we need to learn how to make it visible to us. Here's the way we think
about the Electrical Reality of Arduino-based systems:

http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 3/7
5/18/2017 arduino-info - RobotKitMenu-3

These are terms you will hear many times in Arduino and Electronics:
HIGH = 1 = ON = 5 Volts
LOW = 0 = OFF = 0.0 Volts
PINS:
Arduino has many electrical connections coming from the Atmel chip inside the plastic
package to metal PINS or metal tabs. We will use the PINS to electrically connect to
Input and Output Devices.

This is the reality point where "ON" and "HIGH" means really that Arduino is putting
out 5V on an output pin. And "OFF" or "LOW" means really that Arduino is putting out
0V on an output pin.

DIAGRAMS:
Often an actual circuit (like the YourDuino and Breadboard hookup) gets to be a
confusing bunch of wires and components going in all directions. To keep our heads
together, we draw Circuit Diagrams to show what we're trying to do. Notice the
Symbols used in the diagram above for things like: SWITCH, RESISTOR, LED. And
there are Labels on connections, like GND, INPUT, OUTPUT, ARDUINO etc.

There's our theme music again: "Watch Closely Now"... (You may like the Kris
Kristofferson version HERE)

http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 4/7
5/18/2017 arduino-info - RobotKitMenu-3

In the diagram above, we have added a dose of reality: Arduino is powered (usually) by
+5.0 Volts of DC (Direct Current).

We show the +5.0 Volts connected HIGH on the top. Look closely at Your Arduino or
YourDuino RoboRED board. Find the PIN marked "5V". that's the one +5.0V power is
connected to. Where does it come from?? (To start, from the USB cable from your
computer to Arduino.)

We show GND (Ground) connected LOW down on the bottom of the diagram. Look at
Your board (or a photo).. find the PIN marked "GND". ("Watch Closely Now" - There
are actually 3 "GND" PINS).

RAILS !

As we mentioned earlier, the parallel lines of +5V HIGH on the diagram, and GND -
LOW on the diagram are often called "RAILS". Kind of like railroad RAILS across the
top and bottom. Almost everything that happens on Arduino is between the +5V HIGH
RAIL and the GND-LOW (0.0V) RAIL.

DIGITAL "SIGNALS":

When a PIN (or wire or connection) changes from 0 to 1, or 1 to 0, we say it is a


SIGNAL. Kind of like someone raising up a flag or lowering it.

OUTPUT SIGNALS: An LED or Buzzer connected to to an Arduino OUTPUT can


"signal" you that something has happened.

INPUT SIGNALS: If you push a button that changes an INPUT, you "signal" Arduino
that something should be done.

BITS !

Oh, um.. what's a BIT anyway? It is a Binary InTeger which is a number which has
only two possible values: 0 and 1. Each Arduino Input or Output PIN is one BIT inside
Arduino. (A GROUP of 8 BITS is called a BYTE. Bet you knew that!).

DIAGRAMS, Again:
http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 5/7
5/18/2017 arduino-info - RobotKitMenu-3

OK, Look again at the diagram above:

The pushbutton switch causes the INPUT to change from LOW to HIGH, which
is a "signal" to Yourduino.
Yourduino can change the OUTPUT from LOW to HIGH, causing electricity to
flow through the LED, light it up and "signal" you.

OK, another one of those tekkie words:


DIGITAL: This means Arduino will use these Pins only as ON or OFF.

You will hear "Digital" things described three or four ways: but

"0" and "OFF" and "LOW" and Zero Volts mean the same thing.
"1" and "ON" and "HIGH" and +5 Volts mean the same thing.

"DIGITAL" values
0 1
OFF ON
LOW HIGH
0.0 Volts(GND) 5.0 Volts(5V)

Let's listen to the way these terms are used by people talking about this
Microcomputer Stuff. You'll hear stuff like:
"When SOFTWARE inside the Arduino sets an OUTPUT PIN to a "1" it is "ON"
and "HIGH" . Arduino connects the OUTPUT PIN to the HIGH RAIL which is
5.0V (5V)."
"When SOFTWARE inside the Arduino sets an OUTPUT PIN to a "0" it is
"OFF" and "LOW". Arduino connects the OUTPUT PIN to the LOW RAIL which
is 0.0V (GND)."

Sorry for the multiple names for the same things, but those names are widely used,
and it's time for you to know them...

PINS, BITS, ONES and ZEROS, HIGH and LOW... (Make Sense??)

http://arduino-info.wikispaces.com/RobotKitMenu-3?f=print 6/7
5/18/2017 arduino-info - Robotkitmenu-4

Robotkitmenu­4
print this page
BACK to MENU

CONTROLLING MOTION, SENSING DISTANCE:


NOTE about POWER:
Many newer computers and most laptops and tablets limit the power available on the USB cable. This robot will
usually need to run from the external Battery Case with 6 AA batteries. So in some cases you will have to have
the battery connected to use the USB to upload sketches.
I want to just Build The Robot! (SKIP AHEAD)
In this section you'll learn about the Servo Motor used in the Robot, connect it and make it move. Then you'll
learn about the Ultrasonic Distance Sensor, connect it and test it. You'll be ready to add those together to the
Robot Base later.

Servo:

Servos are small box-shaped electro-mechanical devices that contain a DC


motor, electronics to control the motor from a signal, a gear system to
produce slow/strong output to a shaft, and a position feedback
potentiometer. They are Positional devices: they move an output arm to
different positions as commanded by a signal. They are not (usually)
continuous-rotation devices. There are a variety of sizes and weights, of
similar construction. They are widely used in Model cars and airplanes, and
can cost as little as $3.50 More details HERE.

Servos usually come with several different arms you can attach depending
on your design. Usually you use a Servo to position something, like steering direction, arm/leg movement etc. In
this Robot the servo is used to point the Ultrasonic Distance Sensor in different directions, like a person
"looking around".

For most servos the position angle of the servo is controlled by the length of the pulse in milliseconds (usually
between about 1.00-2.00ms). 1.50ms is usually Center.

Open the small bag with servo arms and screws. Attach the long white arm to
the top of the servo as shown in the photo. Orient the servo with the wire to
the right.

Lightly push the white servo arm onto the servo shaft
Carefully turn the arm counter-clockwise until it stops
Remove the arm and reposition it so that it is oriented at right angles
(as shown). It is now pointing "Left". Do not put the screw in yet.
OK, now let's make it work. All RC servos have a three wire connector. One
wire supplies positive DC voltage – usually 5 to 6 volts. The second wire is for
ground, and the third wire is the signal wire. The Arduino “talks” to the servo through this wire by means of a
simple on/off pulsed signal. They can plug directly into the 3-pin connectors on a YourDuino RoboRED or a
SensorShield.

CONNECTIONS:
http://arduino-info.wikispaces.com/Robotkitmenu-4?f=print 1/5
5/18/2017 arduino-info - Robotkitmenu-4

wire colors may vary!


Servo Black or Brown to Ground
Servo Red or Orange (Center wire) to +5V
Servo White or Yellow to Signal (Pin 11)
You should have your RoboRED plugged in with USB, and have run BLINK successfully.
NOTE: The RoboRED also has a switch labelled 3V3 5V that can change the operating voltage.
Make SURE it is in the 5V position.

SKETCH TO TEST SERVO MOTION:


The SERVO library is part of the regular Arduino software installation. We will use a sketch similar to the
example called "Sweep" which will move the servo through its range of movement.

Plug in the USB Cable to be ready to upload this software sketch. Do NOT plug the servo in yet; you'll need to
use the battery case power.

HOW TO COPY/PASTE SOFTWARE SKETCHES:


You will Copy and Paste the Software Sketches below to test and run your robot. Here's how:

On this page, position your mouse cursor just before the beginning of a sketch, then hold the left button
down and move slowly down over the sketch and over the end " //*( THE END )*"
Press <Ctrl> C to COPY. (<Command> C on MAC)
Switch to the Arduino IDE software.
Click on File > New (You will get a new window)
Use your mouse cursor and left button to highlight the small example shown there. Leave it highlighted
so you will replace it.
PASTE the sketch by pressing <Ctrl> V (<Command> V on MAC)
Check that the beginning and end of the sketch are right.
Click Verify on the IDE and make sure there are no errors. If problems, see "About Libraries" Here.

Click Upload on the IDE with your USB cable connected and the right Port selected. It should say
"Compiling Sketch" and then "Uploading Sketch" and then "Upload Complete". You should see the Tx and
Rx LEDs on the RoboRed board blink for a second or two during the actual upload..

Now Unplug the RoboRED (which you should do whenever making connections). and then plug the Servo onto the
3-pin connector at I/O Pin 11. (see photo above). Easier to count Down: 13-12-11. The brown wire should plug on
the G (ground) (Blue) pin. Now plug the battery case with batteries into the RoboRED external power
connector. The servo should "look around" back and forth. It will keep going until you unplug the YourDuino or
upload a different Sketch. (When you want to stop the servo motion unplug it and just upload Blink again.)

/* YourDuino Basic Robot Kit V2: Test Servo movement


- WHAT IT DOES: Tests the servo by commanding it to go to several different directions
to "Look Around". You may want to reposition the servo arm on the servo to get the
positions to look around correctly.
- SEE the comments after "//" on each line below
- CONNECTIONS:
-
-
- V2.13 05/15/2017 Limit extreme positions
Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/


#include <Servo.h>

/*-----( Declare Constants and Pin Numbers )-----*/

http://arduino-info.wikispaces.com/Robotkitmenu-4?f=print 2/5
5/18/2017 arduino-info - Robotkitmenu-4
#define SERVO_PIN 11 // Servo plugs into Pin 11

/*-----( Declare objects )-----*/


Servo myservo; // create servo object to control a servo

/*-----( Declare Variables )-----*/


int pos; // variable to store the servo position

void setup() /****** SETUP: RUNS ONCE ******/


{
myservo.attach(SERVO_PIN); // attaches the servo on pin 11 to the servo object

}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/


{
for(pos = 20; pos < 160; pos += 28) // goes from 20 degrees to 160 degrees
{ // in steps of 30 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1000); // Wait 1000ms between pings
}

for(pos = 160; pos>=20; pos -= 28) // goes from 160 degrees to 20 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1000);
}

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/


//NONE

//*********( THE END )***********

Ultrasonic Distance Sensor:


(Unplug the servo for now) Get the plastic bracket that will hold the Ultrasonic Sensor(right):
Attach 4 wires from the rainbow cable, (use Red, Orange,
Yellow and Green) to the base of the ultrasonic sensor (As
shown in the closeup photo of the back of the Ultrasonic
Sensor at left <-). Cut 3 pieces of the thin blue wire about 2
Inches (5cm) long. Place the Ultrasonic Sensor into the blue
bracket from the back (bottom bracket side), and secure it
with two pieces of the blue wire. Use another piece of wire to
secure the cable to the bracket through the two vertical
cutouts.
ConnectionsUltrasonic-200.jpg

Connect the cable from the Ultrasonic Sensor to the RoboRED as shown at right. Use the
3-pin connector for pin 2. Numbers start at D0, D1 D2. Green to pin 2 GND (blue row),
Red to Pin 2 Voltage (red row), Orange to Pin 2 Signal (yellow row), and finally Yellow to
pin 3 Signal (yellow row). This connects the sensor Ground, Voltage, Trigger and Echo wires.

We will use a library called NewPing written by Tim Eckel to run the Ultrasonic Sensor. You will need to
download and install the NewPing library. You can find the NewPing library zip file HERE and download it.
Remember where you saved it.
http://arduino-info.wikispaces.com/Robotkitmenu-4?f=print 3/5
5/18/2017 arduino-info - Robotkitmenu-4

Then install the new library as shown HERE:.

Then copy, paste, upload and run the test sketch below.

Note: The sketch will send the distance measurements it is making to the "Serial Monitor," which is a window
you can start by clicking on the "serial monitor" icon at the upper right of the IDE window. Put your hand or
other object in front of the Ultrasonic sensor and move it farther and closer and you should see the distance
displayed on the Serial Monitor.

/* YourDuino Basic Robot Kit V2: Ultrasonic Sensor Test


- WHAT IT DOES
- Tests the operation of the Ultrasonic Sensor
- SEE the comments after "//" on each line below
- CONNECTIONS: (suggest cable with 4 wires: Red,Orange,Yellow,Green )
- Sensor Vcc to RoboRED Vcc (Red)
- Sensor Ground to RoboRED Gnd (Green)
- Sensor Trig to RoboRed pin 2 (Orange)
- Sensor Echo to RoboRED pin 3 (Yellow)
- V2.10 11/10/2014
Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/


#include <NewPing.h>

/*-----( Declare Constants and Pin Numbers )-----*/


#define TRIGGER_PIN 2 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 3 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

/*-----( Declare objects )-----*/


NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
/*-----( Declare Variables )-----*/
unsigned int uS;

void setup() /****** SETUP: RUNS ONCE ******/


{
Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.

}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/


{
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println("cm");

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/


//NONE

//*********( THE END )***********

Attach the Ultrasonic Sensor and Bracket on top of the Servo arm:
Push the white servo arm firmly in place. Carefully rotate it fully counterclockwise as shown above. Align
the blue bracket for the Ultrasonic Sensor on top of the servo arm, the front of the bracket should be
parallel to the white servo arm .
Switch your screwdriver to "Phillips" end. Use one of the 2 longer small screws in the package to
secure the bracket, the white arm and the servo shaft. Put the screw down through the center hole of
http://arduino-info.wikispaces.com/Robotkitmenu-4?f=print 4/5
5/18/2017 arduino-info - Robotkitmenu-4

the bracket base and into the center hole in the servo shaft. Point the
ultrasonic sensor to the left (away from the servo wires).
Tighten the screw just enough that the bracket stays aligned with the
white arm.

OK! If that's all working OK, you'll go ahead now to build the Robot Base with
wheels, motors etc. and then add the RoboRED and the Servo/Sensor Shield
assembly you just built.
o To the Next Section: Build The Robot Base
OR back to the Main Menu:

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/Robotkitmenu-4?f=print 5/5
5/18/2017 arduino-info - RobotKitMenu-5

RobotKitMenu­5
print this page
BACK to MENU

BUILDING THE ROBOT BASE:


At this point, you should have tested the Servo and Ultrasonic Sensor and have them assembled
with the bracket. They're probably still plugged into the RoboRED; you can move all that onto
the Robot Base after it is assembled.

Before you start to build your Robot Base, become familiar with all the parts and what they are
called. Check that you have all the components in the kit. There is another page that shows all
the parts and explains them. If you didn't do so at the beginning, go check that page (HERE) and
then return. NOTE: The 4-position battery case and printed sheet that may be inside your parts
package will not be used!
HINT: Use an egg carton or small dish when you open the small parts ziplock bag. Organize the
parts. (Many of the small bolts and nuts will not be used).

START BUILDING HERE:

ROBOT CHASSIS, WHEELS and DC MOTORS


1. Robot Chassis: Laser-cut clear plastic. This has a stick-on paper
covering, and this is a good time to remove it if you want the
clear plastic to be shown. (You want at least one side clear for
the Velcro to adhere well). This is why we have fingernails :-)
2. Wheels (2). The wheels have a hole in the center with two flat
sections. Make sure you line this up with the motor shafts later
when you attach them.
3. DC Gear Reduction Motors (2). These have 2 wires attached.
Later, when you assemble them to the chassis, make sure the
wires go towards the center of the robot.

Assembling the Robot Base Chassis and Attaching the Parts


First, you will attach these parts to the robot chassis and then connect them electrically:

1. Motor Driver Board


2. DC Motors
3. Yourduino RoboRED
4. ServoMotor and Ultrasonic Distance Sensor on Bracket
5. Battery Case
http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 1/13
5/18/2017 arduino-info - RobotKitMenu-5

CHASSIS:

Notes on Optional Power Switch:


We do not show how to wire the optional power switch; it would require soldering which
the kit avoids. If you plan to use the power switch later, line it up with the rectangular
hole in the center of the chassis and PUSH it down into position. This may take a strong
person with strong fingers, or you may have to file the switch case to make it fit! Many
people simply plug and unplug the battery connector to turn the robot on and off. The
switch may have a red dot showing the ON position. We suggest you point it toward the
front (wide end) of the robot.

Originally we supplied a chassis with predrilled boards and "TOP" marked. Younger (and
other!) people had difficulty with the small hardware used to attach the RoboRED and
Motor Driver. As of September 2015 we supply Velcro-type adhesive strips which are
easier to handle and allow things to be removed. It is also better for the battery case
which is often removed.
See the photo above for suggested locations for the Velcro sections. We suggest you put
the HOOK part on the chassis and the LOOP (fuzzy fabric) part on the RoboRED, Motor
Driver, Servo and especially the Battery Case so that it won't snag things when it is not
attached..
http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 2/13
5/18/2017 arduino-info - RobotKitMenu-5

IF you want to drill holes in the chassis yourself, a .JPG file that will give you an
accurate layout if you print it at 300DPI is available HERE. The holes should be
1/8" (USA) or 4mm (Metric).
NOTE: Probably better to mount motors before attaching other parts like Motor
Driver etc.
Locate the 4 Motor Mounts. Use 2 at a time to attach each motor to the chassis.

On the underside of the Robot Chassis, place the motors with their wires facing
towards the center of the chassis and towards the back.. close to the edge of the
RoboRED locatio.. (NOTE: Velcro is now used for the motor driver and RoboRED, not
the screws in this photo!)

(<- See Photo)

1 bracket is inserted up through a center slot and the 2nd bracket goes in a slot on
the outer edge of the chassis.

Turn the chassis over and insert the long machine screws through the outer
brackets, through the holes in the motor, and through the inner bracket. HINT:
Hold the nuts flat against the motor, with the screws extending out. Rotate the
screws until they start onto the nuts. Then spin the nuts in place lightly.

(See Photo Below)

Attach two nuts and tighten just snug but not too tight. The plastic is not real
strong. Hold the lower nut in position as shown and then start and tighten the
screw. (Right)

Install the second motor on the other side.

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 3/13
5/18/2017 arduino-info - RobotKitMenu-5

Route the wires up through the two


larger round holes closest to the
rectangular cutout in the center of the
chassis. (NOTE: Velcro is now used for
the motor driver and RoboRED, not the
screws in these photos!)

CASTER WHEEL

At the back of the chassis, check out the position of the holes by placing the caster
wheel on the bottom of the chassis, to see which 4 holes line up with the holes on
the caster wheel.

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 4/13
5/18/2017 arduino-info - RobotKitMenu-5

Now, attach the 4 metal 'standoffs' by putting 4,


8mm long machine screws from the top of the
chassis, through the 4 holes and into one end of
the standoffs. Hold the standoffs and tighten the
screws with the small Phillips screwdriver.

Line the caster wheel holes up with the 4


standoffs and attach it with the 4 small
screws that have large flat heads.

(Photo Below) Here is the Robot Chassis with the parts


attached (Now we supply, Velcro, not screws). The motor wires
are routed through the holes. We suggest you wait until later to attach the wheels. It's
easier to test the wiring and software when the robot can't try to escape :-)

RoboRED:
Attach
the
RoboRED
to the
chassis
using
Velcro
(See
photo)
NOTE:

RecentRoboREDs have a small black jumper which should already be in the 5V position. If
you don;'t have that jumper, find the small silver colored switch near the USB connector,
labeled 3V3 and 5V. Make sure this switch is pushed to the 5V position. If you have the
Servo and Ultrasonic wires connected, put them off to the side temporarily.

Connecting the wires from the RoboRED to the components


http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 5/13
5/18/2017 arduino-info - RobotKitMenu-5

Motor Driver Board


The Motor Driver board looks like this: (See Photo)
The motor wires will connect to the blue terminal blocks on the
left and right. The RoboRED control wires will connect to the
small black terminal strip in the lower center, and the motor
power will connect to the bottom blue terminal strip at "VCC"
and "GND".
Important note: As received,
there are two jumper blocks
on the motor driver connected
to the ENA and ENB Pins
which must be removed. You
can pull them straight up off
the pins using tweezers or
your finger nails. (<- See Photo )
Now you are going to use wires from the Rainbow cable to connect the RoboRed pins to the
corresponding pins on the Motor Driver Board. The connections and corresponding wire colors
are shown in the following table. We are using different colored wires to make the wiring easier
to understand. This may seem complicated, but if you follow the steps below, it will all come
together!

NOTE! The connections shown below are correct. SOME of the photos show White and Black
wires reversed. THIS is right. (Sorry!)

1. Strip off a section from your "Rainbow" flat cable with 6 wires, with colors Green through
Black. Push one end of this cable onto the RoboRED pins (Longer Yellow strip) 5-6-7-8-9-10 as
shown in the photo. (These numbers are not printed on the board. Notice the section starts at
the 7th position from the right.) They must be on the Yellow (signal) pins, not the Red (Voltage)
or Blue (Ground) pins.

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 6/13
5/18/2017 arduino-info - RobotKitMenu-5

2. Connect the other end of the cable you made


to the Motor Driver, with each colored wire
connecting to the corresponding pin on the
motor driver board, as shown in the table
above. (See photos ->)

ERROR! WHITE and BLACK wires are reversed!! Use Table.

3. Now, attach the Red and Black wires from the motors to the Motor
Driver Board. Looking at the 2 smaller blue terminal blocks on the Motor
Driver Board, the Black wire is attached on the left and the Red wire
is attached on the right. (See photo ->) !! IGNORE PHOTOS THAT
SHOW THE WIRES REVERSED!!

Use the flat end of the screwdriver to loosen the tiny screws in the
terminal block, up to the level of the top of the blue plastic. (They may fall
out if you go any higher.) You may want to insert a toothpick or other small
round object into the terminal strip to enlarge the space a bit to allow the
wire to go into place easily. Then tighten the screws moderately. Pull on
the wires a little to be sure they are secure. Now turn the chassis around
and attach the wires on the other side!

4. Now you will wire power from the RoboRED "Vin" and "Gnd" pins to the motor driver. (This will
connect the battery pack to the motor driver board later when you plug it in). Strip off a section
http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 7/13
5/18/2017 arduino-info - RobotKitMenu-5

from your ribbon cable with just 2 wires: Red and Brown wires. You will need to remove the black
plastic coverings that are over the metal terminals on one end of your cable. Remove the plastic
parts as shown in the photos below.

Look closely at the wire ends. There is a very small plastic "latch" that you can pry up with a
pushpin or other small sharp object (we use a pin of the "Pin Strip" in the photo). When the latch
is bent up, the plastic end can be pulled off leaving the metal connector exposed. Loosen the
screws on the Motor Driver Board "VCC" and "GND" terminal strip locations, (on the 3 terminal
strip), up to the top of the blue plastic. Again, you may want to insert a toothpick or other small
round object into the terminal strip to enlarge the space a bit to allow the wire to go into place
easily.

Insert the metal ends of your cable: Red to VCC, and Brown to GND. You may have to push a bit
to get them in place. Then tighten the screws. Pull on the wires a little to be sure they are
secure. (See photo below.)

5. For the other end of the


cable, find the "Pin Strip" and
break off a small section of 3
or 4 pins wide (they will stay in
place better than 2 pins but
BLACK and WHITE wires CORRECT!
some are unused). Plug that
into the Yellow terminal strip on the RoboRED that is closest to the caster wheel. Notice the
pins labelled "Vin" and "GND".You need to plug the Red wire into the "Vin" pin (on the end of the
yellow strip), and the Brown wire to the "GND" pin which is the next one over. Use the pin strips
to make the cable end connect to the yellow strip sockets.
NOTE: Later when you connect the Battery pack with 6 AA batteries to the Yourduino RoboRED
external power connector, that power will connect to the VIN and GND to power the motors.

Servo and Ultrasonic Sensor:

If you followed through all the previous pages you have gotten the Servo and Ultrasonic Sensor
wired to the RoboRED and working. Now, attach the Servo by placing it in the rectangular hole
from the bottom, and securing it with two special screws in your parts. (Photo on right) Make
sure the servo wire is pointing towards the right side of the robot chassis. Now connect the
http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 8/13
5/18/2017 arduino-info - RobotKitMenu-5

servo to the RoboRED. The servo connector simply plugs


onto the RoboRED 3-pin D11 , as shown in the photo below,
the 3rd group of pins from the left. (Brown wire connects
to blue pin, red to red pin, yellow to yellow pin)

Robot Partly Built with Ultrasonic, Servo

Battery Pack

Insert 6 AA batteries into the battery case. Be careful about the orientation of each battery.
Make sure each battery's + end is pushed towards the + contact. You will want to use the small
flat screwdriver to push the individual AA cells toward the +connection to make sure. (There is a
lot of friction in a new battery case and they might not make contact).

Use velcro, blue wire, a rubber band or other means to attach the Battery Pack to the back of

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 9/13
5/18/2017 arduino-info - RobotKitMenu-5

the robot chassis over the caster wheel. We like using a rubber band or velcro so the battery
pack can be easily taken off and then put back on when the batteries are replaced!
We recommend rechargeable NiMH type batteries. You will also find the small flat screwdriver
good to help get batteries OUT of the battery case. They are very tight and secure, but
difficult to get in and out.
NOTE: When you plug the battery case into the RoboRED, the power LED on the RoboRED should
light. If it does not, check that the batteries are pushed towards their PLUS end.

Important: Do not plug the battery case in at this time.

Check your wiring connections:

Check that you have the wires connected properly to the RoboRED (See above for cable colors
and location). These connections must be correct for the robot to function properly. ###
TERRY CHECK THIS ###

Motor
Driver
1 Board
to
6 Wires:
RoboRed
Green, Blue, Violet, Gray,
White, Black

ERROR! BLACK and WHITE reversed. Use Table

2 Motor
Driver

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 10/13
5/18/2017 arduino-info - RobotKitMenu-5

Board
to
RoboRed

2 Wires: Brown, Red

Motor
Driver
Board
3
to
2 DC
Motors 2 Wires: Red, Black

4 Wires: Green, Yellow,


Orange, Red

Ultrasonic
Distance
4 Sensor
to
RoboRed

Servo
5 to 3 Wires: Brown, Orange,
RoboRed Yellow

ALL Wires In Place. COLORS Correct!

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 11/13
5/18/2017 arduino-info - RobotKitMenu-5

Arduino and Robot Software:

Next we are going to program the RoboRED to test the Robot Motors. Then we will try out some
Robot Moves you can use to set up a sequence of moves you decide about.

Go To the Next Section: Controlling Power


OR back to the Main Menu:

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitMenu-5?f=print 12/13
5/18/2017 arduino-info - RobotKitMenu-6

RobotKitMenu­6
print this page
BACK to MENU

CONTROLLING POWER:
Small DC motors can take significant current and they normally can‛t
be driven directly from the output pin of an Arduino or any other
microcomputer chip . Details HERE: Therefore they need some sort of
driver or current boost before you can control them. We use the
motor driver board shown on the right. This has a chip that can
control the current that the motors will need. Details are HERE:
You MUST use the battery power to run the robot motors in the following tests.

Speed and Direction Control:


The Motor Driver is connected to the RoboRED with 6 wires that can set the
connection of each motor wire (to + or - of the battery) and also switch power to the
motors on and off very quickly. Details HERE: The direction and speed of each motor
can be controlled independently.

TEST MOTOR DRIVER AND MOTORS:

Battery Case Setup:

Insert 6 AA batteries into the battery case. Be careful about the orientation of each
battery. Make sure each battery's + end is pushed towards the + contact. (The - end
goes towards the coiled connection). You will want to use the small flat screwdriver
(see Photo) to push the individual AA cells toward the + connection to make sure.
(There is a lot of friction in a new battery case and they might not make contact). You
should also rotate each AA cell a bit with you thumb to assure good contact. If the
cells are new, it's also a good idea to run both ends against your blue jeans (or other
slightly abrasive cloth) to clean the contacts.

We recommend rechargeable NiMH type batteries. You will also find the small flat
screwdriver good to help get batteries OUT of the battery case. They are very tight
and secure, but difficult to get in and out.

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 1/10
5/18/2017 arduino-info - RobotKitMenu-6

NOTE: If you want to


use the optional power
switch, instructions are
at the bottom of this
page.

Start with the battery


case UNplugged from the
Robo1. Find something to
sit your robot on so that
it's two big wheels are
off the ground and it
can't try to escape.

Download the motor driver library HERE and add it to your "libraries" folder.
How-To Install Libraries HERE:
Close and restart the Arduino IDE so that the library is recognized.

Cut and paste the test Software Sketch below into a new blank sketch window. Click
Verify to make sure the software and libraries are installed correctly. Save it with
some name like "MotorTest". Then click Upload to send it to the RoboRED.

NOTE! There is a small white button switch next to the blue power terminal board.
SIGH! Some need to be UP and some need to be DOWN to power the motor
driver. After you plug in the battery cable, look for a red led on the motor driver.
Push the switch to the position where an led lights up. NOTE: You can also use the
switch to turn the motors off temporarily to upload a new sketch.

Now UNplug the USB cable and plug in the Battery Case cable. (If you have wired in
the switch, turn it on.) After several seconds you should see the LEDs on the motor
driver board change brightness and one wheel should turn forward, stop and then turn
in reverse, followed by the second motor. After a delay the test should run again. If
the LEDs on the motor driver do NOT light up, the AA cells are not making good
http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 2/10
5/18/2017 arduino-info - RobotKitMenu-6

contact in the battery case (see above) or the button switch is in the wrong position.
.
Note: With the caster wheel towards you, check the motors operation: If you have
the motors connected properly you should first see the LEFT-hand motor go forward
and then reverse, followed by the RIGHT-hand motor going forward and then reverse.
If a motor is rotating in the wrong direction, check the wiring as shown in the photos,
and if necessary reverse the red and black wires where they are connected to the
motor driver terminal block. (Thanks to Ganesh Shenoy for fixing this!)

/* YourDuino.com Example Software Sketch


MotorDriverDEV
YD_MotorDriver1 Library Test
terry@yourduino.com
V2.01 12/10/2016 Add Print statements
*/

/*-----( Import needed libraries )-----*/


#include <YD_MotorDriver1.h>

/*-----( Declare Constants )-----*/


// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable
#define Motor1A 8
#define Motor1B 7
#define Motor2C 6
#define Motor2D 5

#define RampDelay 250


/*-----( Declare objects )-----*/
YD_MotorDriver1 RobotDriver(Motor1A, Motor1B, Motor2C, Motor2D);
//YD_MotorDriver1 RobotDriver();

/*-----( Declare Variables )-----*/

void setup() /*----( SETUP: RUNS ONCE )----*/


{
Serial.begin(115200);
Serial.println("YourDuino MotorDriver1 Ramp Up / Down Test");
RobotDriver.init();

}/*--(end setup )---*/

void loop() /*----( LOOP: RUNS CONSTANTLY )----*/


{
Serial.println();
Serial.println("Yourduino.com Robot Kit V2 Motors Test");
delay(2000); // Give time to put the robot down!
Serial.println("LEFT Motor Forward: Motor 1 0..+400");
for (int i = 0; i <= 400; i = i + 10)
{
RobotDriver.Motor1Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 3/10
5/18/2017 arduino-info - RobotKitMenu-6
Serial.println();
delay(2000);

Serial.println(" LEFT MOTOR Slow - Stop - Reverse: Motor 1 +400..0..-400");


for (int i = 400; i >= -400; i = i - 10)
{
RobotDriver.Motor1Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}
Serial.println();
delay(2000);

Serial.println("LEFT Motor slow to stop: Motor 1 -400..0");


for (int i = -400; i <= 0; i = i + 10)
{
RobotDriver.Motor1Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}
Serial.println();
delay(2000);

/*----( Ramp Motor2 Up and Down both directions )-------*/


Serial.println("RIGHT Motor Forward: Motor 2 0+");
for (int i = 0; i <= 400; i = i + 10)
{
RobotDriver.Motor2Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}
Serial.println();
delay(2000);

Serial.println(" RIGHT MOTOR Slow - Stop - Reverse: Motor 2 +-");


for (int i = 400; i >= -400; i = i - 10)
{
RobotDriver.Motor2Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}
Serial.println();
delay(2000);

Serial.println("RIGHT Motor slow to stop:Motor 2 -0");


for (int i = -400; i <= 0; i = i + 10)
{
RobotDriver.Motor2Speed(i);
Serial.print(i, DEC);
Serial.print(" ");
delay(RampDelay);
}
Serial.println();
delay(2000);

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 4/10
5/18/2017 arduino-info - RobotKitMenu-6

// delay(5000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/

/* ( THE END ) */

You can also run the test with the USB connected. You might have to unplug and
replug it to be recognized in the Arduino IDE. Click on the upper-right "Serial

Monitor" icon. Set the speed (lower right) to 115200 to see the
output.

If the above test ran OK, continue here. And if you haven't already this is a good time
to put the wheels on!

TEST AND ADJUST MOTOR SPEEDS:


This test sketch will run the robot in slow, medium and fast speeds. You should place
it on a smooth floor if possible. Carpet, especially thick carpet will slow or stop this
robot. If you must run it on some carpet, you may have to change the MoveSpeed
values to be higher, like SlowMoveSpeed 300, MediumMoveSpeed 360,
FastMovespeed 390. But it will only run really well on a smooth floor.

You can adjust the right VS left motor speeds to try to get the robot to move
straight ahead. You can hold the robot in both hands, holding the RESET button on
the right side of the RoboRED pressed until you put the robot down. Also make sure
the caster wheel is pointing straight when you start. You can hold the RESET button
with your right thumb, and click the Motor Driver White Button with your left finger,
like in the following photo:

NOTE: To upload changes, you can leave the battery connected, turn the motors
temporarily OFF with the button on the Motor Driver, plug in the USB and upload a
new sketch. Then walk away, turn the motor driver on, hold your thumb on RESET and
put the robot down for another run.

See this part of the test sketch:

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 5/10
5/18/2017 arduino-info - RobotKitMenu-6

#define SlowMoveSpeed 280


#define SlowMoveAdjust 5 Adjust for straight move: - Left + Right??

#define MediumMoveSpeed 300


#define MediumMoveAdjust 5 Adjust for straight move: - Left + Right

#define FastMoveSpeed 350


#define FastMoveAdjust 5 // Adjust for straight move: - Left + Right

After you have found the best MoveAdjust values, write them down (or later cut and
paste) for use in the other sketches.

/* YourDuino Basic Robot Kit V2 Motor Speed Test


http://yourduino.com/sunshop2/index.php?l=product_detail&p=400
- WHAT IT DOES:
- Runs the robot motors at different speeds. Helps adjust Right-Left offsets
- SEE the comments after "//" on each line below
- CONNECTIONS:
Pins 9 (Motor1 PWM) and 10 (Motor2 PWM) are predefined, unchangeable

// Label--Arduino Pin-- Motor Driver Pin


Motor1A pin 8 // INA
Motor1B pin 7 // INB
Motor2C pin 6 // INC
Motor2D pin 5 // IND

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 6/10
5/18/2017 arduino-info - RobotKitMenu-6

- V2.10 11/10/2014
Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/


#include <YD_MotorDriver1.h> // For control of the two DC Motors

/*-----( Declare Constants and Pin Numbers )-----*/

// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable


#define Motor1A 8
#define Motor1B 7
#define Motor2C 6
#define Motor2D 5

#define StartMoveSpeed 200 // Motor Driver value for start of motion

#define SlowMoveSpeed 280


#define SlowMoveAdjust 5 // Adjust for straight move: - Left + Right??

#define MediumMoveSpeed 300


#define MediumMoveAdjust 5 // Adjust for straight move: - Left + Right

#define FastMoveSpeed 350


#define FastMoveAdjust 5 // Adjust for straight move: - Left + Right

/*-----( Declare objects )-----*/


YD_MotorDriver1 RobotDriver(Motor1A,Motor1B,Motor2C,Motor2D); // Set pins

void setup() /******************* SETUP: RUNS ONCE *****************/


{
Serial.begin(115200);
delay(1000);
Serial.println("YourDuino Robot Kit V2 Motor Speed Test");
//--NOTE: Motor Pins set to OUTPUT by their libraries
RobotDriver.init();
}//--(end setup )---

/************** LOOP: RUNS CONSTANTLY **************************/


void loop()
{
Serial.println("Forward Slow Speed");
ForwardSlow();
delay(5000);
Stop();
Serial.println("---STOP---");
delay(5000);

Serial.println("Forward Medium Speed");


ForwardMedium();
delay(5000);
Stop();
Serial.println("---STOP---");
delay(5000);

Serial.println("Forward Fast Speed");


ForwardFast();
delay(5000);
Stop();
Serial.println("---STOP---");

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 7/10
5/18/2017 arduino-info - RobotKitMenu-6
delay(10000);
Serial.println("---END---");

}//--(end main loop )---

/*----------------( Declare User-written Functions )---------------*/

//------( MOTOR CONTROL FUNCTIONS )----------------


void ForwardSlow()
{
RobotDriver.Motor1Speed(SlowMoveSpeed + SlowMoveAdjust);
RobotDriver.Motor2Speed(SlowMoveSpeed - SlowMoveAdjust);
}
/*---------------------------*/

void ForwardMedium()
{
RobotDriver.Motor1Speed(MediumMoveSpeed + MediumMoveAdjust);
RobotDriver.Motor2Speed(MediumMoveSpeed - MediumMoveAdjust);
}
/*---------------------------*/
void ForwardFast()
{
RobotDriver.Motor1Speed(FastMoveSpeed + FastMoveAdjust);
RobotDriver.Motor2Speed(FastMoveSpeed - FastMoveAdjust);
}
/*---------------------------*/
void BackwardSlow(int HowMuch)
{
RobotDriver.Motor1Speed(- SlowMoveSpeed );
RobotDriver.Motor2Speed(- SlowMoveSpeed );
delay(HowMuch);
Stop();
}
/*---------------------------*/
void BackwardMedium(int HowMuch)
{
RobotDriver.Motor1Speed(- MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void BackwardFast(int HowMuch)
{
RobotDriver.Motor1Speed(- FastMoveSpeed);
RobotDriver.Motor2Speed(- FastMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void Stop()
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(0);
}
/*---------------------------*/
void SpinLeft(int HowMuch)
{

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 8/10
5/18/2017 arduino-info - RobotKitMenu-6
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void SpinRight(int HowMuch)
{
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/

//*********( THE END )***********

TEST ROBOT MOVES AND CREATE YOUR OWN ROBOT


CONTROL PROGRAMS

Next is the section that shows details of making your own Robot Control Programs.

Go To the Next Section: Robot Commands and Editing


OR back to the Main Menu:

OPTIONAL: Connect a Power Switch


The Basic Robot does not require any soldering or special wiring. Many people plug the
battery case cable in or out to control power to the robot. If you would like to use the
optional switch included in the kit, here are instructions:
Physically install the switch (tight fit!) ; you might have to file the hole a little.
Find some small wire; cut two pieces about 5 inches long, strip the ends about
1/2 inch.
Connect the wire ends to the switch. The rear two contacts will be active when
the switch is flipped forward.
Solder the wires to the switch, OR
Put the wire end through the hole in the contact, wrap tightly around it
and tape securely.
http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 9/10
5/18/2017 arduino-info - RobotKitMenu-6

Cut the + (Red) wire of the battery case approximately in the center; strip the
ends about 1/2 inch.
Connect the wires from the switch to the battery case wire (either one is OK).
Plug the battery case connector into the RoboRED and check that the switch
works.

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 

Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitMenu-6?f=print 10/10
5/18/2017 arduino-info - RobotKitMenu-7

RobotKitMenu­7
print this page
BACK to MENU

ROBOT COMMANDS AND EDITING:

Now that you have built the Robot and have it running, you can learn to
edit the Commands and create a new Software Sketch to make the
Robot follow your own commands. Some of the different Commands
and what they do are listed below:

Forward: Runs both motors in the forward direction


Backward: Runs both motor in a backward direction
TurnRight: Makes the left motor go forward with the right
motor stopped
TurnLeft: Makes the right motor go forward with the left
motor stopped
SpinRight: Runs the right motor in reverse and the left motor in
forward
SpinLeft: Runs the left motor in reverse and the right motor in
forward
Wait: Stops the robot for a certain length of time that you
decide
Stop: Stops both motors

You can change the Robot Commands in these


ways:
Speed:
Forward:

ForwardSlow, ForwardMedium, ForwardFast, ForwardMax


http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 1/7
5/18/2017 arduino-info - RobotKitMenu-7

Backward:
BackwardSlow, BackwardMedium, BackwardFast,
BackwardMax
Length of Time a Command will Run:

Time is measured in milliseconds (Ms) so 1000 Ms = 1 second,


500 Ms = 1/2 second, etc.
Order in which the Commands Occur:
You can mix and match commands to make the Robot run in many
different patterns

How to use this code


It's interesting to look at the format of the code in the Software
Sketch below. There are basically 4 parts to the Software Sketch
after the Title and introduction:
1. Definition Area: This is where the Motor Control Library,
motor speeds and adjustments are defined (created by the
original programmer - don't change this!)
2. Setup Area: This is code that runs only once at the beginning
to set things up (defined by the original programmer - don't
change this!)
3. Editable Area: Contains the code that You can change to make
a new robot control program!
4. Motor Control Area: Code which specifies what the motors will
do in each of the different Commands. (defined by the original
programmer - don't change this!)

Now you can copy and paste the software Sketch below into the
Arduino IDE and try it out as-is on your own Robot. Observe your
Robot carefully. What did the Robot do? How do the commands in the

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 2/7
5/18/2017 arduino-info - RobotKitMenu-7

Editable Area control what the robot does?

Now you're ready to make some changes. Try changing the timing and
order of the different commands in the Editable Area of the
Software Sketch. Can you make the robot "dance"? Use "SAVE AS" to
save different versions; give each a name.

/* YourDuino Basic Robot Kit V2 User EDitable Software Sketch


How To Page that goes with this Software Sketch:
http://arduino-info.wikispaces.com/Robot+Commands
WHAT IT DOES:
- Runs the robot motors
- Program the robot to make different moves such as Forward, SpinRight, Back etc.
- SEE the comments after "//" on each line below

- V2.20 3/27/2015 maryalice@yourduino.com


Questions: terry@yourduino.com */

/***************************************************************/
/*---------------------( DEFINITION AREA )---------------------*/
/***************************************************************/

/*-----( Import needed libraries )-----*/


#include <YD_MotorDriver1.h> // For control of the two DC Motors

/*-----( Declare Constants and Pin Numbers )-----*/

// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable


#define Motor1A 8
#define Motor1B 7
#define Motor2C 6
#define Motor2D 5
/* Motor speed can be in the range of 200 - 400 only */
#define StartMoveSpeed 200 // Lowest Motor Speed value for start of motion
/* The section sets up the motor speeds for slow, medium, fast
The adjust numbers help make the robot run straight.
Positive numbers turn more right, negative numbers turn more left.*/
#define SlowMoveSpeed 280
#define SlowMoveAdjust 0 // Adjust to go straight: - Left + Right??

#define MediumMoveSpeed 300


#define MediumMoveAdjust 0 // Adjust to go straight: - Left + Right

#define FastMoveSpeed 350


#define FastMoveAdjust 0 // Adjust to go straight: - Left + Right

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 3/7
5/18/2017 arduino-info - RobotKitMenu-7

#define MaxMoveSpeed 385


#define MaxMoveAdjust 0 // Adjust to go straight: - Left + Right
/*-----( Declare objects )-----*/
YD_MotorDriver1 RobotDriver(Motor1A,Motor1B,Motor2C,Motor2D); // Set pins

/***************************************************************/
/*-----------------( SETUP AREA RUNS ONCE )--------------------*/
/***************************************************************/

void setup()
{
Serial.begin(115200); //Start the "Serial Monitor"
delay(1000);
Serial.println("YourDuino Robot Kit V2 User Editable Robot Control");
//--NOTE: Motor Pins set to OUTPUT by their libraries
RobotDriver.init(); //Start up the Robot Driver Library
}//--(end setup )---

/******************( LOOP: RUNS CONSTANTLY )********************/


void loop()
{
/***************************************************************/
/*--------------------( EDITABLE AREA )------------------------*/
/***************************************************************/
ForwardSlow(2000);
Wait(2000);

ForwardMedium(2000);
Wait(2000);

BackwardMedium(4000);
Wait(2000);

SpinRight(5000);
Wait(2000);

SpinLeft(5000);
Wait(5000);

//Now this will go back to the beginning of code in the Editable Area

/***************************************************************/
/*-----------------( END OF EDITABLE AREA )--------------------*/
/***************************************************************/
}//--(end main loop )---

/***************************************************************/
/*-------------------( MOTOR CONTROL AREA )--------------------*/
/***************************************************************/

void ForwardSlow(int howLong)

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 4/7
5/18/2017 arduino-info - RobotKitMenu-7

{
RobotDriver.Motor1Speed(SlowMoveSpeed + SlowMoveAdjust);
RobotDriver.Motor2Speed(SlowMoveSpeed - SlowMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/

void ForwardMedium(int howLong)


{
RobotDriver.Motor1Speed(MediumMoveSpeed + MediumMoveAdjust);
RobotDriver.Motor2Speed(MediumMoveSpeed - MediumMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void ForwardFast(int howLong)
{
RobotDriver.Motor1Speed(FastMoveSpeed + FastMoveAdjust);
RobotDriver.Motor2Speed(FastMoveSpeed - FastMoveAdjust);
delay(howLong);
Stop();
}

/*---------------------------*/
void ForwardMax(int howLong)
{
RobotDriver.Motor1Speed(MaxMoveSpeed + MaxMoveAdjust);
RobotDriver.Motor2Speed(MaxMoveSpeed - MaxMoveAdjust);
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardSlow(int howLong)
{
RobotDriver.Motor1Speed(- SlowMoveSpeed );
RobotDriver.Motor2Speed(- SlowMoveSpeed );
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardMedium(int howLong)
{
RobotDriver.Motor1Speed(- MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void BackwardFast(int howLong)
{

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 5/7
5/18/2017 arduino-info - RobotKitMenu-7

RobotDriver.Motor1Speed(- FastMoveSpeed);
RobotDriver.Motor2Speed(- FastMoveSpeed);
delay(howLong);
Stop();
}

/*---------------------------*/
void BackwardMax(int howLong)
{
RobotDriver.Motor1Speed(- MaxMoveSpeed);
RobotDriver.Motor2Speed(- MaxMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void Stop()
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(0);
}
/*---------------------------*/
void TurnLeft(int howLong)
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void TurnRight(int howLong)
{
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(0);
delay(howLong);
Stop();
}
/*---------------------------*/
void SpinLeft(int howLong)
{
RobotDriver.Motor1Speed(-MediumMoveSpeed);
RobotDriver.Motor2Speed( MediumMoveSpeed);
delay(howLong);
Stop();
}
/*---------------------------*/
void SpinRight(int howLong)
{
RobotDriver.Motor1Speed(MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(howLong);
Stop();

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 6/7
5/18/2017 arduino-info - RobotKitMenu-7

}
/*---------------------------*/
void Wait(int howLong)
{
delay(howLong);
}
/*---------------------------*/

//*********( THE END )***********

Go To the Next Section: Collision Avoidance


OR back to the Main Menu:

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­
Commercial 3.0 License. 
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitMenu-7?f=print 7/7
5/18/2017 arduino-info - RobotKitMenu-8

RobotKitMenu­8
print this page
BACK to MENU

NOTE!! PROBLEM with compiling solved with new software version (below)

PROBLEMS: Email terry@yourduino.com

AUTONOMOUS COLLISION-AVOIDING ROBOT SKETCHES:


These are more complex software sketches. IF you want to change them you will need good programming
skills.

This assumes you have built the robot with:


YourDuinoRoboRED
Battery Case (Optional: switch)
DC Motors connected to the Motor Controller board
Servo mounted in the front of the Robot
Ultrasonic Sensor mounted on the Servo to "Look Around"
The Motor Driver and NewPing (Ultrasonic) and SM (State Machine) libraries have been installed
The Tests above of Servo, Motor Driver and Ultrasonic Sensor are all working

The needed connections are shown in the details at the beginning of the sketch. If you followed the
directions on the build page and the motor tests ran OK you will have the correct wiring.

NOTE: See the MoveAdjust values in the Sketches below to compensate for motor differences to make the
robot run straighter. It won't be perfect.

COLLISION AVOIDANCE 2 (2.20): Stops to look around; easier to see actions.

Copy and paste this Sketch into a blank Arduino IDE page, save it with a name, Verify it, and Upload it to the
Robot.

/* YourDuino Basic Robot Kit V2 Collision-avoidance Test


(Rewritten using "Switch" statements to create the State Machine )
This version is slow, waits to look around.
KIT here: http://yourduino.com/sunshop2/index.php?l=product_detail&p=400
HOW-TO here: http://arduino-info.wikispaces.com/RobotKitMenu
- WHAT IT DOES:
- Runs the robot motors
- Looks Around with the Servo and Ultrasonic Sensor
- Avoids obstacles
- SEE the comments after "//" on each line below
NOTE: See the MoveAdjust values below to compensate for motor differences
to make the robot run straighter. See:
http://arduino-info.wikispaces.com/RobotKitMenu-6
REQUIRES: YD_MotorDriver1 Library
- CONNECTIONS:
Pins 9 (Motor1 PWM) and 10 (Motor2 PWM) are predefined, unchangeable

// Label--Arduino Pin-- Motor Driver Pin


Motor1A pin 8 // INA
Motor1B pin 7 // INB

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 1/7
5/18/2017 arduino-info - RobotKitMenu-8
Motor2C pin 6 // INC
Motor2D pin 5 // IND

// - V2.20 02/02/2016
Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/


#include <YD_MotorDriver1.h> // For control of the two DC Motors
#include <NewPing.h> // Runs the Ultrasonic Distance Sensor

/*-----( Declare Constants and Pin Numbers )-----*/

// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable


#define Motor1A 8
#define Motor1B 7
#define Motor2C 6
#define Motor2D 5

#define RampDelay 10

#define StartMoveSpeed 200 // Motor Driver value for start of motion

#define SlowMoveSpeed 280


#define SlowMoveAdjust 0 // Adjust for straight move: - Left + Right??

#define MediumMoveSpeed 300


#define MediumMoveAdjust 0 // Adjust for straight move: - Left + Right

#define FastMoveSpeed 350


#define FastMoveAdjust 0 // Adjust for straight move: - Left + Right

// Ultrasonic Sensor Pins


#define TRIGGER_PIN 2 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 3 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 100 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
// Servo
#define SERVO_PIN 11 // The "Look Around" servo

#define PIN13_LED 13 // The onboard LED: Lights when an object is sensed by the Ultrasonic
// Add a Beeper on pin 13 if you want

//----( "TARGET FOUND" DIRECTIONS (index into TargetArray )---------


#define TARGET_FOUND_ANY 0 // Values will be "true" or "false"
#define TARGET_LEFT 1
#define TARGET_LEFT_CENTER 2
#define TARGET_CENTER 3
#define TARGET_RIGHT_CENTER 4
#define TARGET_RIGHT 5

#define TARGET_ARRAY_SIZE 6

#define TARGET_TOO_CLOSE 25 // cm

/*-----( Declare objects )-----*/


YD_MotorDriver1 RobotDriver(Motor1A, Motor1B, Motor2C, Motor2D); // Set pins
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // Set pins and maximum distance.

/*-----( Declare Variables )-----*/


unsigned int uS; // Result of a ping: MicroSeconds
unsigned int cm; // Distance calculated for ping (0 = outside set distance range)
unsigned int cm_now; // For test

int TargetArray[TARGET_ARRAY_SIZE]; // Holds the directions a Target was found in


int DirectionsToLook = 3; // For LookAround()
int ServoDirectionData[3] = { 2500, 1600, 600};

/*-----( Define the 'States' the robot can be in )-----*/


enum { START_STATE,
STOP_LOOK_STATE,
TARGET_CENTER_STATE,
TARGET_LEFT_STATE,
TARGET_RIGHT_STATE
} RobotState = START_STATE;

void setup ()
{
Serial.begin(115200);

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 2/7
5/18/2017 arduino-info - RobotKitMenu-8
delay(1000);
Serial.println("YourDuino Robot Kit Test");
//--NOTE: Ultrasonic Sensor and Motor Pins set to OUTPUT by their libraries
pinMode(SERVO_PIN, OUTPUT);
pinMode(PIN13_LED, OUTPUT);
RobotDriver.init();
}

void loop()
{
/*-----( Control the Robot by changing the "State" it is in. )-----*/
switch (RobotState)
{
case START_STATE: // Start here, return here if no obstacles
Serial.println("+++ RoboStartState");
digitalWrite(PIN13_LED, LOW); // LED Means Target Too Close. Turn it off for now.
ForwardFast(); // Get a good start moving forward
delay(25);
ForwardSlow(); // Continue moving forward
delay(600);
RobotState = STOP_LOOK_STATE ; // Now change to state to look for obstacles
break;

case STOP_LOOK_STATE: // Look around for obstacles; take different actions if found
Serial.println("+++ RoboStopLookState");
Stop(); // Stop moving forward

for (int i = 0; i < TARGET_ARRAY_SIZE; i++) TargetArray[i] = false;


LookAround(); // Ping Ultrasonic in different directions, Set TargetArray

if (TargetArray[TARGET_CENTER ] == true) RobotState = TARGET_CENTER_STATE;


else if (TargetArray[TARGET_LEFT ] == true) RobotState = TARGET_LEFT_STATE;
else if (TargetArray[TARGET_RIGHT ] == true) RobotState = TARGET_RIGHT_STATE;
else RobotState = START_STATE;
break;

case TARGET_CENTER_STATE: // Obstacle straight ahead; back up then turn around


Serial.println("***** RoboTargetCenter");
Stop();
BackwardSlow(500);
SpinLeft(1100); // try for 180 degrees turn
delay(500);
RobotState = START_STATE;
break;

case TARGET_LEFT_STATE: // Obstacle on left; back up then turn right


Serial.println("***** RoboTargetLeft");
Stop();
BackwardSlow(500);
SpinRight(500);
delay(500);
RobotState = START_STATE;
break;

case TARGET_RIGHT_STATE: // Obstacle on right; back up then turn left


Serial.println("***** RoboTargetRight");
Stop();
delay(500);
BackwardSlow(500);
SpinLeft(500);
delay(500);
RobotState = START_STATE;
break;
} // end of switch

} // end of loop

/*----------------( Declare User-written Functions )---------------*/

//------( MOTOR CONTROL FUNCTIONS )----------------


void ForwardSlow()
{
RobotDriver.Motor1Speed(SlowMoveSpeed + SlowMoveAdjust);
RobotDriver.Motor2Speed(SlowMoveSpeed - SlowMoveAdjust);
}
/*---------------------------*/

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 3/7
5/18/2017 arduino-info - RobotKitMenu-8

void ForwardMedium()
{
RobotDriver.Motor1Speed(MediumMoveSpeed + MediumMoveAdjust);
RobotDriver.Motor2Speed(MediumMoveSpeed - MediumMoveAdjust);
}
/*---------------------------*/
void ForwardFast()
{
RobotDriver.Motor1Speed(FastMoveSpeed + FastMoveAdjust);
RobotDriver.Motor2Speed(FastMoveSpeed - FastMoveAdjust);
}
/*---------------------------*/
void BackwardSlow(int HowMuch)
{
RobotDriver.Motor1Speed(- SlowMoveSpeed );
RobotDriver.Motor2Speed(- SlowMoveSpeed );
delay(HowMuch);
Stop();
}
/*---------------------------*/
void BackwardMedium(int HowMuch)
{
RobotDriver.Motor1Speed(- MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void BackwardFast(int HowMuch)
{
RobotDriver.Motor1Speed(- FastMoveSpeed);
RobotDriver.Motor2Speed(- FastMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void Stop()
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(0);
}
/*---------------------------*/
void SpinLeft(int HowMuch)
{
RobotDriver.Motor1Speed( MediumMoveSpeed);
RobotDriver.Motor2Speed(- MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/
void SpinRight(int HowMuch)
{
RobotDriver.Motor1Speed(- MediumMoveSpeed);
RobotDriver.Motor2Speed( MediumMoveSpeed);
delay(HowMuch);
Stop();
}
/*---------------------------*/

unsigned int PingBlink()


{
uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
cm = uS / US_ROUNDTRIP_CM; // Convert ping time to distance in cm
Serial.print(" cm = ");
Serial.print(cm, DEC);

if ((cm < 40) && (cm != 0))


{
return (cm);
}
else
{
return (100); // No Valid Distance
}
}// end PingBlink
/*---------------------------*/

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 4/7
5/18/2017 arduino-info - RobotKitMenu-8

void PointServo(int ServoAngle)


{

for (int i = 0; i < 20; i++) // Send the pulse 10 times


{
digitalWrite(SERVO_PIN, HIGH);
delayMicroseconds(ServoAngle);
digitalWrite(SERVO_PIN, LOW);
delay(20);
}
}// PointServo end
/*---------------------------*/

void LookAround() // Sets next state if Target Found


{
for (int Direction = 0; Direction < DirectionsToLook ; Direction ++)
{
Serial.print("DIRECTION = ");
Serial.print(Direction, DEC);
PointServo(ServoDirectionData[Direction]); // Get servo pulse width from array
delay(200);
cm_now = PingBlink(); // Read the Ultrasonic distance

Serial.print(" cm_now = ");


Serial.println(cm_now, DEC);
if (cm_now < TARGET_TOO_CLOSE) digitalWrite(PIN13_LED, HIGH);

if (cm_now < 40)


{
TargetArray[TARGET_FOUND_ANY ] = true;
}
else TargetArray[TARGET_FOUND_ANY ] = false;

if ((cm_now < TARGET_TOO_CLOSE) && (Direction == 2)) //LEFT


{
TargetArray[TARGET_LEFT ] = true;
Serial.println("TargetLeft");
}

if ((cm_now < TARGET_TOO_CLOSE) && (Direction == 1)) //Center


{
TargetArray[TARGET_CENTER ] = true;
Serial.println("TargetCenter");
}

if ((cm_now < TARGET_TOO_CLOSE) && (Direction == 0)) //RIGHT


{
TargetArray[TARGET_RIGHT ] = true;
Serial.println("TargetRight");
}

}// END Directions

}// END LookAround

//****** THE END ************

Plug in the battery connector, hold the robot in both hands, and put it down in a clear area. It should move
forward, stop and look around. The sequence of it's actions are:

1. Move forward at medium speed for about a second


2. Stop
http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 5/7
5/18/2017 arduino-info - RobotKitMenu-8

3. Use the servo to point the Ultrasonic Sensor Left, Center, Right
4. IF something is too close, turn on the Pin 13 LED on the RoboRED and THEN:
1. Left: Spin Right and then start over.
2. Center: Spin around backwards and then start over
3. Right: Spin Left and then start over.
5. ELSE Go to the beginning and start over

Test this by holding your flat hand on the left side of the robot as it stops to look. It should spin right, away
from you. Test again on the right side, and then straight ahead.

You can add a Buzzer to signal when the robot 'sees' something (Actually, hears a close echo). Find the
"Buzzer" module in your kit. See it here: Notice it has a (+) mark (and that lead is longer). Strip off a 2-wire
piece from your Rainbow Cable. (We used Black and White). Push the White lead on one end on to the Buzzer
(+), then Black on the other lead. REMOVE the white sticker! On the other end, plug the Black wire on Pin 13
[G]round (Blue) and the White wire on Pin 13 [S]ignal (Yellow). Arrange the wire so the buzzer does not
bounce are or get in the way. Run the robot again. When a too-close object is found, the Pin 13 LED should
light as before AND the Buzzer should sound.

Other possible modifications if you dig into the code:

Look at the code for avoiding objects. Add an LED and 220 ohm resistor to (available) pin 4 or pin 12
and made them be turn signals. Or maybe add LEDs and resistors where the Beeper is connected as
Backup lights.
Modify the directions the servo points the ultrasonic and 'scan' for an object and stop in front of it.
Or follow it.
Add new hardware to make a line follower robot. You'll probably have to use the pins the servo and
ultrasonic use now.
Other Ideas?? email terry@yourduino.com

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 6/7
5/18/2017 arduino-info - RobotKitMenu-8

Go To the Next Section: Adding Capabilities


OR back to the Main Menu:

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

Add Discussion

Contributions to http://arduino­info.wikispaces.com/ are licensed under a Creative Commons Attribution Non­Commercial 3.0 License. 
Portions not contributed by visitors are Copyright 2017 Tangient LLC
TES: The largest network of teachers in the world

http://arduino-info.wikispaces.com/RobotKitMenu-8?f=print 7/7
5/18/2017 arduino-info - RobotKitMenu-9

RobotKitMenu­9
print this page

ADDING CAPABILITIES:

We plan to show more project ideas here. As of now we plan:

IR Infrared Robot Remote Control Kit for remote control of the Robot (See early
version below)
Line Following, using the Robot 7-way Multi Tracking Sensor

PINS Used on the RoboRED:

Later you might want to connect other things to the RoboRED on your robot, like maybe an IR
remote control. Arduino UNO and RoboRED have 13 Digital I/O Pins and 6 Analog/Digital I/O
pins. Here's what the robot uses them for, and what's still available:

So, as you can see, only Input-Output pins 4 and 12 are available for new ideas.
BUT, BUT! We are not using ANY of the Arduino "Analog" pins.

PIN NumberWhat the robot uses it for


0 Upload Software Sketches
1 Upload Software Sketches
2 UltraSonic Sensor
3 UltraSonic Sensor
4 AVAILABLE
5 Motor Controls
6 Motor Controls
7 Motor Controls
8 Motor Controls
9 Motor Controls
10 Motor Controls
11 Servo
http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 1/7
5/18/2017 arduino-info - RobotKitMenu-9
12 AVAILABLE
13 LED/Beeper "Object was Sensed"
A0 AVAILABLE
A1 AVAILABLE
A2 AVAILABLE
A3 AVAILABLE
A4 AVAILABLE
A5 AVAILABLE

NOTE: The A0 to A5 pins may be


used just like pins 0..13 as Digital
Inputs and Outputs, as well as for
measuring Analog voltages from
0..5.0 Volts
Suggested pins for future add-
ons:
12 - Infrared Remote Control
Back to the Main Menu:

Infrared Remote Control


for YourDuino Basic
Robot Kit V2
This is an early version, apparently
working, which adds a simple IR
receiver to the Yourduino Basic
Robot Kit V2. (See it near Blue
Tape: right)
If you haven't already, download
the motor driver library HERE and add it to your "libraries" folder.

Copy and paste the following code into your Arduino IDE and upload it to your Robot. HINT:
Connect both battery and USB for upload. Use the small white button on the Motor Driver to
turn motors OFF while uploading. After upload, unplug the USB, put the robot down and turn
the motors back on.
PLEASE give feedback on how this works for you! terry@yourduino.com

/* YourDuino.com Robot Kit 2 Infrared Remote Control Example


YD_Robot_IR_Control.ino
Adapted from Club Electron (South Africa) Example

Adds an Infrared Receiver on Pin 12 to usual Robot Kit configuration

Controls DC motors and servo from Robot kit to run depending on button pressed on IR remote
Forward
Reverse
Turn Right
Turn Left
OK (Stop now)
*/

http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 2/7
5/18/2017 arduino-info - RobotKitMenu-9

/*-----( Import needed libraries )-----*/


#include "IRremote.h"
#include "IRremoteInt.h"
#include <YD_MotorDriver1.h>

/*------( Define pin numbers )----- */


//NOTE: Pins 9 and 10 are already used by the Motor Library
#define Motor1A_PIN 8
#define Motor1B_PIN 7
#define Motor2C_PIN 6
#define Motor2D_PIN 5
#define LED_PIN 13

#define IR_RECEIVER_PIN 12

/*-----( Declare Other Constants )-----*/


#define MOVE_FORWARD 10 // Remote Button
#define MOVE_LEFT 11
#define MOVE_STOP 12
#define MOVE_RIGHT 13
#define MOVE_REVERSE 14
#define SPIN_MODE 20
#define AUTO_MODE 30

#define REPEAT_CODE -2 // Return codes from TranslateIR


#define BAD_IR_DATA -1

/*-----( Declare global variables )-----*/


int ButtonValue; // Value returned by TranslateIR
int LastCommand; // Used by Repeat
boolean SpinOption = false; // Turns can be TURN (One wheel stopped) or SPIN (Wheels in opposite directions).
boolean AutoMode = false; // Switch to autonomous collision avoidance mode (NOT YET!)

int StopCounter = 0;
int Timeout = 20000; // Stop motors if no button signal detected for some time (range 15000 - 30000)

/* Motor speed can be in the range of 200 - 400 only */

/*-----( Declare objects )-----*/


IRrecv robotRemote(IR_RECEIVER_PIN); // Create instance of 'IRrecv'
decode_results results; // Create instance of 'decode_results'
YD_MotorDriver1 RobotDriver(Motor1A_PIN, Motor1B_PIN, Motor2C_PIN, Motor2D_PIN); // Set pins used

/*-----( Declare Variables )-----*/


/* Max speed should be 400. Positive numbers turn more right, negative numbers turn more left.*/
#define MOVE_SPEED 370
#define MOVE_ADJUST 0 // Adjust to go straight: - Left + Right??

void setup() /*----( SETUP: RUNS ONCE )----*/


{
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("YourDuino.com Robot Kit 2 Infrared Remote Control");

robotRemote.enableIRIn(); // Start the Receiver

RobotDriver.init(); // Start up the Robot Driver Library

} /*--(end setup )---*/

void loop() /*----( LOOP: RUNS CONSTANTLY )----*/


{

CheckButtons(); // Check if a button is pressed


StopMotors(); // Stop motors if no button is pressed

http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 3/7
5/18/2017 arduino-info - RobotKitMenu-9

} /* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/


int TranslateIR() // returns value of Remote IR code received
{

switch (results.value)

{
case 0xFF629D:
return MOVE_FORWARD;
break;
case 0xFF22DD:
return MOVE_LEFT;
break;
case 0xFF02FD:
return MOVE_STOP;
break;
case 0xFFC23D:
return MOVE_RIGHT;
break;
case 0xFFA857:
return MOVE_REVERSE;
break;
case 0xFF42BD: // *
return SPIN_MODE;
break;
case 0xFF52AD: // #
return AUTO_MODE;
break;
case 0xFFFFFFFF:
return REPEAT_CODE; // REPEAT: Button Held down
break;
default:
return BAD_IR_DATA; // Other Button / Bad Code / IR receive error

} //END case

} //END TranslateIR

//-------------------------------------------------------------------------------
void CheckButtons() //Checks if button pressed and moves motors accordingly
{
if (robotRemote.decode( & results)) // Have we received an IR signal?
{
StopCounter = 0;
ButtonValue = TranslateIR();
if (ButtonValue != REPEAT_CODE) LastCommand = ButtonValue;
if (ButtonValue == REPEAT_CODE) ButtonValue = LastCommand;
if (ButtonValue == BAD_IR_DATA)
{
digitalWrite(LED_PIN, HIGH);
}
else
{
digitalWrite(LED_PIN, LOW);
}

// Serial.println(ButtonValue, DEC);

switch (ButtonValue)
{
case MOVE_FORWARD:
Serial.println(" FORWARD");
Forward();
break;

http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 4/7
5/18/2017 arduino-info - RobotKitMenu-9

case MOVE_REVERSE:
Serial.println(" REVERSE");
Back();
break;

case 6:
SpinRight();
break;

case 4:
SpinLeft();
break;

case MOVE_RIGHT:
if (SpinOption == false)
{
Serial.println(" TURN RIGHT");
TurnRight();
}
else
{
Serial.println(" SPIN RIGHT");
SpinRight();
}
break;

case MOVE_LEFT:
if (SpinOption == false)
{
Serial.println(" TURN LEFT");
TurnLeft();
}
else
{
Serial.println(" SPIN LEFT");
SpinLeft();
}
break;

case MOVE_STOP:
Serial.println(" STOP");
StopMotors();
break;

case SPIN_MODE:
Serial.println(" CHANGE SPIN MODE");
SpinOption = !SpinOption;
delay(1000);
break;

case AUTO_MODE:
Serial.println(" AUTO MODE");
AutoMode = ! AutoMode;
delay(1000);
break;

case REPEAT_CODE:
Serial.println("+++RPT+++");
break;

default:
StopMotors();
Serial.println("Invalid Number");
break;
}
ButtonValue = 0;

http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 5/7
5/18/2017 arduino-info - RobotKitMenu-9

robotRemote.resume(); // Receive the next value


}
} // END CheckButtons

/*-------------------( MOTOR CONTROL FUNCTIONS )--------------------*/

void Forward()
{
RobotDriver.Motor1Speed(MOVE_SPEED + MOVE_ADJUST);
RobotDriver.Motor2Speed(MOVE_SPEED - MOVE_ADJUST);
}

void Back()
{
RobotDriver.Motor1Speed(-MOVE_SPEED);
RobotDriver.Motor2Speed(-MOVE_SPEED);
}

void TurnLeft()
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(MOVE_SPEED);
}

void TurnRight()
{
RobotDriver.Motor1Speed(MOVE_SPEED);
RobotDriver.Motor2Speed(0);
}

void SpinLeft()
{
RobotDriver.Motor1Speed(-MOVE_SPEED);
RobotDriver.Motor2Speed(MOVE_SPEED);
}

void SpinRight()
{
RobotDriver.Motor1Speed(MOVE_SPEED);
RobotDriver.Motor2Speed(-MOVE_SPEED);
}

void StopMotors()
{
StopCounter += 1;
if ( StopCounter >= Timeout ) // Stop motors if there is no signal after Timeout cycles
{
RobotDriver.Motor1Speed(0);
RobotDriver.Motor2Speed(0);
}
} //END StopMotors

/*---------------------------*/
/* ( THE END ) */

Please email comments, critiques, suggestions and questions to:


terry@yourduino.com

http://arduino-info.wikispaces.com/RobotKitMenu-9?f=print 6/7

Vous aimerez peut-être aussi