Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
www.STEMCenterUSA.com 1
Contents
I. Installing miniBloq (windows) .............................................................................................. 4
II. Getting started with the Pi-Bot .............................................................................................. 5
III. Programming Pi-Bot using miniBloq .................................................................................... 8
IV. Making your robot move ..................................................................................................... 16
V. Ultrasonic Sensor ................................................................................................................. 19
VI. Line Following ..................................................................................................................... 24
VII. Reference ............................................................................................................................. 28
www.STEMCenterUSA.com 2
MiniBloq
About miniBloq
MiniBloq is one of the first graphics programming environment developed
for Arduino. MiniBloq provides an excellent environment for learning
Arduino C. The system displays C codes dynamically as the program is
developed using icons. Another important feature of miniBloq is that coding
can be done in C or Python in traditional text format. The ability to switch
between languages along with icon-based programming makes it a powerful
learning tool. Julin da Silva Gillig from Argentina created miniBloq. STEM
Center USA has partnered with Mr. da Silva and adopted miniBloq to work
with the STEM Board.
www.STEMCenterUSA.com 3
I. INSTALLING MINIBLOQ (WINDOWS)
To download miniBloq, go to the link: http://www.stemcenterusa.com/pi-bot/downloads-/
Please download the miniBlog installer file, miniBloq.v0.82.PiBot.Win.exe. Double click on this file
and it installs the miniBloq software and creates a shortcut on your desktop. You must have
administrative rights to install the software. To do that, right-click on the file and choose Run as
administrator from the contextual menu there, as shown in the image below.
Installation will create an icon for miniBloq on the desktop. Double click) miniBloq icon shown to
start the program.
www.STEMCenterUSA.com 4
II. GETTING STARTED WITH THE PI-BOT
MiniBloq supports the STEM Board (Arduino compatible). When you open miniBloq, Pi-Bot is
already selected for you. Make sure you connect your Pi-Bot using the USB cable to the computer
and wait for a few seconds. Then choose the appropriate com port from the pull down menu. You
will get a screen display which may look like as shown below:
The left hand side area shows the STEM board. The right area is meant for miniBloq graphics
programming. MiniBloq has the ability to dynamically generate the C code as you program using
icons. This is a great learning tool. In order to see the generated code, please select View from the
top menu and then choose Generated Code. Now the right area shows the C code generated
dynamically as you program using icons. Refer to the figure below.
www.STEMCenterUSA.com 5
Understanding STEM Board Layout and Pin connections
The default pin connections used in the sample programs uses the following configuration. If you
are a beginner, use default values as shown in the STEM Board diagram. The following diagram
shows all pin connections. Just familiarize yourself but do not wire them yet. We will do this in the
next section starting with a LED.
www.STEMCenterUSA.com 6
Motor wiring
Pin 3 connects to one of the two dc motors. Let us call this A motor (or motor0). AIN1 stands for
one of the leads (top) from A motor
Pin 5 connects to the second lead of A motor. AIN2 stands for second lead (bottom) from the from
A motor
Pin 6 connects to the second dc motor. Let us call this B motor (or motor1). BIN1 stands for one
of the leads (top) from B motor
Pin 11 connects to the second lead of B motor. BIN2 stands for second lead (bottom) from the
from B motor
LED wiring
Pin 13 connects to the anode of an LED
Buzzer
Pin 12- one of the leads of the buzzer
IR Sensor
Pin 4 not included in basic Pi-Bot
www.STEMCenterUSA.com 7
III. PROGRAMMING PI-BOT USING MINIBLOQ
Programming in miniBloq is done using icons which can be selected from the action blocks menu and
putting them together like a flow chart in the graphics programming area. Each miniBloq program
begins with the Start icon (initBoard initializes the board) shown below.
In order to light up an LED, we are going to use pin 13. Take any regular LED. Let us say, we will use
the Green LED. The Green wire indicates positive and black wire indicates negative. You will have to
use a resistor in order to connect an LED. Use the small breadboard and complete the following
wiring. A 5-band 330 ohm resistor (Orange-Orange-Black-Black-Brown) included in your kit is
shown below.
www.STEMCenterUSA.com 8
Below is a schematic diagram of your wiring.
Flow Diagram
Once you have wired your LED, we can write the program. The program begins with the initBoard
block. This block is already placed in the programming area as the initial start block.
Our goal is to light up an LED which is connected to Pin 13. On the STEM Board, digital pins can be
set to LOW (0 V) or HIGH (5V). To define an LED connected to pin 13, we can use the I/O Pin block
(two horizontal arrows pointing in opposite direction). Click on the I/O pin block and it will
automatically attach itself under the initBoard block as shown below.
www.STEMCenterUSA.com 9
Notice the RED arrow pointing left. Keep an eye for this red arrow as you will see this option in
various blocks on the right side. Clicking on the red arrow opens a configuration window which has
numerous parameters to choose from. Some of the options include true, false, greater than, less
than, etc. to choose from the pop-up menu. The following diagram choose the option available when
you click on the red arrow.
Click on the RED arrow and choose True as we want to light up an LED. Choosing True will set the
pin to high. To complete this step, choose appropriate digital pin form the pull down menu. Let us
choose Pin 13. So pin 13 is now high. To make it low, we have to set the parameter to false. Your
program should look like this.
www.STEMCenterUSA.com 10
Thats it. Congratulations! You have completed your first miniBloq program. Choose Run
from the component menu or from the tool bar, and watch your LED lighting up.
Exercise 1: In the last activity, we lighted up one LED. Can you light up two LEDS. Dont forget to
include a dropping resistor in your circuit.
Anything placed between the recycling arrows will be repeated while the condition is true. To select
the condition, click on the red arrow and choose true as you have done before and your program
will now look like as follows:
Our goal is to blink the LED connected to Pin 13. We will use the I/O pin block as before and the
resulting diagram should look as follow:
www.STEMCenterUSA.com 11
Select the appropriate pin (in this case, we will choose D_13LED) from the pull down menu and
choose True condition. Your final program will now look like as shown below:
Now let us add a wait command. Wait block is described by a clock icon. Choose this icon. Since the
wait command is about time, the red arrow now looks for time in milliseconds (1000 milliseconds =
1 second). Click on the left arrow and choose # to specify time and type in 400. This means we want
the LED to be on for .4 seconds (400 milliseconds).
www.STEMCenterUSA.com 12
To blink an LED, we have to switch it on and off. Now that the LED is on, let us use another the I/O
pin block to turn it off. If you run this program, the LED will still lights up but there is no blinking. It
is because we switch off the LED momentarily but it turns on very quickly because of the loop. To
make sure it is off for a time that we can observe, we will use another wait block and set it to 0.4
seconds again. The final program is shown below:
Congratulations! You have completed your blink program using miniBloq. Run the program
and you will see your LED will blink. Dont forget to save your program. To save your program,
go to file menu and choose Save All option.
www.STEMCenterUSA.com 13
Note: Inserting blocks
If you want to insert a block between two existing blocks, use your mouse to select the block in your
programming space where you want to insert new block to go below. Then click on the action block
on the right side of your window. This will insert the action block into your programming space,
below the originally clicked block. If you made a mistake, you can drag and drop the block anywhere
within the program.
C Program
Notice on the right hand side, as you select icons and create your graphics program, C codes are
dynamically generated. Take a look at the code if you want to learn C programming language, or you
can close this area by selecting the Generated Code option from the View menu option.
www.STEMCenterUSA.com 14
Exercise 1: Traffic light
Write a program to simulate a traffic light using 3 LEDs.
www.STEMCenterUSA.com 15
IV. MAKING YOUR ROBOT MOVE
Wiring the motors
Motor wiring is explained in the section, Making Your Pi-Bot Move in the manual, which can be
downloaded from the following link:
http://www.stemcenterusa.com/pi-bot/downloads-/
However, please note that the there is a minor change in the wiring. Pins 3 and 5 are swapped
in miniBloq. If you do not make this change your robot will spin instead of going forward. The
wiring diagram is shown below.
MiniBloq has a motor icon (two gears) to represent motors. Pi-Bot uses two dc motors. In miniBloq,
motor connected to pin 3 & 5 is named as motor 0 (also A motor as noted in the STEM Board pin
configuration). Motor connected to pin 6 & 11 is named as motor 1 (also B motor as noted in the
www.STEMCenterUSA.com 16
STEM Board pin configuration). Below is the sample program for making the Pi-Bot move. Notice
the motor block and how the values are added to define the power level in the motor. Motor power
values range from -100 to +100 in miniBloq. This means, for reverse, you have to enter the power
level with a negative sign. To specify negative value choose the modifier, -(X).
This program runs only once. Your robot goes forward and backward just once and then stops. If
you want your robot keep doing this again and again, you would have all this code inside a while
loop block.
www.STEMCenterUSA.com 17
Note: If the motor is not running, check the wiring properly. You might have swapped the
connections.
Exercise 2: Square
Write a program to make the robot go in a square.
www.STEMCenterUSA.com 18
V. ULTRASONIC SENSOR
Assemble your ultrasonic sensor using the section, Distance Sensor in the accompanying manual.
Wire your sensor exactly as mentioned. Trigger Pin of your sensor goes to STEM Board digital pin 7
and the echo pin of your sensor goes to STEM Board pin 8.
To display we use the terminal option. To show the terminal, please go to the menu view->Terminal
or press Alt + T. However, you will have to use the Open button to see the results. See the figure
below for a view of the terminal.
Once we have the serial monitor block selected, to get the readings from the ultrasonic sensor, we
will define the input to serial monitor as number and that the numbers (readings) come from the
ultrasonic sensor. Make sure you choose the correct ultrasonic sensor (HC-SR4). Sample code is
given below:
www.STEMCenterUSA.com 19
Obstacle Avoidance Using Ultrasonic Sensor
Once you tested the ultrasonic sensor and the motors, you are now ready to program your robot to
move around while not hitting any objects. In order to prevent accidents, you must constantly
watch your ultrasonic sensor reading and take appropriate action when the object is too close.
One option is when the distance from an object is less than a predefined value, the robot should
back up and turn. In order to do that we will need to define two variables, the minimum distance
you want to maintain between the robot and the object, and the speed of the motors. Notice the
icons for creating new variables. Below is the sample code which shows how three variables are
defined. Motor speed is set to 75 and minimum distance is set to 15 cm.
The next step is to introduce the while loop as we want our robot to be wandering around without
stopping. We now want to get the readings from the ultrasonic sensor and compare the result with
the minimum distance we want to maintain. If the distance is greater than the minimum, then the
robot can move forward. If not go back for and then turn. If is a conditional statement and we will
www.STEMCenterUSA.com 20
use this statement now. If statement is defined by a block with a question mark. Since if statement
compares a condition, there are two parameters that need to be defined. One of them (the top one)
is the input from the ultrasonic sensor and the second is the minimum distance which is defined as
15 cm). See example below for the if statement inside the while loop.
Finally if the obstacle is far away (condition is true meaning the distance from the sensor to the
object is greater), then the robot must go forward. We can achieve this by making both motors to
run at the specified speed. These blocks are self-explanatory. If the not, then the corresponding
motor blocks below the false option. See the sample code with explanations below.
www.STEMCenterUSA.com 21
Study each part of this code and understand how it works. The complete code is given below. It is
broken into two parts for the purpose of display only. Second part goes right at the end of first part.
You can download this program from our website.
www.STEMCenterUSA.com 22
Part 1 Part 2
www.STEMCenterUSA.com 23
VI. LINE FOLLOWING
Line following is a very important and fun activity. Many real world system including
robots performing warehouse operations use line following activities. Speaking of
warehouse operations, it may be interesting to know that not too long ago, Amazon paid
almost a billion dollar for Kiva System, a company that makes robots for warehouse
operations. These Kiva robots are strong and silent. They replace the use of humans with
forklifts. These robots use pretty much all techniques our students learn and more: going in
a straight line, turning, machine vision, line following, obstacle avoidance, dead reckoning
and bar code reading. For a day in the life of Kiva Robot, take a look at the following video:
http://www.youtube.com/watch?v=6KRjuuEVEZs
There are several competitions focusing on line following. You can use one, two, three or
even more sensors for line following. In this lesson, we will be using three light sensors.
Connect five (5) 30cm wires to the line sensor array as follows:
VCC Red
L Yellow (Sensor on the left)
C Green (Sensor at the center)
R Blue (Sensor on the right)
GND Black
After connecting the wires to the pins, attach the line sensor to the two nylon (1) spacers
using two 4-40 x screws as shown in the diagram below:
www.STEMCenterUSA.com 24
Figure below show the view of the robot from the underside showing the line sensor
wiring.
This block converts the Boolean data coming from the IO readings to a number (0 for false
and 1 for true) from light sensors so the readings can be stored in a numerical variable.
www.STEMCenterUSA.com 25
Part 1 Part 2
www.STEMCenterUSA.com 26
Download and run the following program:
Part 1 Part 2
www.STEMCenterUSA.com 27
VII. REFERENCE
Action Blocks
Image Name Description Type
Every miniBloq program starts with a start
Start none
block
Block will execute when some conditions is
While loop condition: Boolean
true
This is same as while block but will execute
While loop iteration count
specified number of times
If Conditional statement decision making condition: Boolean
Variable
Create and initialize a new variable value: number
(create)
variable This block allows to assign a value to the
value: number
(assign) selected variable.
This block allows to control the state of a
I/O pin value: Boolean
digital pin
This block allows to control an analog pin
Analog value: number
(PWM)
value: terminal method
Terminal block: It lets a program to send
Terminal (to print text or
numbers or text through the serial port
number)
Terminal
This blocks enables the terminal block to send
number value: number
a numerical value though the serial port.
method
Terminal text This blocks enables the terminal block to send
value: text
method a text though the serial port.
This block allows to emit sounds. The first note (Hz): number
Buzzer
parameter sets the frequency (note) and the
(setter)
second sets the duration. duration (ms): number
This block allows to control an electric motor
power (-100 to 100):
Motor (setter) connected to one of the controller's motor
number
outputs.
This block allows to set the position (in
ServoRC
degrees) of an R/C Servo connected to the angle: number
(setter)
board.
www.STEMCenterUSA.com 28
Allows to insert code directly in the program,
Insert Code allowing for text programming inside a none
graphical program
www.STEMCenterUSA.com 29
number
This block returns a constant number. none
(constant)
value2: number
This block allows to add numbers, variables
Add
and other arithmetic expressions. Note: More operands
(values) can be added
with the add param
button.
value1: number
This block allows to substract numbers,
Substract
variables and other arithmetic expressions.
value2: number
value1: number
value2: number
This block allows to multiply numbers,
Multiply
variables and other arithmetic expressions. Note: More operands
(values) can be added
with the add param
button
This block allows to divide numbers, variables numerator: number
divide and other arithmetic expressions. It also lets
you to write numbers as fractions. denominator: number
negative
This block makes negative the number or the
(unary value: number
arithmetic expression at its left.
minus)
value1: number
modulo This block returns the remainder of the
(remainder) division between it's 2 parameters.
value2: number
www.STEMCenterUSA.com 30
This block returns the minimum of two value1: number
minimum numbers, variables or other arithmetic
expressions. value2: number
fromLow: number
This block allows to map linearly a numerical
map value from a range of values (fromLow to fromHigh: number
fromHigh) to another range (toLow to toHigh).
toLow: number
toHigh: number
x: number
This block allows to limit a number, variable
or any other arithmetic expression to a value
constrain a: number
between a minimum (a) and a maximum (b).
b: number
This block converts a Boolean value (true or
bool to
false) into a numerical value (1 or 0, value: bool
number
respectively)
This block returns the sine of the angle given
sine by the number or the arithmetic expression at value: number
its left (in radians).
This block returns the cosine of the angle
cosine given by the number or the arithmetic value: number
expression at its left (in radians).
www.STEMCenterUSA.com 31
This block returns the number obtained from
IRRemote none
an infrared remote control sensor.
true
This block always returns "true". none
(constant)
false
This block always returns "false". none
(constant)
value1: number
This block allows to compare numbers, and
equal
returns "true" if these are equal.
value2: number
value1: number
This block allows to compare numbers, and
not equal
returns "true" if these are not equal.
value2: number
This block allows to compare numbers (or
value1: number
arithmetic expressions), and returns "true" if
less than
the first parameter (value 1) is lower than the
value2: number
second one (value 2).
www.STEMCenterUSA.com 32
This block allows to compare numbers (or
value1: number
arithmetic expressions), and returns "true" if
greater than
the first parameter is greater than the second
value2: number
one.
This block allows to compare numbers (or
value1: number
less than or arithmetic expressions), and returns "true" if
equal the first parameter is lower or equal to the
value2: number
second one.
This block allows to compare numbers (or
value1: number
greater or arithmetic expressions), and returns "true" if
equal the first parameter is greater or equal to the
value2: number
second one.
value1: Bool
value2: Bool
This block makes a logical (Boolean) "AND"
and
and returns the result. Note: More operands
(values) can be added
with the add param
button
value1: Bool
value2: Bool
This block makes a logical (Boolean) "OR" and
or
returns the result. Note: More operands
(values) can be added
with the add param
button
value1: Bool
This block makes a logical (Boolean)
xor
"Exclusive-OR" (XOR) and returns the result.
value2: Bool
www.STEMCenterUSA.com 33