STEMCenter USA Pi-Bot v2.00 User manual

V2.0 User Manual
A uniquely designed, complete robot kit to get you started in
building and programming!

2
Table of Contents
Introduction: Before You Begin ............................................................................................................................4
Chapter 1: Introduction to Electronics .................................................................................................................5
Electricity ..........................................................................................................................................................5
Resistors............................................................................................................................................................6
Understanding Voltage, Current, and Resistance.............................................................................................7
Circuit Symbols .................................................................................................................................................7
Breadboards .....................................................................................................................................................8
Building a Basic Circuit......................................................................................................................................9
Chapter 2: Basic Hardware Programming...........................................................................................................10
The Arduino Board..........................................................................................................................................10
Digital Input/Output .......................................................................................................................................11
The Light Emitting Diode (LED).......................................................................................................................13
Breadboarding to Prototype...........................................................................................................................14
Chapter 3: Introduction to C Programming ........................................................................................................15
The Basic Arduino Program ............................................................................................................................15
Constants and Variables .................................................................................................................................16
Control Statements.........................................................................................................................................19
Chapter 4: Assembling Your Gearbox.................................................................................................................25
Identification of the Gearbox Parts ................................................................................................................25
Assembly of the Gearbox................................................................................................................................30
Chapter 5: Building Your Basic Pi-Bot .................................................................................................................43
Mounting the Gearbox ...................................................................................................................................44
Installing Your Switch .....................................................................................................................................45
Setting Up Your Caster Wheel ........................................................................................................................47
Assembling Your Tires.....................................................................................................................................49
Mounting the STEM Board Microcontroller...................................................................................................51
Setting Up Your Battery Pack Slide.................................................................................................................54
Chapter 6: Wiring and Programming Your Basic Pi-Bot......................................................................................58
Basic Motor Wiring Schematic........................................................................................................................60
Wiring the H-Bridge........................................................................................................................................61
Making Your Pi-Bot Move...............................................................................................................................66
Chapter 7: Distance Sensor.................................................................................................................................70

3
Assembly.........................................................................................................................................................70
Wiring the Distance Sensor ............................................................................................................................73
Wiring the LEDs...............................................................................................................................................74
Programming the Distance Sensor .................................................................................................................76
Chapter 8: Line Tracking .....................................................................................................................................85
Line Tracking Sensor Assembly.......................................................................................................................85
Complete Pi-Bot Wiring Schematic.................................................................................................................87
Basic Line Following Program .........................................................................................................................89
Line Following –Advanced Programming ......................................................................................................93
Appendix A: Installing and Testing the IDE.........................................................................................................98
Preparing the Computer.................................................................................................................................98
Connecting the Arduino to the Computer....................................................................................................101
Testing the IDE..............................................................................................................................................105
Appendix B: Complete Pi-Bot Wiring Schematic ..............................................................................................110
Notes by the Team
We are excited to have you join us the Pi-Bot Adventure! STEM Center USA created the Pi-Bot to offer
users a holistic robotics experience where they could taste multiple fields of engineering. The Pi-Bot first
launched on Kickstarter in 2014 and is now used by individual users as well as high schools and colleges
worldwide.
What is the Pi-Bot?
The Pi-Bot kit is a multidisciplinary robotics experience intended for high school and college aged
students and above. It includes an introduction to mechanical, electrical, and computer science
engineering.
What makes Version 2.0 special?
We have upgraded our Pi-Bot! Some of our main updates includes:
Extra wires
Streamlined choice of fasteners (with a couple extras included!)
Longer motor wires for easier motor wiring
Zip-ties to clean up your Pi-Bot
How do these instructions vary from Version 1.5?
Version 1.5 uses different types of fasteners at various locations. It also places the breadboard on the
opposite side of the chassis for cleaner wire routing. The video tutorials for the gearbox assembly and all
wiring are the same for Version 1.5 and Version 2.0 –just watch out for the breadboard and fasteners
please! Version 2.0 Video Tutorials will be released by mid-October 2015.

4
Introduction: Before You Begin
Congratulations on purchasing your Pi-Bot Robot Kit! The Pi-Bot manual is meant to assist you in
building and programing. All of the instructions in this manual are designed to provide an easy step-by-
step method for every aspect of building your Pi-Bot, from start to finish. Make sure to take your time
and read through each lesson carefully. Pictures are included with every step for clarity.
This manual is for the Version 2.0 Pi-Bot which has minor changes from the Version 1.5.
Accompanying video tutorials can be found at:
http://www.stemcenterusa.com/pi-bot/tutorials-/
Before starting the assembly of your Pi-Bot, please check to make sure all necessary parts for your Pi-Bot
are included. Your kit should include the following items:

5
Chapter 1: Introduction to Electronics
Digital devices are widely used. Earlier, most electronic devices contained analog circuits which dealt
with continuously changing signals. Today, digital circuits are widely used. Personal computers and
smart phones are examples of digital devices that contain digital circuits. Digital devices use discrete
values which are zero (0) or one (1). The notation based on these two numbers is known as the Binary
system.
Electricity
The movement of electrons can be described by the analogy below:
The flow of water from one tank to another is a good analogy for an electrical circuit and the
mathematical relationship between voltage, resistance, and current. See Figure 1.1.
oForce: The difference in water levels (voltage)
oFlow: The flow of the water between the tanks (current)
oResistance: The valve that limits the amount of water (resistance)
Figure 1.1

6
Resistors
A resistor is an electronic component that resists the flow of electrical current. A resistor is typically
used to control the amount of current that is flowing in a circuit. Resistor converts electrical energy into
heat. Resistance is measured in units of ohms (Ω) and named after George Ohm, whose law (Ohm’s
Law) defines the fundamental relationship between:
Voltage - measured in Volts [V]
Current - measured in amperes [A]
Resistance - measured in ohms [Ω]
A resistor’s rating can be identified by its color “bands”. Refer to Figure 1.2 below.
Figure 1.2: Courtesy of DigiKey

7
Understanding Voltage, Current, and Resistance
Ohm’s Law: V = IR
Units:
Current (I) –Ampere
Voltage (V) –Volt
Resistance (R) –Ohm
Circuit Symbols
Below are basic circuit symbols that you should familiarize yourself with, as shown in Figure 1.4.
Figure 1.4
Be able to draw a circuit diagram for each circuit you create using the above symbols.
Figure 1.3

8
Breadboards
A breadboard is a reusable platform to quickly build and test electronic circuits. Breadboards are a
rectangular array of electrical contacts. Each contact in a row is electronically the same. See Figure 1.5,
below, for various breadboard sizes.
Figure 1.5
Each row is electrically the same. Figure 1.6 shows the back, disassembled view of the breadboard
where you can clearly see the rows. This means the voltage at any point along each row is the same.
Figure 1.6
Lighting up an LED

9
LED stands for light emitting diode. LEDs work like a one way street. They allow current to flow in one
direction only. The longer end of the LED is positive (anode) and the shorter end is negative (cathode).
An LED requires an appropriate resistor, based on the power supply, to drop the voltage. A simple LED
circuit is shown in Figure 1.7.
Figure 1.7
Building a Basic Circuit
The same circuit diagram is shown in Figure 1.8 but with the actual components. Compare this to the
symbols in Figure 1.7.
Figure 1.8
Understanding circuits is extremely important when wiring your Pi-Bot. Wire your own LED circuit like
the one in Figure 1.7 and Figure 1.8. You will have more practice and repetition in the following chapter.

10
Chapter 2: Basic Hardware Programming
The Basic Arduino Program
In this lesson, you will learn how to program the input/output ports of your STEM Board
microprocessor. The focus will be on functions needed for programming your robot. It is assumed that
you have a basic understanding of the C programming language, as described in Lesson 3: Introduction
to C Programming. After completing this lesson, you should be familiar with the digital I/O ports, the
analog-digital converter (ADC), and the pulse width modulator (PWM).
The Arduino Board
1. The STEM Board microprocessor and its features are shown in Figure 2.1. The functionality of
your STEM Board microprocessor is the same as an Arduino UNO Board.
Figure 2.1

11
2. The specifications for the STEM Board microprocessor are:
Microcontroller
ATmega328
Operating Voltage
5V
Input Voltage (recommended)
7 –12V
Input Voltage (limits)
6 –20V
Analog Input Pins
6
Digital I/O Pins
14 (of which 6 provide PWM output)
DC Current for 3.3V Pin
50 mA
Flash Memory
32 KB of which 0.5 KB used by bootloader
SRAM
2 KB
EEPROM
1 KB
Clock Speed
16 MHz
Digital Input/Output
1. After plugging the STEM Board microprocessor into your PC using the USB connector, you
should notice that the green LED power light is turned on. You do not need to plug in the 9-volt
battery at this point as the board is now powered from the USB port.
2. If everything looks good, enter and run the program: led_01.ino, as shown in Figure 2.2. The LED
on your STEM Board microprocessor for channel 13 (as shown in Figure 2.2) should be flashing.
Figure 2.2: Program –led_01.ino
3. As before, the program consists of two separate functions, setup () and loop ()
a. Note:
In the setup function, digital pin 13 is defined to an output pin.
Again, the loop function is the main program. The statement digitalWrite (13,HIGH);
is a function call to the digitalWrite. The first parameter is the pin number, as shown
at the top row of the STEM board microprocessor in Figure 2.1. The second
parameter, HIGH, is a predefined constant for 1. Likewise, LOW is a predefined
constant for 0.
Note that C is case-sensitive. Typing in High instead of HIGH will cause an error. That
is why HIGH is blue and High is black, reminding you that you are using predefined

12
constants. The use of predefined constants, such a HIGH and LOW, make the
program much more readable end easier to debug.
The delay is used to pause the program for 0.1 seconds.
Exercise 1
1. After you get the program: led_01.ino to run, modify it to:
a. Turn on the Board LED (digital I/O pin 13) and stay lit for 1 second.
b. After the 1 second, turn off for 0.1 seconds.
c. Repeat indefinitely.
2. We can use the predefined constants to make our programs easier to read. For example, pin 13
represents the board LED for our robot. We can make a global definition that Board_LED is 13,
as shown in Figure 2.3.
3. Beginner programmers are hesitant to use long descriptive variables. Typing Board_LED is more
time-consuming than typing 13, but program led_02.ino is much easier to understand than
led_01.ino. They do the exact same thing. So, make your programs as easy to read as possible.
Figure 2.3: Program –led_02.ino
4. Now that you understand the use of digital I/O, let’s connect our own LEDs to your STEM Board
microprocessor.

13
The Light Emitting Diode (LED)
1. LED is short for Light Emitting Diode and is shown in simple circuit in Figure 2.4.
Figure 2.4
2. The LED conducts electricity only in one direction. If the polarity of the diode is reversed, it will
not damage the LED, it will simply not emit light. What will damage the LED is too much current.
The LEDs included in the robot kit are .020 amps, commonly referred to as 20 ma (milliamps).
Therefore, a limiting resistor is needed in series with the LED, as shown in Figure 2.4.
3. Ohm’s Law is used to determine the current flow through the circuits:
I = 𝑉
𝑅or V = IR or R = = 𝑉
𝐼
V –the voltage across the component
I –the current flowing through the component
R –the resistance of the circuit
4. In circuitry, ohms is a unit of electrical resistance and is represented by the symbol Ω.
5. In our case, the LED will be connected on a digital I/O pin which has a HIGH output of 5 V. By
placing a 220Ω resistor in series, you are limiting the circuit through the resistor and LED to
about 20 ma. Let's connect the circuit shown in Figure 2.4 to your STEM Board microprocessor.
For this, we will need to use the breadboard.

14
Breadboarding to Prototype
1. The protoboard, commonly referred to as a breadboard, is used for prototyping electrical
circuits without needing to solder everything together. The term protoboard differentiates from
breadboards as protoboards typically require soldering while breadboard do not.
2. A diagram of the breadboard layout is shown in Figure 2.5.
Figure 2.5
3. Your mini breadboard has 170 connections arranged in groups of give, as shown in Figure 2.5
Any five connections within each group are electrically joined.
4. To connect the circuit shown in Figure 2.4 to the STEM Board, see Figure 2.6.
Figure 2.6

15
Chapter 3: Introduction to C Programming
This lesson assumes that the Arduino IDE is correctly installed on your computer and tested. If not, refer
to Appendix A to follow the installation process.
The Basic Arduino Program
1. Let’s start with a simple program, as shown in Figure 3.1. This is the same program referenced in
Appendix A.
Figure 3.1: Program - First.ino
2. The program consists of two separate functions, namely setup and loop.You will be adding
additional functions to your code, but you must have a setup function and a loop function in
every program that you write. Referring to the program, you should note:
The setup function is used to define certain parameters on the Arduino microprocessor.
In this example, the setup function includes the statement Serial.begin(9600); which
sets the communication speed of the serial port on the Arduino to 9600 baud. This will
allow the Arduino to communicate with the serial monitor on the PC. The () after the
name setup is the parameter list passed to the function. Since there are no parameters
being passed to the function, the list is empty. However, the () after the name is still
required. Following the function name is a {at the opening, and a matching }at the end
of the function. Everything between the first {and its matching }belong to the
function.
The // indicates that whatever follows is a Comment. Comments may begin in any
column. For example, one could write:
Serial.println("Hello World"); // used to print to a serial port
Use comments to help document the program.
The word void in front of the function names indicate that the functions are not
returning a value. We will discuss this more later.
void setup()
{
// Your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
// Your main code here, to run repeatedly:
Serial.println("Hello World");
delay(1000);
}

16
In the case of the function Serial.begin(9600), the name of the function is
Serial.begin and when called, the program passes the value of 9600, which in this case
is the baud rate (transfer rate) for the serial communication. For another example,
when the function Serial.println("Hello World"); is called, the string Hello World is
a parameter being passed to the communication port.
The semicolon ; terminates the command. It is required. Note that the function name
void loop() is not terminated by a ;. That is because the function name contains the
lines between the { and }and therefore cannot be terminated.
The function delay(1000); calls a delay function where the parameter list contains the
number of millisecond to wait. In this case, there is a one (1) second delay. Note that
when the program executes this command, it is literally waiting the specified time. If
something is happening, such as a sensor value has changed, the Arduino
microprocessor will not see it during the wait time.
The void loop() is the main function and it must be in every Arduino code that you
write. It is the entry point for your code. The loop function is executed continuously,
that is, when the program reaches the end of the loop function, denoted by the last },
the Arduino goes back to the top the of the loop function and begins execution again.
Exercise 1
After you get the “Hello Word” program to run, modify it to:
1. Print your first name
2. Wait ½ second
3. Print surname on the next line
4. Print a blank line
5. Wait 2 seconds
6. Repeat
If you have any difficulty with this exercise, ask your instructor for help.
Constants and Variables
1. Constants can be thought of as predefined variables that cannot change during the execution of
a program. There are two types of constants, which you will see in Figure 3.2:
a. User defined constant
b. Predefined constant
2. Don’t be overwhelmed by the lengthy of the program. It is mostly print statements. We will see
shortly how we can reduce the number of lines to do the same thing.
3. Review the program in Figure 3.2. Then we will analyze it in the next steps.

17
Figure 3.2: Program - Second.ino
#define var1 1
int const var3=1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
const int var2 = 1;
int var4;
int var5=1;
boolean var6=false;
var4=1; // The value of c4 is now defined
Serial.print("var1 = ");
Serial.print(var1,DEC);
Serial.print(" var2 = ");
Serial.print(var2,DEC);
Serial.print(" var3 = ");
Serial.print(var3,DEC);
Serial.print(" var4 = ");
Serial.print(var4,DEC);
Serial.print(" var5 = ");
Serial.print(var5,DEC);
Serial.print(" var6 = ");
Serial.println(var6, DEC);
//var3++;
var4++;
var5++;
var6=true;
Serial.print("var1 = ");
Serial.print(var1,DEC);
Serial.print(" var2 = ");
Serial.print(var2,DEC);
Serial.print(" var3 = ");
Serial.print(var3,DEC);
Serial.print(" var4 = ");
Serial.print(var4,DEC);
Serial.print(" var5 = ");
Serial.print(var5,DEC);
Serial.print(" var6 = ");
Serial.println(var6, DEC);
Serial.println(" ");
delay(1000);
}

18
4. You have two required functions: setup () and loop ()
5. We have added #define var1 1 to the first line of the program. This var1 is now a user defined
constant that cannot be changed .This also has a global definition, that is, var1 is equal to 1 for
all the functions. If you try to redefine var1,you will get a compile error. Another method to
define the var1 as a constant global variable will be to place the statement int const var1
before the first function call.
6. var2 is also a constant defined to be 1. However, it is local to the function loop (). Therefore, it
is not available in any functions.
a. Note: If the variable name var2 is used in another function, it will be a unique variable
that is local to that function.
7. var3 is a global integer variable because it is typed before the first function call.
8. var4 and var5 are integer variables and can be changed anywhere within the function. They
are local variables and their scope is limited to the function that they are defined (typed) in. Run
the programs and watch how the variables change as the programs are executed. The purpose
of the program is simply to print the values of each variable, then increment the variables using
the ++ command and print the values again.
9. Repeat the loop every 1 second. Make sure that you open the serial monitor after the program
is completely downloaded. As you can see, the constants var1 and var2 do not change.
10. For fun, try to change their values in the code and see what happens.
11. The value of var3 increments continuously, as it is a global variable and is not reset upon
successive loops. The values of var4 and var5 are local variables and get re-initialized at the
beginning of each loop. The only difference between var4 and var5 is that var5 is initialized
when it is typed. var4 is not, so it needs to be assigned a value prior to using it.
a. Note: Non-constant variables are referred to as variables, and constant variables are
referred to as constants.
12. var6 is a Boolean variable, which is often used with the predefined constants:
a. “True” defined as 1
b. “False” defined as 0
13. Be sure to look at the code and its output to help understand the use of the Boolean variables.
14. We will discuss integers, Booleans, and other variables in more detail later. For now, let’s take a
look at some control statements in the next section.

19
Control Statements
1. The control statement is used to control the flow of the program. In this section we will be
addressing three of the commonly used control statements:
a. if statement
b. for statement
c. do while statement
2. The form of the if statement is as follows:
3. Note that both the else if and else statements are optional.
if(logical test)
{
statements are executed if logical true.
}
else if(logical)
{
statements are executed if the first logical is false and the
second logical is true.
else
{
statements are executed if none of the above logical are
true. This is the default condition.
}

20
4. Let’s do the example as shown in Figure 3.3.
Figure 3.3
5. Things to note about the if statement in the example:
a. The logical test is == not just =. A single = is an assignment statement.
b. In the statement var1 = 1, the value of 1 is assigned to the variable var1. In the
statement var1 == 1, the value of var1 is compared to the value of 1 and returns a
“true” if the values are equal and “false” if the values are not equal.
6. Take a few minutes to change the value of var1 in the example to see what happens to the
value of var2. Does the output make sense?
7. The logical operators are:
a. == test if equal
b. != test if not equal
c. < test if less than
d. > test if greater than
e. <= test if less than or equal to
f. >= test if greater than or equal to
void setup()
{
Serial.begin(9600);
}
void loop()
{
int var1, var2;
var1 = 1;
var2 = 1;
if( var1 == 1)
{
var2 = 2;
}
Serial.print("var1 = ");
Serial.print(var1, DEC);
Serial.print(" var2 = ");
Serial.println(var2, DEC);
Serial.println(" ");
delay(1000);
}
Table of contents