You are on page 1of 27

!

eBot
Build Program Learn

Robot
Handbook
ebotx.co.uk

The eBotx is a programmable robot designed by East


Barnet School to teach basic electronics and
programming. After following this booklet, you will learn
how to assemble simple circuits and hardware. You will
learn how to program simple step-by-step instructions as
well as more advanced feedback control.

The eBotx utilises the Arduino Nano micro controller. It is


an open source controller board (for more information see
www.arduino.cc).

The eBotx has two independently controlled, gear boxed


motors for driving. It also has an Ultrasonic Distance
Sensor, a Microswitch, two Infrared Encoders and a few
expansion ports for other hardware.

This booklet takes you though the steps


of assembling and programming your
eBotx. There is a list of parts that
should be in the kit, check that
everything is there before you
start! If there is
anything missing,
contact the person
who supplied you
with the kit.

!
!

ii

Contents

How does it all work?

!
Parts

!
Building Instructions

!
Programming Instructions

12

Tasks

13

Programming Using Flow Codeo

14

Programming Using Ardunio Software


15

eBotx Library

18

iii

How does it all work?


Arduino Nano
The Arduino Nano is a board made by Arduino. It is a
programmable micro-controller. Code written on a
computer is uploaded to the Arduinos internal memory
via a USB cable, this code is then run by the board which
controls various inputs and outputs.

Microswitch
A microswitch is a component that allows collision
detections. When the lever arm is depressed, the circuit is
broken; stopping the flow of electricity. This
interruption can be detected by the eBotx.

Ultrasonic Distance Sensor


This ultrasonic distance sensor is the most advanced
sensor used in this project. An ultrasonic pulse is sent by
the sensor, a timer is then started on the Arduino. The
pulse will bounce off an object in front of the eBotx .
When the reflected pulse is detected by the
sensor, the timer is stopped. The Arduino
then calculates the distance from the
object based on the time taken and the
speed of sound (340ms-1).

Encoder Board
The Encoder board uses a Infrared LED
and Infrared receiver to detect when an
object is in front of it. When the wheel
spoke is in front of the Infrared Distance
Sensor, the light from the LED is reflected
back onto the receiver. The when the
receiver detects a lot of reflected Infrared light, the eBotx
1

Parts

Chassis

Ultrasonic
Distance
Sensor

Microswitch

Motor Holder

2 x Encoder Board

2 x Wheel
2

Main Board

2 x Motor

2 x Tyre

!
!

4 x M4 Spacer

5 x M4 Bolt

3 x M3 Nut +
Spacer + Bolt

2 x Wheel
Screw

Castor Ball

Capacitor

3

6 x M4 Nut

4 x Wheel
Spacer

Building Instructions
Before you can program the eBotx, you need to build it.
The next few pages will give step-by-step instructions on
how to build the eBotx. The names used for each part can
be seen on the the Parts page

Step 1 Main Board onto Chassis


Use three M3 Nuts, M3 Bolts and M3 Spacers to secure the

Main Board onto the Chassis

4

Step 2 Motors onto Motor Holder

Slide the Motors into the Motor Holders so they are


vertical.

M4 Bolt
M4 Nut

Castor Ball

5

Step 4 Motor Holder onto Chassis


Use four M4 Bolts, M4 Nuts and M4 Spacers to attach the
Motor Holder onto the Chassis. Place the M4 Spacers
between the Motor Holder and the Chassis.

M4 Bolt
M4 Spacer
M4 Nut

6

Step 5 Wire Motors into Main Board


Run the four wires under the Chassis and through the slot
in its rear. Then screw the wires into the four screw
terminals on the rear of the Main Board.

7

Step 6 Attach Wheels onto Motors


Place a Wheel spacer over the Motor axle, then the Wheel
and then another Motor Spacer, secure these in place
using a Wheel Screw. Repeat for the other Motor. Place the
Spacer

tyres over the Wheels.


Wheel

Wheel Wheel
Spacer Screw

8

Step 7 Slot Encoders onto Main Board

9

Step 8 Slot Microswitch onto Main Board

Slot the Microswitch onto the front of the Main Board.

10

Step 10 Wire Battery Holder onto Main Board


Slot the Battery Holder into the Chassis, then screw the
red wire into the leftmost screw terminal on the Main

Board. Screw the black wire into the screw terminal next
to it.

11

Programming Instructions
This section of the booklet will teach you everything you
need to know about programming your eBotx. The robot
uses the Arduino micro controller so if you already know
about programming using an Ardunio then you can skip
ahead to the Programming with Arduino Software part of
this section.
The Arduino microcontroller is programmed using the
Arduino programming language and the Arduino
development environment. To control the eBotx, you can
either write code using the Arduino development
environment or Flow Codeo - flow charting software
specifically designed for use with the eBotx
(recommended for beginners).
Whichever method you choose, it is necessary to
download and install the Arduino software. To do this visit
the Arduino website:

arduino.cc
Navigate to the download page and choose the right
software for your operating system (Mac, Linux or
Windows). There are more detailed instructions on the
Arduino website if you encounter any problems.
We have provided a series of tasks that we suggest you
complete to develop your confidence with the eBotx. Use
the Programming using Flow Codeo or Programming with
Arduino Software instructions to help you complete these
tasks.

12

Tasks
It is recommended that you complete each of these tasks
to guide your learning with the eBotx. If you are a
beginner; use the Flow Codeo online software to help
program theeBotx.

Task 1
Drive forward - for 5 seconds - stop

Task 2
Drive forward - for 5 seconds - reverse - for 5 seconds

Task 3
Drive forward - for 5 seconds - spin - for 1.8 seconds loop the program

Task 4
( Drive forward - Until you hit a wall ) - reverse

Task 5
( Drive forward - Until you hit a wall ) - reverse - spin for 2.4 seconds - loop the program

13

Programming using Flow Codeo


Flow Codeo is an online development platform specifically
designed for use with the eBotx. It breaks down coding
into simple flow chart style blocks. You can see the code
each block generates and you go to help develop your
understanding. When you have finished your flow chart,
you can download it as an Arduino sketch (.ino file) which
can be opened in the Arduino software and uploaded to
your eBotx.

The Website
Flow Codeo is an online development tool which means
you dont have to download any specific software to use it.
You just to go to:

flowcodeo.co.uk
Choose eBotx front the menu. You will need to login to
the website using the credentials printed on a separate
sheet in this box.
Once you have logged in, you can begin programming.
Use the intuitive drag and drop interface to control the
eBotx.

Programming the eBotx


Once you have completed your code. Press the Export
button on the menu bar. You can now download your
code as an .ino file.
Once downloaded, open the file using the Arduino
software.
Under the Tools > Board menu, make sure that the
Nano w/ATmega328 is selected.
14

Under the Tools > Serial Port menu, make sure that the
correct serial port is selected (usually trail and error!)
Now press the

upload button to program you eBotx.

15

Programming with Arduino


Software
The best way to program an Arduino is using the Arduino
development environment. The Arduino is programmed in
the C language (search C on the internet for more
information). The first part of this section will go over the
specifics of programming for Arduino. If you are familiar
with other C based languages (like java, C++, PHP etc.)
this will give you all you need to know to get started.

arduino.cc
will give you a much better introduction and it is well
worth having a look at.
Once you have written the program follow the steps in the
Programming the eBotx part of the Programming with
Flow Codeo section.

Structure
Arduino programs are often called sketches and have
the .ino file extension. For the program to compile, you
must have the two required functions:
void setup{ }

and
void loop{ }

Void loop is used to setup the various inputs and outputs


of the Arduino. It is run once and the beginning of the
program. Void loop is then run continuously.

16

Syntax
Syntax is a very important part of the C Programming
language, if you use incorrect syntax your program wont
compile properly (which means it won't work!)
// a single line comment
/* a multi-line
comment */
{ } (curly brackets) are used to define when a block of code
starts and ends (like an if statement or a function).
; a semi-colon is used to end a line. Every line of code must finish
with a semi-colon. This is the most common error when
compiling a program.

Variable Data Types


Variables are used to store information, different data
types are used to store different types of information.
int - integer variable (an integer number between -32768 and
32767)
long - long variable (an integer number between -2,147,483,648
and 2,147,483,647)
boolean - boolean variable (a simple true or false statement)
float - floating point variable (for decimal numbers between
3.4028235E+38 and 3.4028235E+38)
char - character variable (one character using ASCII values )

Arithmetic Operators
These are used to do maths within the Arduino
environment.
= - Assignment operator (eg. A = 4+3; //so A is now 7)
+ - Addition
- - Subtraction

17

* - Multiplication
/ - Division
% - Modulo (calculates remainder when one number is divided
by another. eg. x = 7 % 5; //x is now 2)

Comparison Operators
These are used when comparing operands (like in a if/for
statement)
== - Equal to
!= - Not equal to
< - less than
> - greater than
<= - less than or equal to
>= - greater than or equal to

Control Structures
If statement:
if(condition){
command();
} else{
another_command();
}

For statement:
for(int i = 0; i < repeats; i++){
command();
}

18

19

eBotx Library
The eBotx library has been written to let you easily
interact with your eBotx hardware within the Ardunio
programming environment. To use the library you first
have to install it. You can download the library from:

ebotx.co.uk
Then open your Arduino software and go to Sketch >
Import Library > Add Library and select the library
you just downloaded.
The library contains functions to control the various input
and outputs on the eBotx. To use the library in your
sketch you must include it at the top of your Arduino
sketch like this:
#include <EbotX.h>

To use the various inputs and outputs we have to define


them at the beginning of our sketch. The definitions for
the motors and sensors are:
Motor motorLeft(A);
Motor motorRight(B);
DistanceSensor distSense;
MicroSwitch mswitch;

When defining our motors and sensors the label is user


definable, for example distSense is an instance of the
DistanceSensor class. The instance label is arbitrary so
you could replace sensor1 with whatever name you like.
Once defined you can use various functions relating to
each device.
20

Motor Functions
The functions for the motors enable you to control their
speed and count the number of rotations of each wheel
(useful for distance calculations).
Forward:
motorLeft.forward(speed);
motorRight.forward(speed);

speed can be any integer value between 0 and 255.


Reverse:
motorLeft.reverse(speed);
motorRight.reverse(speed);

speed can be any integer value between 0 and 255.


Stop:
motorLeft.stop();
motorRight.stop();

Tip: If the ebot isnt driving in a straight line, try setting


one of the motors to be slower than the other one to
compensate!
Wheel Encoders:
int x = motorLeft.distance();

distance() will return an integer number which is a count


of how many times the wheel spoke has passed the wheel
encoder.
int x = motorLeft.resetDistance();

21

resetDistance() will set the distance() count to 0.


int x = motorLeft.checker();

checker() will return 1 when it detects a wheel spoke and


0 when it doesnt.

Micro Switch
There is only one function for the micro switch; read().
This is a boolean function and returns 1 when the switch
is pressed and 0 if not.
x = mswitch.read();

Distance Sensor
The distance sensor read() function will return the
distance of an object in front of it in cm as a long
number.
y = distSense.read();

Example Program 1
Here is an example program showing how to use some of
the functions in the eBotx library. This simple program
will make the eBotx drive forward in a straight line until it
hits a wall, then it will reverse until it is 10cm from the
wall and stop:

22

#include <EbotX.h>
Motor motorLeft('A');
Motor motorRight('B');
DistanceSensor distSense;
MicroSwitch mswitch;

!
!

int toggle = 0;
void setup(){
/*nothing to setup*/
}

!
void loop(){
if(mswitch.read() == 1 && toggle == 0){
motorLeft.reverse(255);
motorRight.reverse(255);
toggle = 1;
} else if(distSense.read() > 10 && toggle == 1){
motorRight.stop();
motorLeft.stop();
} else{
motorRight.forward(255);
motorLeft.forward(255);
}
}


23

Example Program 2
This program will drive the eBotx forward for 1000ms (1
second), then rotate the right wheel for 10 encoder
counts:
#include <EbotX.h>
Motor motorLeft('A');
Motor motorRight('B');

void setup(){
/*nothing to setup*/
}

!
void loop(){
motorLeft.forward(255);
motorRight.forward(255);
delay(1000);
motorLeft.stop();
motorRight.stop();
motorRight.resetDistance();
while(motorRight.distance() < 11){
motorRight.forward(255);
}
}

24

You might also like