Educational Robitics With Halocode- Summarised Edition.pdf (1) .PDF(副本)
Educational Robitics With Halocode- Summarised Edition.pdf (1) .PDF(副本)
Educational Robitics With Halocode- Summarised Edition.pdf (1) .PDF(副本)
with
Halocode
by
makeblock
Summarised Edition
3
Ernesto Martínez deCarvajal Hedrich
www.emchtechbooks.com
Educational Roboticswith
Halocode
by makeblock
Summarised Edition
5
PROLOGUE
7
Table of Contents
1.- Introduction................................................................................13
1.3.- What is Makeblock?......................................................................... 13
1.3.1.- Maker line....................................................................................13
1.3.2.- Neuron......................................................................................... 16
1.3.3.- Codey Rocky.............................................................................. 18
1.3.4.- Halocode..................................................................................... 22
1.4.- On line suppport................................................................................22
1.5.- Focus ofthe book..............................................................................23
1.5.1.- STEAM Philosophy.................................................................... 24
1.5.2.- Teaching in Robotics................................................................. 25
1.5.3.- Teaching with robotics...............................................................25
2.- Halocode components............................................................ 26
2.1.- Integrated sensors in Halocode...................................................... 26
2.1.1.- Button.......................................................................................... 26
2.1.2.- Touch sensor.............................................................................. 26
2.1.3.- Sound andvoice sensor............................................................ 27
2.1.4.- Gyroscopic and accelerometer sensor....................................27
2.1.5.- Connection pins..........................................................................28
2.2.- Additional sensors............................................................................ 29
2.2.1.- Potentiometer............................................................................. 31
2.2.2.- Light sensor................................................................................ 31
2.2.3.- Temperature sensor.................................................................. 32
2.2.4.- Soil moisture sensor.................................................................. 32
2.2.5.- PIR sensor.................................................................................. 33
2.2.6.- Flame sensor.............................................................................. 33
2.3.- Actuators integrated in Halocode....................................................34
2.3.1.- RGB LED.....................................................................................34
2.4.- Additional actuators..........................................................................34
2.4.1.- Buzzer..........................................................................................34
2.4.2.- Relay............................................................................................35
9
2.4.3.- Fluid pump.................................................................................. 36
2.5.- Comunication.................................................................................... 37
2.5.1.- USB connector........................................................................... 37
2.5.2.- WiFi module................................................................................ 37
2.5.3.- Bluetooth module....................................................................... 37
2.6.- Processor...........................................................................................37
2.6.1.- Firmware update........................................................................ 38
2.7.- Program............................................................................................. 38
2.7.1.- Algorithm..................................................................................... 39
2.7.2.- Pseudocode................................................................................39
2.7.3.- Programming.............................................................................. 40
2.7.4.- Programming by functions........................................................ 40
2.8.- Power supply..................................................................................... 41
2.9.- Structural parts..................................................................................42
2.9.1.- Modding Pc................................................................................. 42
2.9.2.- LEGO Technic parts.................................................................. 42
2.9.3.- Wareable technology.................................................................44
2.9.4.- Metallic metric3 screws............................................................ 45
2.9.5.- Nylon metric3 screws................................................................45
3.- Programming with mBlock5...................................................46
3.1.- Initial screenof mBlock5.................................................................. 46
3.2.- Board selectionand connection......................................................49
3.2.1.- USB connection..........................................................................51
3.2.2.- Bluetooth connection.................................................................52
3.3.- Stage.................................................................................................. 52
3.4.- Execution options menu...................................................................52
3.5.- MBlock5 program edition options menu.........................................53
3.6.- Programming block menu................................................................53
3.6.1.- Lighting........................................................................................ 53
3.6.2.- Sensing........................................................................................57
3.6.3.- Pins.............................................................................................. 61
10
3.6.4.- Wi-Fi.............................................................................................63
3.6.5.- LAN.............................................................................................. 66
3.6.6.- Events..........................................................................................68
3.6.7.- Control......................................................................................... 70
3.6.8.- Operators.................................................................................... 73
3.6.9.- Variables..................................................................................... 78
3.6.11.- My blocks.................................................................................. 79
3.2.12.- Extensions................................................................................ 81
3.7.- mBlock5 toPython translation.........................................................82
4.- STEAM projects with mBlock5...............................................83
4.1.- With the Halocode board alone....................................................... 84
4.1.1.- Flashlight.....................................................................................84
4.1.2.- Flashlight with brightness adjustment..................................... 85
4.1.3.- Flashlight with brightness, colour and blink adjustment..........89
4.1.4.- Emergency vehicle lighting....................................................... 89
4.1.5.- Rotating Emergency vehicle lighting........................................93
4.1.6.- SOS signal light.......................................................................... 94
4.1.7.- Kids night light.............................................................................97
4.1.8.- Metronome with light..................................................................98
4.1.9.- Sound meter with light indicator............................................... 98
4.1.10.- Noise classroom traffic light..................................................101
4.1.11.- Rhythm meter.........................................................................103
4.1.12.- Disco Light.............................................................................. 103
4.1.13.- Heads or tails..........................................................................109
4.1.14.- Dice..........................................................................................109
4.1.15.- Quiniela (Football Lottery).................................................... 112
4.1.16.- Rock-paper-scissors............................................................. 112
4.1.17.- Chronometer.......................................................................... 112
4.1.18.- Timer....................................................................................... 112
4.1.19.- Wristwatch.............................................................................. 112
4.1.20.- Pedometer.............................................................................. 112
11
4.1.21.- Drop.........................................................................................116
4.1.22.- Bubble level............................................................................ 116
4.2.- Halocode and speech recognition................................................ 116
4.2.1.- Turn LEDS on and off with voice............................................ 116
4.2.2.- Halocode shows the indicated color...................................... 117
4.2.3.- Control the lit LEDS number................................................... 121
4.2.4.- Control the LEDS from a remote Halocode........................... 127
4.2.5.- Send messages to mBlock5 stage.........................................127
4.3.- With Halocode board and one more component.........................127
4.3.1.- Doorbell.....................................................................................127
4.3.2.- Adjustable intensity light (with potentiometer)......................129
4.3.3.- Twilight light..............................................................................133
4.3.4.- Environmental thermometer...................................................136
4.3.5.- Alarm of presence....................................................................141
4.3.6.- Multi colour light with remote control..................................... 144
4.4.- With Halocode and two more components.................................. 144
4.4.1.- Sound presence alarm............................................................ 144
4.4.2.- Fire alarm.................................................................................. 147
4.4.3.- Motion andnoise alarm........................................................... 152
4.4.4.- Twilight courtesy light.............................................................. 152
4.4.5.- Automatic watering.................................................................. 157
4.4.6.- Alarm of presence with remote control.................................. 157
4.5.- Real home automation with Halocode......................................... 157
12
1.- Introduction
The purpose of this book is to provide theoretical and practical
knowledge of robotics to readers, using Halocode as the working
platform. It serves both for self-training and for educational support
material.
13
Its structural parts, made of reinforced aluminum, are designed so that
they can be assembled easily, providing stability, which allows to build all
kinds of robots, 3D printers, CNC machines, etc.
The easy and solid union of the pieces makes assemblies very simple and
adapts to practically any project you can imagine.
14
1.3.1.1.- Open source
As the manufacturer states, Makeblock will be Open Source Hardware for
ever with CC-BY-SA3.0 licence, so that the diagrams, plans and firmware
will always bepublic.
Since May 2017 some Makeblock products can also be programmed with
Bitbloq, an environment that, in our opinion, is much more powerful, but
also somewhat morecomplex.
15
1.3.1.5.- Easy connections
All of the Maker line products connections
are "plug and play" by means of RJ25
connectors, similar to those of LEGO, and
with colour codes, so that it is not necessary
to solder cables or use prototyping boards,
which allows focused on robotics.
1.3.1.6.- Arduinocompatible
Makeblock ME sensors and actuators are Arduino open source
compatibles.
1.3.2.- Neuron
Neuron is an educational robotics platform based on interconnectable
blocks, with more than 30 different functionalities, that allows to carry
out in a very easy way all kinds of STEAM projects.
Precisely that simplicity makes it very suitable to introducing youngsters
in electronics and robotics, but its power and versatility allows it to be
used for all ages and levels.
16
1.3.2.1.- Neuron blocks
17
https://store.makeblock.com/index.php?route=product/search&search=
neuron
18
1.3.3.1.- Codey
Codey is the brain of the robot that, in addition to the processor,
integrates more than 10 electronic modules that can be controlled by
program.
1.3.3.2.- Rocky
Rocky is the vehicle that gives Codey mobility. It has integrated, in
addition to the motors that move its tracks, other sensors and a
connector for Neuron modules, which further expands its possibilities.
19
1.3.3.3.- Makeblock App
The easiest way to use Codey Rocky is with the "Makeblock App",
available for both Android and Apple, which allows three modes.
1.3.3.3.1.- Drive
In this mode the tablet or
smartphone acts as a remote
control from Codey. In addition to
moving it in different directions
and at different speeds, user can
draw in its LEDS matrix or apply
different combinations of sounds,
expressions and movements.
20
1.3.3.3.2.- Draw and Run
In this mode the user draws a path
on which sounds and colors can be
included.
Pressing "Play", Codey Rocky will
follow the path by executing the
instructions that he finds to emit
sounds or turn on lights.
It is a conceptual way to introduce
the younger in the programming.
1.3.3.3.3.- Code
This mode allows Codey Rocky programming using a block graphical
environment very similar to mBlock5.
21
1.3.3.5.- Other books by the same author
For more information the reader has the
Spanish book “Educational Robotics with
Codey Rocky” by the same author (ISBN
978-8409067527).
1.3.4.- Halocode
HaloCode is a programmable small
board that integrates some
components:
Button
4 Contact sensors
Microphone
12 RGB LEDS
WiFimodule
22
https://www.makeblock.com/support
23
1.5.1.- STEAM Philosophy
STEM, without the A, is the acronym of the names of four academic
disciplines: Science, Technology, Engineering and Mathematics
Educational initiatives or projects oriented towards the STEM philosophy
aim to combine these four subjects to develop an interdisciplinary
approach to the teaching and learning process, also incorporating
contexts and situations of daily life, and using the necessary technological
tools.
The European Commission bet decidedly by this methodology, as
evidenced by the more than 13 million euros that it planned to devote in
the period 2014-2020 to subsidize initiatives aimed to increasing the
attractiveness of scientific studies and the interest of young people in the
STEM philosophy.
However, despite the projection of this philosophy, the reality is that
since the beginning of the 2000s there has been a considerable decline in
the proportion of students in STEM disciplines, something that contrasts
with the growing demand for this type of profiles in the labor market.
More recently, there has been a change in trend in STEM actions, possibly
due to the rise of the maker philosophy and do-it-yourself (DIY)
movements, as well as the inclusion in the educational field of promotion
of creative thinking and work based on more competent and productive
activities.
24
In 2003, matching up with the third generation
of the iPod presentation, the New York Times
include in an article the following sentence from
Steve Jobs:
Design is not just what it looks like and feels
like. Design is how it works.
25
2.- Halocode components
In the same way that the brain of living beings receives information
through the senses and coordinates and moves the limbs, robots can
interact in different ways with the environment, depending on the
sensors and actuatorsused.
2.1.1.- Button
Halocode has a single blue button, located in
the center of the board.
A button is a sensor which returns a logical
value based on its state:
True (logical 1) if pressed
False (logical 0) if not pressed
26
2.1.3.-Soundandvoicesensor
Halocode integrates a sound sensor and
voice sensor.
This sensor gives Halocode a sense similar to
the sense of hearing capable, not only of
measuring the intensity of sound, but also of
interpreting it, which allows interesting
applications, such as for example that the
user can turn on or off the LEDS with the
voice.
By means of this type of sensor it is possible to carry out a multitude of
devices such as a sound level meter (instrument that measures the
ambient sound), sonic alarms or a fun light noise for the classroom.
27
2.1.5.- Connection pins
Halocode board has 6 connection pins identifiable by its golden color:
The 4 pins can be used for digital (ie: binary) inputs and outputs and for
analog outputs (ie: values between 0 and 1023).
28
On the contrary for analog inputs (values between 0 and 1023) only pins
2 and 3 can be used.
29
Once this change is made, the component can be directly connected to
the Halocode board (G with GND, V with 3V and S with 0, 1, 2 or 3), as
shown in the image.
30
2.2.1.- Potentiometer
A potentiometer is a variable resistor. That is, an
electronic component that makes it possible to regulate
the intensity of the current (the amount of electricity)
circulating in a circuit. A clear example are the controls
that allow adjusting the volume in the music equipment.
31
It is an analog digital component, so it must be connected in one of the
analog digital pins (2 or 3) in a similar way as described in section 2.2.1.
2.2.4.-Soilmoisturesensor
This sensor determines the soil moisture by
measuring the conductivity between the two
probes and returning an analog value between 0
and 1023. Since water is a good conductor of
electricity, the higher the humidity, the greater the
measured current.
With this type of sensor you can, for example, control the humidity of a
plant or, even, proceed to its irrigation when necessary.
The mBlock5 programming environment does not have a specific block to
manage it, so we will use the direct reading block of the pin to which it is
connected.
It is an analog digital component, so it must be connected in one of the
analog digital pins (2 or 3) in a similar way as described in section 2.2.1
32
2.2.5.- PIR sensor
The acronym PIR corresponds to "Passive InfRared", a type of sensor that
measures the infrared (IR) light emitted by the objects that are in its
vision field. One of the most common applications of this type of sensors
is motion detectors, either in alarm systems or in automatic lighting
systems.
The term passive refers to the fact that PIR devices do not
generate or radiate energy to achieve detection, but
operate exclusively on the basis of the energy emitted by
the objects.
33
2.3.- Actuators integrated in Halocode
An actuator is a device capable of transforming hydraulic, pneumatic or
electric energy in the activation of a process with the purpose of
generating an effect on an automated process.
The actuator receives the order of a regulator or controller and
accordingly generates the order to activate a final control element, such
as a valve.
2.4.1.-Buzzer
A buzzer is a passive electro acoustic transducer (there are
also active transducers) that produces a mono tonal
continuous sound (usually sharp). It serves as a signaling or
warning mechanism and is used in multiple systems, such
as household appliances, vehicles, etc.
34
The quality and power are what you can expect from this type of device,
much lower than a speaker. Even so they are apt for infinity of
applications, even musical, for which it is relevant to know the relation
between the notes and their frequencies.
It is a binary digital actuator so it can be only connected on Halocode
board pins 0 or 1, in similar way as described in section 2.2.1
mBlock5 current version does not have any specific block to manage this
type of component, so you have to use the direct write blocks to the
digital pins.
To make a buzzer sound, it is necessary to quickly change its status
between "on" (1) and "off" (0). The faster the state changes, the higher
the frequency.
2.4.2.- Relay
A relay is a device similar to a switch but, instead of manually-operated, it
is operated by a digital signal to turn it on or off.
In this way, with a low voltage signal, you can control the operation of
equipment that works at 220 volts.
It is therefore the key element to use robotics in home automation
projects (domotic).
Presently they are solid type, known as "SSR"
(solid state relay), and the element that makes
the switch is an optotransistor formed by an LED
that when the control signal is set to 1 emits
light that, when received by a photoresist, allows
electrical courrent passes through the controlled
circuit.
A relay completely isolates the control circuit (robotics) from the power
circuit (controlled equipment), thus protecting the board and control
elements.
The relays can have one or several channels. Each channel is used to
control the operation of a device. In this book we use single-channel
relays.
35
Each channel has 3 terminals to connect the circuit you want to control.
One of the cables is connected to the central terminal, which is common
to the other two, and the other cable will be connected to the NO
(Normally Open) or NC (Normally Close) terminal depending on whether
you want the idle state to be open (disconnected) or closed (connected) .
The most common is to connect it to the NO (Normally Open) so the
normal state of the controlled equipment is turned off.
The pins associated to each channel of the relay are connected directly to
a digital pin of the Arduino board (we use only free prototyping boards)
and the terminals to the positive and negative cables of the electrical
circuit that we want to control. By writing a 1 (high value) on the digital
pin to which we have connected the relay, it will be activated, closing the
circuit and, in this example, turning on the light LED. Writing a 0 (low
value) the relay will deactivate and open the circuit, turning off the LED.
In section 4.5 of the full book a domotic project is carried out using safe
currents of maximum 25 volts.
36
2.5.- Comunication
Halocode has several components for communication, both wired and
wireless.
2.6.- Processor
The processor is the brain of the robots. It is
usually located on the "control board" which,
in addition to the processor, usually includes
memory, input and output ports, USB
connection to the computer, a reset button,
the on / off switch and, optionally, some
additional elements as sensors, actuators and
Bluetooth connection.
37
2.6.1.- Firmware update
The firmware is the non-volatile software (it is not erased when the
Halocode is turned off) that controls the basic functions of an integrated
circuit (chip). Sometimes the firmware has to be updated, either to solve
operating problems or to add new functionalities.
2.7.- Program
A computer program is a set of instructions
for a processor to perform a series of
specific tasks. Without programs,
computers are not capable of any action.
The general set of programs is called
software.
When talking about programs differentiation should be made between
the source and the executable code.
It is called source program or source code to the written by the
programmer in a particular programming language, more or less close to
human language.
Halocode has its own graphical programming environment for PC and
Mac called mBlock5, very friendly and intuitive.
As soon as the program load is finished, its execution begins. Since, just
like the Arduino boards, Halocode can only contain one program in its
memory, when it is loaded, it replaces the one that had previously.
38
2.7.1.- Algorithm
An algorithm is a set of well-defined, ordered and finite instructions or
rules that allows to carry out an activity following the steps indicated.
They must be complete and should not generate doubts about the
purpose of each of these steps, regardless of whether the reader may not
know how to put it into practice.
In daily life, algorithms are used
constantly, most of the time
unconsciously, to solve problems or
execute actions.
A typical example is to solve a problem
with a light bulb.
It is highly recommended to be clear
about the algorithm before starting to
create the program.
2.7.2.- Pseudocode
The pseudocode is an informal, although accurate, high-level description
of an algorithm, which essentially uses natural language together with
some syntactic conventions of programming languages, such as
assignments, cycles and conditional, although it is not governed by any
standard.
It is used to describe algorithms and as an intermediate element during
development, with the great advantage that it requires little extension.
The pseudocode is designed to make it easier for people to understand
an algorithm, and therefore can omit irrelevant details that, nevertheless,
are necessary in the later development of the program.
The main characteristics of this language are:
It is a simple form of representation to use and understand.
It facilitates the passage of the program to the programming
language.
It is independent of the programming language that will be used.
39
Facilitates the further development of the program.
A typical example of commonly used pseudocode is a food recipe, but it
can be applied in any activity or process.
This would be the pseudocode for the subsequent development of a
program that is able to calculate the area of any rectangle:
While not pressing the X key
Ask the user the base length
Ask the user the height length
Rectangle area = Base length x length height
Display Rectangle area
Ask the user to press any key to continue
or X to end
All the projects in this book include the pseudocode of the algorithm that
is then programmed in mBlock5 although the pseudocode could be used
to develop the program in any other platform.
2.7.3.- Programming
Finally, it remains to write the program from the pseudocode, for which
the programmer must know the specific programming language to be
used.
In section 3 the programming resources available in mBlock5 are
described.
2.7.4.-Programmingbyfunctions
When solving a problem, it is always better to divide it into smaller
problems, which will be easier to solve.
In programming, the same thing happens, so regardless of the
programming environment or language used, it is always better (if
possible) to split the program into functions that perform simple and
specific tasks. We will touch on this question later.
40
2.8.- Power supply
To operate, the Halocode board needs power, either through the USB
connector or the side connector.
In the case of the USB connector, the power supply can be the computer
to which we have connected it or an external battery equipped with this
type of connector:
If batteries are used, they should be between 3 and 5 volts. In the market
there are batteries of all sizes and capacities. For certain projects, such as
41
the watch, the ideal thing is to feed the Halocode board with a small
battery that we can fix to its back side by means of velcro:
Just after receiving power, the Halocode board will start and run the
program that has loaded in its memory.
2.9.1.- ModdingPc
As usual in the books of this author, a faithful follower of the STEAM
philosophy, the A (Arts) will be taken into account, which, in this
occasion, will be oriented towards the so-called "Modding Pc", a design
style that takes into account the strength, originality and functionality,
that when applied to the PCs, and in this case the Halocode board will
derive in models that leave the components exposed.
42
Frontal view
Back view
The result considers that, besides being functional, it contributes the
artistic component required in the STEAM projects, offering absolute
freedom to the user to quickly adapt the structures to their liking and to
43
fix additional components, such as the PIR sensor that appears in the
image.
On the other hand this structure offers an adequate grip of the crocodile
clips of power and ground, preventing them from making contact with
other pins or components of the board, which could cause a short circuit
and damage it.
Likewise, the metal screws with which
the board is fixed to the structure also
serve to fasten the crocodile clips of the
signal cables simply and safely.
To fix the components we propose this
simple and practical solution that also
prevents it from moving or turning. As
you can see, we use nylon 3 metric
screws to avoid false contacts.
2.9.3.- Wareabletechnology
The term wareable refers to the set of devices and electronic devices that
are incorporated in any part of the body or clothing, interacting
continuously with the user and with other devices in order to perform a
specific function.
44
Examples of wearable technology are smart watches, sneakers with built-
in GPS, or wristbands that control our state of health, all of them
increasingly present in our lives.
In that sense we also make use of a proposal that we consider fits both
the design and the concept of the Halocode, a wristwatch entirely made
with LEGO pieces:
45
3.- Programming with mBlock5
Halocode can be programmed with mBlock5, available for PC and Mac, a
tool developed byMakeblock.
It is based on Scratch3, so it uses blocks that fit together, as if it were a
puzzle, to buildprograms.
This helps to make programming accessible to children, because they do
not have to worry about syntax (they do not need to learn how to write
code in a literal programming language such as Processing, C ++ or Java).
The Web version is also available, which makes it possible to use mBlock5
from any site and with any device through a browser (provisionally at
https://ide.makeblock.com/#/)
46
Option Description
Option menu:
My Projects Shows the user's projects. From this screen
you can manage existing projects (open,
share, rename, copy, save to the computer,
delete) or openit.
New Project Start a new project
Open from your Open a project from the local computer.
computer
Example
(See same section of )
programs
Help Help User manual
Check for updates
Send comments to Makeblock
About mBlock5
47
My Projects Shows the user's projects. From this screen
you can manage existing projects (open,
share, rename, copy, save to the computer,
delete) or openit.
Search projects
Open recently worked
projects.
Sample programs Codey Codey Rocky projects
Rocky samples
Stage Stage samples
AI AI Samples
IoT IoT samples
Project name To change Project name
Save Save Save in the same place
and with the same name
Save as Save with other name
Save to Save to computer with
computer other name
Log in mBlock5 community. Once
Identify identified, the projects are saved in the
cloud. You can also use the IoT
functionalities and see data in the cloud.
48
Area Description
Top menu
Stage
Execution menu
Submenu
Board selection and connection
Edition comands
Programming command groups
Programming commands of the selected group
Programming area
The following sections describe the different areas of the graphic
environment mBlock5, although we will start with the selection and
connection of the board since the environment is adjusted to the
selected plate.
49
By default Codey is marked, but if you wish you can work with other
Makeblock robots, such as mBot, Ranger or Halocode, or even with other
manufacturers' boards such as micro:bit. By clicking on the box that
contains the plus sign, a new screen appears with the available robots
and boards:
50
3.2.1.- USB connection
Halocode can be connected
to a PC through the mini
USB connector on top.
After connecting the USB
cable, click on mBlock5 in
"Connect", opening a
window to select the port.
Once the connection is successful, this window closes and in the Devices
section the option to load the program appears (upload).
The USB connection itself provides power to Halocode.
51
3.2.2.- Bluetooth connection
3.3.- Stage
In the upper left mBlock5 environment, appears the stage window.
In this book it is used only to visualize the values of the different
variables, which is very useful to check the operation of the program and
debug possible errors, especially if we take into account that Halocode
doesnothaveascreenthatallows ustoshowthevaluesofthevariables.
To display the value from a variable in the
stage, simply check the box next to its
name in the variable section.
To be able to show the values of the
variables (in the sample image is “Dice”);
you must work with the board in
peripheral mode, that is, with the "upload
mode" disabled.
52
Execution options menu
3.6.1.- Lighting
This group includes the blocks used to manage the RGB LEDS ring that
Halocode has on its front.
53
The block itself allows access to a drop-down menu to select one of the
available patterns:
Rainbow All the LEDs light up and a transition of the colors of the
rainbow occurs.
Spindrift All LEDs turn blue and then a group of white LEDs rotates until
the circle iscompleted.
Meteor Similar to the previous one but at a higher speed and two
rounds are completed.
Firefly At random, the LEDs are switched on and off progressively.
The execution of the program stops until the pattern is completed.
Since it is a very specific Halocode block, we do not use it in the projects
in this book. Instead we use more usual programming blocks.
54
3.6.1.4.- Turn on all LEDs with a certain colour
This block allows you to turn on all the LEDS
by specifying a certain color, saturation and
brightness.
3.6.1.7.-TurnonallLEDsbyspecifyingRGBvalues
This block allows you to turn on all the LEDs by specifying the value of
each of the three component colors (red, green or blue). Indicating the
values 0 the LEDS turn off.
55
In the projects of this book it is usual to use this block in the following
way:
56
It allows to indicate a fixed value or,
what is more useful, a variable. A
value of 50 lights turn on half of the
LEDS, while a value of 100 lights all
of them. On the other hand the LEDS
are going on in a scale of colors.
3.6.2.- Sensing
This group includes the blocks used to manage the sensors integrated in
the Halocode board.
57
3.6.2.5.- Check the position of Halocode
This block is used to check the position of Halocode.
58
When Halocode is fully leveled in the horizontal plane, the acceleration
values on the X and Y axes will be 0. When perfectly vertical, the
acceleration value of the Z axis will be 0.
59
The gyroscopes sensors are suitable for determining instantaneous and
small magnitude turning angles, but they are not suitable for determining
angles of rotation over time or of great magnitude.
60
3.6.2.15.- Read the value of the internal timer
All the processors have an internal timer with which it synchronizes all
the components and the operations that are carried out. When starting
Halocode, the timer is reset to zero.
This block allows you to read the value of the
internal timer, either to assign it to variables or to
condition actions.
As we will see, in programs you can use the value of this stopwatch to
control precisely the passage of time.
3.6.3.- Pins
This group includes the blocks used to manage the four connection pins
(0, 1, 2 and 3) of the Halocode board.
3.6.3.1.-Checkthevalueofapinin digitalmode
This block allows you to check
the digital (binary) value of any
of the 4 pins. It is usually used to
condition actions.
Pins 0 and 1 are identified as digital (D), while pins 2 and 3 are identified
as analog (A). However, all analog pin can be read as digital, since values
61
higher than 512 will be identified as 1 and lower values as 0, as shown in
the example in the next section.
62
3.6.3.5.- Write an analog value in a pin
This block allows you to write an analog value (between 0 and 1023) in
any of the 4Halocode pins.Writing the analog 1023 value is equivalent to
writing the value 1 in binary mode.
3.6.4.- Wi-Fi
This group includes blocks destined to manage WiFi communication,
either to make use of voice recognition or to communicate two or more
Halocodeboards.Theseblockscanonlybeusedin"UploadOn"mode.
Voice recognition is based on Microsoft Cognitive Services, that is, the
Halocode board records the voice message and sends it to the Microsoft
server so that it translates the voice file into text.
Therefore, it will only be possible to use voice recognition if Halocode is
first connected to a WiFi access point that also has an Internet
connection,and theuser has logged in to his makeblock.com account.
The communication between boards is done at the level of "user code",
that is, any board with Internet access connected in the same user
account can exchange messages with each other, regardless of their
physical location.
63
Once the connection is established, the rest of the mBlock5 blocks
related to WiFi communication can be used.
3.6.4.2.-Check WiFiconnection
This block allows you to check if the WiFi connection between Halocode
and the WiFi access point has been established.
Normally this block usually follows the one seen in the previous section,
so that the execution of the program will wait until the connection has
been established:
The normal thing is that the voice recognition is executed based on a user
action, such as pressing the button:
64
3.6.4.4.- Use the voice recognition text result
This block allows you to use the result of speech recognition to, for
example, assign it to a variable:
65
3.6.4.6.- Send a message with a value to the user's cloud
This block allows sending a message with a value to the user's cloud. This
message, along with its value, will be received by all the Halocode boards
connected to the same cloud.
3.6.5.- LAN
This group includes the blocks destined to manage a WiFi wireless local
network between Halocode boards to exchange messages and data
between them.
66
3.6.5.2.- Send a message to the local network
This block allows you to send a message to the local network. For
example, the message "Detected noise" can be sent when the root board
detects a highvolume:
67
3.6.6.-Events
This group includes blocks associated with events.
68
3.6.6.5.- When Halocode istilted
When Halocode is tilted to the indicated side starts the execution of this
block.
69
3.6.7.- Control
This group includes all the blocks that allow controlling the execution
flow of the program.
70
3.6.7.4.- Condition actions (If)
This block allows to condition the execution of a group of instructions.
Precisely in the previous section we saw an example that included a
conditional block "If".
Thecondition can bethe state of a sensor, suchas a button. You can also
combine operators to check if the value returned by a sensor is equal,
less or greater than a certain value. In the next program, when the
volume measured by the microphone is greater than 50, LED 1 will light
red.
71
In section 3.6.8 (Operators), all the operators that can be used to
determine the condition are detailed.
72
3.6.7.6.- Wait until a condition is met
With this block the execution of the program stops until the expected
event occurs.
In the following example, the program waits for the button to be pressed,
after which LED 1 will light up in green:
3.6.8.- Operators
This group includes all the blocks that allow to perform mathematical
operations,logicaloperations,comparisons,arithmeticfunctions,etc.
73
3.6.8.1.- Arithmetic operations
These four blocks allow performing arithmetic operations (addition,
subtraction, multiplication and division) between variables and constants.
3.6.8.3.- Comparison
Thesethree blocksallowyou to comparetwovariables ofthe sametype.
If the comparison is true, the result is true. Otherwise it is false.
Assuming that the variables to be compared are A and B, the possible
comparisons are:
Logical
What does Equivalent to
Operation
Check if A value equals the
A=B A is equal to B?
B value
Check if A vaule is greater A is greater
A>B
than B value than B?
Check if A vaule is lower A is lower than
A<B
than B value B?
This block can be combined, for example, with the "No" block, which
allows to increase the variants:
74
Logical
What does Equivalent to
Op.
Check if it is not true A not equal to
Not (A =
that the value of A is B?
B)
equal to the value of B
75
3.6.8.5.- Contrary (Not)
This block allows you to invert the resulting
value of a condition. It correspondsto the
"Not" operation of the Boolean algebra.
Not(1) = 0 Not(0) = 1
3.6.8.8.-Length of atext
This block returns the length of a text. In
the example, the result would be 4.
76
3.6.8.10.- Get the remainder of a division (modulo)
Modulo operation finds the remainder after division of one number by
another (sometimes calledmodulus).
In the example, the value of A
would be 1.
3.6.8.11.- Round
This block rounds a value. In the
example, the value of A would be
2.
3.6.8.12.-Diversefunctions
This block allows to perform
different functions.
Function Sample
ABS Returns the absolute value of a number, that ABS(-1) = 1
is, without the sign.
Floor Round down FLOOR(1,8)=1
Ceiling Round up CEILING(1,2)=2
SQRT Square root SQRT(4)=2
SIN Trigonometric function sine SIN(90º)=1
COS Cosine trigonometric function COS(90º)=0
TAN Trigonometric tangent function TAN(45º)=1
ARC SIN Arcsine = Inverse function of sine ASIN(1)=90°
ARC COS Arccosine = Inverse function of cosine ACOS(0)=90°
ARC TAN Arctangent = Inverse function of tangent ATAN(1)=45°
Ln Naperian logarithm function Ln 2.71828 = 1
LOG Logarithm to base 10 function Log 10 = 1
e^ Exponentiation function e^1 = 2.71828
10^ Powers of ten 10^2 = 100
77
3.6.9.- Variables
This group contains the programming blocks that allow creating and
managing variables.
A variable is a container to which we give a name
to identify it and in which we can store a data.
There are different types of containers to store
different types of data:
Integernumbers Text
Decimal numbers Logical vaules (true or false)
In the mBlock5 environment, the types of variables are not differentiated,
soa variable can contain any type of data, be it numeric,literal or logical.
The group "Variables" has the option "Make a variable", which is used to
create a new variable.
In the stage area appear the variables created, as well as their value,
which is very useful to check and debug programs.
3.6.9.1.-Make avariable
This option is used to create
variables. Once created, they can
be assigned a numerical, literal or
logical value. Variable names can
contain any character except these:
(& <> ")
Here you can select if the variable
is only for the current project or for
all the projects.
78
3.6.9.3.- Assign a value to a variable (Set)
Once a variable is created, it can be assigned a numerical, text or logical
value.
Assign a numeric
Assign a text Assign a logical value
value
3.6.11.- My blocks
This group contains the programming blocks that allow creating and
managing the blocks created by the user. It is the equivalent of the
functions that we can find in other programming environments. The use
of blocks (functions) allows to structure the programs better.
A function is a set of instructions that perform a specific task, usually
returning a result. They are, therefore, small programs within programs.
They serve to avoid having to repeat the same instructions throughout
the program.
When solving a problem, it is always better to divide it into smaller
problems, which will be easier to solve. In programming, the same thing
happens, so regardless of the programming environment or language
used, it is always better (if possible) to split the program into functions
that perform simple and specific tasks.
Another alternative is to create a loop for each task to be performed.
These loops will all be executed in parallel when the program is launched.
79
When selecting this group, the
option to create a new block
appears, as well as the list of
blocks that you have already
created for the program that is
being edited.
The next function waits for the
user to press and release the
button, confirming the
pulsation with a flash of the
LEDS.
80
This option allows you to create a new block. When selecting a window
opens to indicate the name. Many programming languages do not allow a
function and a variable with the same namein the sameprogram. A good
way to avoid this situation is to have all the functions start with the letter
F, as can be seen in the image of the previous point where we created the
function FWaitForKeyPress.
The functions can have input parameters, which allows to pass data to
said function. These input parameters are indicated when creating or
editing the function and can be of different types: numeric (Number),
text (Text) or logical (Boolean).
3.2.12.- Extensions
At the bottom of the programming block palette
appears an option that allows you to manage the
extensions available for mBlock5.
At the time of writing this book in mBlock5 there were no extensions
available for Halocode. Accessing to the extension manager only appears
the text “ComingSoon…”
Oncethere are extensions available, to add any ofthem, it will be enough
to click on the plus sign that will be below each extension. Once an
81
extension has been added, a trash can appears instead of the plus sign in
case you want to delete the mBlock5 extension.
82
4.- STEAM projects with mBlock5
This section deals with STEAM projects programmed with mBlock5.
Section 3 details how to obtain the mBlock5 program and its operation.
For all projects, it includes:
Explanation, where appropriate, of the element to be
reproduced.
Approach of the project, proposed solution, time required and
levels of difficulty (in relative terms with respect to the rest of
the projects of the chapter).
Required components
Pseudocode
Program in mBlock5
Some of the projects can be used to carry out teaching activities for
"Learning WITH Robotics".
The reader can request to the author the collection of all the programs of
the projects and activities in this section in mBlock5 format (see last page
of the book).
On this summarised edition we include some of the projects from the
full book “Educational Robotics with Halocode” from the same author.
To keep the same projects numbering, an empty section is included for
the projects not included in this summary edition.
83
4.1.- With the Halocode board alone
In this section several projects are carried out only with the Halocode
board, without additional components.
4.1.1.- Flashlight
A Flashlight or torch is a portable hand-held electric lightdevice that
works with batteries, rechargeable batteries or even small dynamos.
Objetive Complexity
Carry out with Halocode a flashlight with a Time 10’
button to turn it on and off. Program: very low
Components used
84
Proposed pseudocode
Forever
Wait until button pressed
Turn on all RGB LEDS in white color
Wait until button released
Wait for pressed button
Turn off all RGB LEDS
Wait until button released
85
Components used
Proposed pseudocode
Brightness = 100
On = -1
Forever
Execute function FBrightnessInc
Execute function FBrightnessDec
If On = 1
Turn On all LEDS in white with intensity = Brightness
Else
Turn Off all LEDS
Wait for 0.2 seconds
Forever
If button pressed, On = On * (-1)
Wait until button released
Function FBrightnessInc
If touch sensor 0 touched
If Brightness less than 250
Brightness = Brightness + 5
Turn On LED 10 in green
Wait for 0.1 seconds
Function FBrightnessDec
If touch sensor 1 touched
If Brightness greater than 5
Brightness = Brightness - 5
Turn On LED 8 in red
Wait for 0.1 seconds
86
Program developed with mBlock5
87
88
4.1.3.- Flashlight with brightness, colour and blink
adjustment
See the full book “Educational Robotics with Halocode” from the same
author.
Objetive Complexity
Carry out an emergency light with Halocode with Time 20’
the following functionalities:
Long press = Turn on or off Program: medium
Short press = Change color
89
Components used
In this project we will see how to use the same component, in this case
the button, to control two parameters, the status (on or off) and the
color, depending on the time that is kept pressed.
To control the on and off state, the normal thing in robotics is to use a
logical variable, for example "OnOff", which contains 1 for the on state
and 0 for the off state. To change the states, simply execute the
operation "OnOff = opposite that(OnOff)" every time the button is
pressed. Although in mBlock5 it is possible to use logical variables,
another option is to use a numeric variable whose values will be 1 for on
and -1 for off. To change the states, simply multiply the variable by -1
each time the button is pressed.
Proposed pseudocode
Execute function FInit
Forever
Execute function FButton
Execute function FOn
Function FInit
Brightness = 100, On = -1, Colour = 1, Time = 0.1
Function FOn
If On = 1
Execute function FLEDSOn
Wait seconds = Time
Execute function FLEDOff
Wait seconds = Time
Function FButton
If button pressed
TimeButton = Execution time
Wait for the button not pressed
TimeButton = Execution time – TimeButton
If TimeButton greater than 1
On = On * (-1)
Else
90
Execute function FColourChange
Function FColourChange
Colour = Colour + 1
If Colour greater than 5, then Colour = 1
Execute function FLEDSOn
Function FLEDSOn
If Color=1 turn on all LEDS in red
If Color=2 turn on all LEDS in yellow
If Color=3 turn on all LEDS in green
If Color=4 turn on all LEDS in blue
If Color=5 turn on all LEDS in magenta
Function FLEDOff
Turn off all LEDS
91
92
4.1.5.- Rotating Emergency vehicle lighting
See the full book “Educational Robotics with Halocode” from the same
author.
93
4.1.6.- SOS signal light
SOS is the most widely used international distress signal since it was
approved during an international conference in Berlin in 1906, to replace
the previously used "CQD" in telegraphic transmissions in Morse Code.
Although Morse code is no longer used today, the SOS signal remains in
effect.
Objetive Complexity
Make Halocode emit the visual signal Time 15’
corresponding to the Morse SOS code.
The button will be used to alternately activate and Program: medium
deactivate it.
94
Components used
Proposed pseudocode
On = -1
Forever
If On = 1
Execute function FLetterS
Execute function FLetterO
Execute function FLetterS
Wait 2 seconds
Else
Turn off all LEDS
Forever
If button pressed
On = On * (-1)
If On = 1
Brightness = 100
Turn on LED 12 in green
Else
Brightness = 0
Turn on LED 12 in red
Wait for button not pressed
Function FLetterS
Repeat 3 times
Turn on all LEDS in white with Brightness = Brightness
Wait 0.3 seconds
Turn off all LEDS
Wait 0.3 seconds
Function FLetterO
Repeat 3 times
Turn on all LEDS in white with Brightness = Brightness
Wait 0.6 seconds
Turn off all LEDS
Wait 0.3 seconds
95
Program developed with mBlock5
96
4.1.7.- Kids night light
See the full book “Educational Robotics with Halocode” from the same
author.
97
4.1.8.-Metronome with light
See the full book “Educational Robotics with Halocode” from the same
author.
Objetive Complexity
Make a light sound meter with Halocode. Time 20’
The number of LEDs lit will be proportional to the
sound level. Program: medium
98
Components used
Proposed pseudocode
Forever
SoundLevel = Microphone volume
Execute function FLEDS
Function FLEDS
LED = Round (12 * Level / 100)
Execute function FLEDSOn
Execute function FLEDSOff
Function FLEDSOn
I =1
Repeat until I > LED
Turn on LED = I in white
I =I +1
Function FLEDSOff
I = 12
Repeat while I less than LED
Turn off LED = I
I =I - 1
99
100
4.1.10.- Noise classroom traffic light
A noise classroom traffic light is a effective way
to control the acceptable noise level in the
classroom, that will depend on the activity to
be developed.
Once this level is set, when the noise in the
classroom exceeds it, the traffic light will warn
students to lower their voice.
Objetive Complexity
Carry out with Halocode a classroom noise traffic Time 15’
light. Program: medium
Components used
Proposed pseudocode
OrangeLevel = 50
RedLevel = 70
Forever
101
SoundLevel = Microphone volume
If SoundLevel less than OrangeLevel
Turn on all LEDS in green
Else
If SoundLevel greater than RedLevel
Turn on all LEDS in red
Else
Turn on all LEDS in orange
102
4.1.11.- Rhythm meter
See the full book “Educational Robotics with Halocode” from the same
author.
Objetive Complexity
Carry out a disco light with Halocode, making the
Time 15’
lights turn and change colour to the rhythm of the
music. With the contact sensors 0 and 1, the
Program: high
sensitivity of the microphone can be adjusted.
103
Components used
Proposed pseudocode
Execute function FInit
Forever
Execute function FTouch0
Execute function FTouch1
Execute function FSoundLevel
If SoundLevel greater than LevelMin
Execute function FColour
Execute function FLEDS
Wait 0.1 seconds
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FInit
LED = 0, LevelMin = 20
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FTouch0
If contact sensor 0 touched
Repeat until contact sensor 0 no touched
If LevelMin less than 50
LevelMin = LevelMin + 1
Turn on LED 10 in green
Wait 0.1 seconds
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FTouch1
If contact sensor 1 touched
Repeat until contact sensor 1 no touched
If LevelMin greater than 5
LevelMin = LevelMin - 1
Turn on LED 7 in red
Wait 0.1 seconds
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FSoundLevel
104
SoundLevel = microphone volume
Brightness = SoundLevel
Colour = round (SoundLevel / 25)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FColour
Red = 0, Green = 0, Blue = 0
If Colour = 1, then Red = Brightness
If Colour = 2, then Green = Brightness
If Colour = 3, then Blue = Brightness
If Colour = 4, then Red = Brightness and Green = Brightness
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FLEDS
LED = LED + 1
If LED greater than 12, then LED = 1
LED2 = LED
Repeat 4 times
Turn on LED = LED2 with Red, Green and Blue
LED2 = LED2 + 3
If LED2 greater than 12, then LED2 = LED2 – 12
105
106
107
108
4.1.13.- Heads or tails
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.14.- Dice
A die is a cube, with each of its six faces
showing a different number of dots from
one to six. Dice are suitable as gambling
devices for games like craps and are also
used in non-gambling tabletop games.
The electronic variant can have a similar
shape or represent the value by means of
a set of LEDS on a single face.
Objetive Complexity
Carry out an electronic die with Halocode. To Time 20’
“throwing” the dice just press and release the
button, after which Halocode will show random Program: medium
number, between 1 and 6, until it stops.
109
Components used
Proposed pseudocode
Brightness = 50
Forever
If button pressed
Repeat until button is not pressed
Execute function FDiceRoll
Roll = random value between 3 and 8
Repeat times = Roll
Execute function FDiceRoll
Function FDiceRoll
Turn off all LEDS
Dice = Random value between 1 and 6
LED = 1
Repeat until LED greater than Dice
Turn on LED = LED in white
LED = LED + 1
Wait 0.2 seconds
110
Program developed with mBlock5
111
4.1.15.- Quiniela (Football Lottery)
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.16.- Rock-paper-scissors
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.17.- Chronometer
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.18.- Timer
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.19.- Wristwatch
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.20.- Pedometer
A pedometer is a device, usually
portable and electronic or
electromechanical, that counts
each step a person takes by
detecting the motion of the
person's hands or hips.
Its operation is based on an
accelerometer.
Today many devices (smartphones,
digital watches, etc.) incorporate
the pedometer function.
112
Objetive Complexity
Carry out a wrist pedometer with Halocode capable of Time 20’
indicating and count each step taken. Once the target
Program:
is reached, it will warn by flashing the LEDS in red. medium
Components used
113
Steps = Steps + 1
Turn off LED number = LED
LED = LED + 1
If LED greater than 12, then LED = 1
Turn on LED number = LED in yellow
If Steps > Goal
Execute Function FGoalReached
Steps = 1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FGoalReached
Until button pressed
Turn on all LEDS in red
Wait 0.3 seconds
Turn off all LEDS
Wait 0.3 seconds
114
115
4.1.21.- Drop
See the full book “Educational Robotics with Halocode” from the same
author.
4.1.22.- Bubblelevel
See the full book “Educational Robotics with Halocode” from the same
author.
116
4.2.2.- Halocode shows the indicated color
Objetive Complexity
Control the Halocode LEDS colour with the Time 20’
voice. Program: high
After pressing and releasing the button, the name of the desired colour is
indicated. It must be pronounced correctly in English because, otherwise,
the program will not be able to understand it. Indicating "Off" the LEDS
will turn off.
Components used
117
Proposed pseudocode
Execute function FWiFiConnect
Forever
Wait until button pressed
Wait until button not pressed
Execute function FListenColor
Execute function FShowColour
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FWiFiConnect
Turn on all LEDS in red
Connect with WiFi network in SSID..... and key ....
Wait until WiFi connected
Turn on all LEDS in green
Wait 0.3 seconds
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FListenColor
Turn on LED 12 in green
Text = Recognize voice English language during 3 seconds
Turn off LED 12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FShowColour
If Text contains “red”
Turn on all LEDS in red
If Text contains “green”
Turn on all LEDS in green
If Text contains “blue”
Turn on all LEDS in blue
If Text contains “yellow”
Turn on all LEDS in yellow
If Text contains “orange”
Turn on all LEDS in orange
If Text contains “white”
Turn on all LEDS in white
If Text contains “off”
Turn off all LEDS
118
Program developed with mBlock5
119
120
4.2.3.- Control the lit LEDS number
Objetive Complexity
Control with the voice the lit LEDS number. Time 30’
Program: high
After pressing and releasing the button, the name of the desired number
is indicated. It must be pronounced correctly in English because,
otherwise, the program will not be able to understand it and will turn on
all LEDS in red.
Components used
121
Proposed pseudocode
Execute function FWiFiConnect
Forever
Wait until button pressed
Wait until No button pressed
Execute function FListenNumber
Execute function FCheckNum
Execute FLEDS
Function FWiFiConnect
Turn on all LEDS in red
Connect with WiFi network in SSID..... and key ....
Wait until WiFi connected
Turn on all LEDS in green
Wait 0.3 seconds
Turn off all LEDS
Function FListenNumber
Turn off all LEDs
Turn on LED 12 in green
Text = Recognize voice English language during 4 seconds
Turn off LED 12
Function FCheckNum
LED = 0
If Text contains “1”, then LED = 1
If Text contains “2”, then LED = 2
If Text contains “3”, then LED = 3
If Text contains “4”, then LED = 4
If Text contains “5”, then LED = 5
If Text contains “6”, then LED = 6
If Text contains “7”, then LED = 7
If Text contains “8”, then LED = 8
If Text contains “9”, then LED = 9
If Text contains “10”, then LED = 10
If Text contains “11”, then LED = 11
If Text contains “12”, then LED = 12
Function FLEDS
If LED = 0
Turn on all LEDS in red
Wait 0.3 seconds
Else
I =1
Repeat until I greater than LED
Turn on LED = I in green
I = I +1
Wait 0.1 seconds
122
Program developed with mBlock5
123
124
125
126
4.2.4.- Control the LEDS from a remote Halocode
See the full book “Educational Robotics with Halocode” from the same
author.
4.3.1.- Doorbell
An electric bell is a device that produces an
audible signal when button is pressed.
It has many applications, being one of the most
common, the doorbell.
Objetive Complexity
Carry out with Halocode a simple bell that Time 10’
emits a mono tonal acoustic signal and light up
Program: low
while the button is pressed.
127
Components used
Proposed pseudocode
Forever
If button pressed
Turn on all LEDS RGB in green
Repeat 500 times
Write in pin 3 (buzzer) the value 1023
Write in pin 3 (buzzer) the value 0
Turn off all LEDS
128
In this project it is
necessary to take care
that the clamps
connected to the power
and ground pins do not
make contact with any
other element of the
board. The structure
described in section 2.9.2
helps reduce this risk.
Objetive Complexity
Time 30’
Carry out with Halocode a light that can be turned
on and off, as well as adjust the intensity using a
potentiometer. Program: medium
129
Components used
Proposed pseudocode
On = -1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Forever
Execute function FButton
Execute function FOnOff
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FButton
If button pressed
On = On * (-1)
Wait until button not pressed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FOnOff
If On = 1
Potentiometer = analog value from pin 3
Brightness = round (Potentiometer * 255) / 1023
Turn on all LEDs in white and brightness = Brightness
Else
Turn off all LEDS
130
Program developed with mBlock5
131
In this project it is necessary to take care that the clamps connected to
the power and ground pins do not make contact with any other element
of the board. The structure described in section 2.9.2 helps reduce this
risk:
132
4.3.3.- Twilight light
A twilight light is a light that is located in transit
areas, equipped with a sensor that turns it on
automatically at dusk, and turns it off at dawn,
thereby reducing day energy consumption.
Objetive Complexity
Carry out a twilight light that turns on Time 20’
automatically at dusk and goes out at dawn.
Program: medium
Components used
Proposed pseudocode
Brightness = 100
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Forever
Execute function FDayNight
If Night = 1
Turn on all LEDS in white and brightness = Brightness
Else Turn off all LEDS
Wait 1 second
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133
Function FDayNight
AmbientLight = analog value pin 3 (light sensor)
If AmbientLight less than 200
Night = 1
Else
Night = 0
134
In this project it is necessary to take care that the clamps connected to
the power and ground pins do not make contact with any other element
of the board. The structure described in section 2.9.2 helps reduce this
risk:
135
4.3.4.- Environmental thermometer
An environmental thermometer is a measurement
instrument that allows to know the ambient
temperature, either from a room or from outside.
Objetive Complexity
Carry out with Halocode an ambient analog Time 20’
thermometer. For this, a proportional analog
temperature sensor TMP36 will be used. Program: medium
Components used
136
On the other hand we will use a very specific block of mBlock5 that allows
to directly display a value, within the scale 0 to 100, with a colour
graduation. Up to 60, it shows the LEDS in green, above 60 and up to 80,
it shows them in orange and, above 80, it shows them in red.
In general we do not recommend making use of such specific blocks since
the reader will not find them in other environments. For this reason for
this project we show a second more elaborate solution that, although it
has the same functionality, is carried out with usual instructions in any
environment.
Proposed pseudocode (mBlock5 specific solution)
Forever
RAW = read analog value from pin 3 (temperature sensor)
TempC = RAW * 19 / 236
LEDS = TempC * 100 / 40
Show in LEDS ring the value LEDS
137
Proposed pseudocode (standard solution)
Forever
Execute function FTemp
Execute function FLEDS
Function FTemp
RAW = Read analog value from pin 3 (temperature sensor)
TempC = RAW * 19 / 236
Function FLEDS
LEDS = TempC * 12 / 40
I =1
Repeat until I greater than LEDS
Execute Function FColour
Turn on LED = I with values Red, Green, Blue
I =I +1
Repeat until I greater than 12
Turn off LED I
I =I +1
Function FColour
Brightness = 5 + (I * 20)
Green = Brightness, Red = 0, Blue = 0
If I greater than 5 then Red = Brightness / 2
If I greater than 9 then Red = Brightness and Green = 0
138
139
In this project it is necessary to take care that the clamps connected to
the power and ground pins do not make contact with any other element
of the board. The structure described in section 2.9.2 helps reduce this
risk:
140
4.3.5.- Alarm of presence
A presence alarm is a device that emits a warning,
usually sound, when detecting the presence of a
person. Normally it is located on the doors of shops
and offices.
Conceptually it is an element very similar to the
alarm based on a presence sensor, but it
incorporates a loudspeaker to emit a warning
sound, as well as an LED in caseyou want it to work
in silent mode.
Objetive Complexity
Using the PIR sensor carry out a visual presence Time 10’
alarm. Program: low
141
Components used
Proposed pseudocode
Forever
PIR = Read digital value pin 3
If PIR = 1
Turn on all LEDS in red
Else
Turn off all LEDS
142
In this project it is necessary to take care that the clamps connected to
the power and ground pins do not make contact with any other element
of the board. The structure described in section 2.9.2 helps reduce this
risk:
143
4.3.6.-Multicolourlightwithremotecontrol
See the full book “Educational Robotics with Halocode” from the same
author.
Objetive Complexity
Using the PIR sensor carry out a visual and audible Time 10’
presence alarm. Program: low
144
Components used
Proposed pseudocode
Forever
PIR = Read digital value pin 3
If PIR = 1
Turn on all LEDS in red
Execute function FBeep
Else
Turn off all LEDS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function FBeep
Repeat 50 times
Write 1 in digital pin 0
Write 0 in digital pin 0
145
In this project it is necessary to take care that the clamps connected to
the power and ground pins do not make contact with any other element
of the board. The structure described in section 2.9.2 helps reduce this
risk:
146
4.4.2.- Fire alarm
The fire alarm is a device that detects the
presence of flames, emitting a sound and visual
warning.
In some cases they can also activate the fire
extinguishing system.
Objetive Complexity
Carry out with Halocode a fire alarm that is Time 10’
triggered when detecting the presence of flames.
Program: medium
Oncetriggered by pressing the button it will reset.
147
Components used
The flame sensor has a potentiometer through which you can adjust its
sensitivity (left = increase sensitivity, right = reduce sensitivity).
Proposed pseudocode
Alarm = 0, Brightness = 100
Forever
Execute function FFire
Execute function FAlarm
Function FFire
Turn on LED 1 in blue
Fire = Read digital value pin 3
If Fire = 1
Alarm = 1
Turn on LED 1 in red
Wait 0.2 seconds
Turn off LED 1
Wait 0.2 seconds
Function FAlarm
If Alarm = 1
Repeat until button pressed
Turn on all LEDS in Red
Execute function FBeep
Turn off all LEDS
Execute function FBeep
Repeat until Fire = 0
Execute function FFire
Alarm = 0
Function FBeep
Repeat 50 times
Write value 1 in pin 0
Write value 0 in pin 0
148
Program developed with mBlock5
149
150
In the projects that are added components it is necessary to take care
that the clamps connected to the power and ground pins do not make
contact with any other element of the board. The structure described in
section 2.9.2 helps reduce this risk:
151
4.4.3.- Motion and noise alarm
See the full book “Educational Robotics with Halocode” from the same
author.
Objetive Complexity
Carry out a twilight courtesy light that, when it is at Time 30’
night, automatically turns on when detecting the
passage of a person. Failing to detect a person, it Program: high
will turn off after a delay time set in the program.
Components used
152
The delay time that we have set in our case, 10 seconds, may seem
scarce, but note that in the objective description, this time is counted
once the sensor failing detecting the person, therefore the light will be on
while the person is passing, and will continue for 10 seconds, once the
sensor failing detecting it.
Proposed pseudocode
Execute function FInit
Forever
Execute function FDayNight
Execute function FPIR
Execute function FOnOff
Execute function FLEDS
Wait 1 second
Function FInit
Brightness = 100
Night = 0
Presence = 0
Time = 10
Function FDayNight
AmbientLight = Read analog value pin 3
If AmbientLight less than 200
Then Night = 1
Else, Night = 0
Function FPIR
Presence = Read digital value pin 0
If Presence = 1
Turn on LED 12 in red
Wait 0.2 seconds
Turn off LED 12
Function FOnOff
If (Night = 1) and (Presence = 1)
On = Time
Function FLEDS
If On greater than 0
Turn on all LEDS in white and brightness = Brightness
On = On – 1
Wait 0.1 seconds
Turn on LED 6 in white and brightness = 50
Wait 0.1 seconds
Else Turn off all LEDS
153
Program developed with mBlock5
154
155
In the projects that are added components it is necessary to take care
that the clamps connected to the power and ground pins do not make
contact with any other element of the board. The structure described in
section 2.9.2 helps reduce this risk:
156
4.4.5.- Automatic watering
See the full book “Educational Robotics with Halocode” from the same
author.
157