BASIC COURSE
2 Contence | Cursus Basiskennis LEGO MINDSTORMS
C ON T E N C E
CONTENTS ....................................................................................................................................... 2
PREFACE .......................................................................................................................................... 3
USE OF SENSORS ............................................................................................................................. 4
INTRODUCTION ................................................................................................................................... 4
TASK 1 : USING MOTORS ....................................................................................................................... 4
WHEN DO YOU USE A MOTOR? ...................................................................................................................... 4
HOW TO USE A LEGO MOTOR ......................................................................................................................... 5
HOW TO USE THE “DISPLAY”SCREEN ................................................................................................................ 5
TASK .......................................................................................................................................................... 5
TASK 2 : USING THE TOUCH SENSOR ......................................................................................................... 7
WHAT IS A TOUCH SENSOR AND WHAT CAN YOU USE IT FOR? .............................................................................. 7
HOW TO USE THE LEGO TOUCH SENSOR ........................................................................................................... 7
TASK .......................................................................................................................................................... 8
TASK 3 : USING A LICHTSENSOR ............................................................................................................. 9
WHAT DO YOU USE THE LIGHT SENSOR FOR? .................................................................................................... 9
HOW DO YOU USE THE LEGO LIGHTSENSOR? ................................................................................................... 10
HOW TO CALIBRATE THE LIGHT SENSOR .......................................................................................................... 11
TASK ........................................................................................................................................................ 11
TASK 4 : USING THE ULTRASONIC SENSOR ................................................................................................ 13
WHAT IS AN ULTRASONIC SENSOR AND WHAT IS IT USED FOR? ........................................................................... 13
HOW TO USE THE LEGO ULTRASONIC SENSOR .................................................................................................. 13
TASK ........................................................................................................................................................ 14
TASK 5 : USING THE SOUND SENSOR ....................................................................................................... 15
WHAT IS A SOUND SENSOR AND WHAT DO WE USE IT FOR? ............................................................................... 15
HOW TO USE THE LEGO SOUND SENSOR ........................................................................................................ 15
TASK ........................................................................................................................................................ 16
Cursus Basiskennis LEGO MINDSTORMS | Preface 3
P R E F AC E
This course material is the result of a Comenius project 2007 – 2009 between VTI Veurne (Belgium), Budai
Középiskola (Hungary), ISS Deambrosis Natta (Italy), Portalens Gymnasium Uddevalla (Sweden) and Vocational
High School of Orestiada (Greece).
In 2007 these schools decided to start a LEGO MINDSTORMS project.
The purpose was to get the students of these schools communicating about the project, having them carry out
experiments with the LEGO NXT and ultimately develop attractive course material for students / teachers.
Very soon other teachers became interested and the LEGO NXT motivated them to introduce it in their lessons.
Therefore a basic course was made up to enable starters to get introduced to the NXT.
At our school group work exercises will be introducing LEGO NXT in the ICT lessons of the first grade of
secondary education, without dealing with sensors though.
In the second grade the students will learn how to work sensors and they will try more difficult exercises with
LEGO NXT..
In the third grade they will start using LabVIEW to program the LEGO NXT.
Please, enjoy!
4 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
U S E OF S E N S ORS
I N T R O D UC TI O N
We subdivide the class into groups of 3 to 4 students. Each group has to complete 5 tasks. Whenever a group
thinks they are ready to do the task they ask the teacher to take their time. The groups can have 3 tries to
correctly complete each task. The teacher notes down the time in the table. If a group does not manage to
complete a task they get the maximum penalty time of 25 seconds for that task.
Group 1 Group 2 Group 3 Group 4 Group 5
Task 1
Task 2
Task 3
Task 4
Task 5
All tasks can be done on a standard classroom table.
T A S K 1 : U SI N G M O T O R S
W H E N D O YO U U S E A M O T O R ?
In our daily life a lot of things need a motor. Everyone knows that.
Can you give some examples?
*………………………………………………………………………………………………………………………………………………
*………………………………………………………………………………………………………………………………………………
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 5
H O W T O U SE A L E G O MO T O R
You can drive a little car with a LEGO motor.
But you could also use a motor to have it hit a ball.
H O W T O U SE T H E “ D IS P L A Y” SC R E EN
Switch on the NXT by pressing the orange button .
The main menu appears. Press the right hand button twice and you will get the “Display” or ‘View’ screen.
Press the orange button again.
With the display you can determine the exact distance that the NXT has to drive. In order to find the number of
revolutions for a certain distance you scroll with the arrow buttons until you find the button ‘Motor rotations
R’. Press the orange button once more. Next you have to select which gate the motor is connected to. If you
now push the robot forward you will see how many rotations it makes.
T A S K
What you need:
• NXT basic model • an extra motor mounted onto the NXT and built in compliance with the
model in the manual
• ball with a little holder built like the model in the manual • black tape for the circuit.
Here you can select a
gate on the NXT.
Here you can define the direction:
forward, backward or stop.
Here you make the NXT turn
under a well defined angle..
Here you can define the next action
the NXT has to take.
Here you can define the distance
the NXT has to cover.
Here you can define the
power of an engine.
6 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
Task
The NXT basic model has to complete the course as represented below. At the end of the course, there is a
little ball. You have to knock away this small ball with the extra motor.
Take care, the NXT robot should stay within the black lines. This can only be done by accurately defining the
angles and by choosing exactly the same starting position with every try. Therefore it can be interesting to
mark this position with a piece of black tape.
See to it that the NXT robot performs the test as fast as possible.
Track
Write down every step of your program in the table below.
Which block do you use? Which are the settings you apply?
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 7
T A S K 2 : U SI N G T H E T OU C H S E NS OR
W H A T I S A T O U C H S E NS O R A ND WH A T C A N YO U U S E I T FO R ?
A touch sensor is a sensor that works as a switch and reacts when you press the button. The sensor signals the
NXT module if it is pressed or not. A good touch sensor can even measure how strong the pressure on the
sensor is. This is measured in Pa.
A touch sensor is used a lot in daily life, but it isn’t that obvious. Can you come up with 2 examples in which
touch sensors are used?
*………………………………………………………………………………………………………………………………………………
*………………………………………………………………………………………………………………………………………………
H O W T O U SE T H E L E G O T O U C H S EN S O R
The LEGO touch sensor is a very simple sensor which can only check if the sensor has been pressed or not.
The touch sensor has a hole in the middle in which you can fit an axle. You can build a construction on it that
allows the sensor to “feel” objects better.
You can use the touch sensor in different ways:
A first way in which you can use it, is with the ‘Wait’ block. When using this
block the NXT waits until the touch sensor registers pressure. The robot
can then start on the next task.
A second way to use the touch sensor is by using the ‘Switch’ block. With
this block you can give the robot a task when the touch sensor is pressed
and another task when it is not. This is called true/false programming.
An example: you can have the robot drive forward as long as the touch
sensor isn’t pressed. When the sensor touches an object the robot must
stop.
8 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
T A S K
What you need:
- NXT basic model without sensors
- the touch sensor which you mount at the front of the NXT
- black tape to mark the track
- 2 little vertical boards which will serve as walls.
Task
The goal is to programme your NXT robot so that it keeps to the track and uses the touch sensor.
Have the basic model of the NXT drive forward until it detects the wall with the touch sensor. Next it has to
turn and drive to the other wall and then turn again. Now the robot has to drive to the finish and stop. In the
drawing below you can see the track. You have your robot do the track as fast as possible. It’s not allowed for
the NXT to cross the black lines. You can solve this problem by accurately measuring the angle at the turning
points and by always taking the same starting position. That’s the reason why it can be useful to mark the
starting position with black tape.
Track
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 9
Write down every step of your program in the table below.
Which block do you use? Which are the settings you apply?
T A S K 3 : U SI N G A LI G HT S E N S O R
W H A T D O YO U U S E T HE L I G H T S EN S O R F O R ?
With a light sensor, you can detect different light intensities.
Can you give an example from everyday life in which a light sensor is used?
--------------------------------------------------------------------------
---------------------------------------------------------------------------
10 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
H O W D O YO U U S E T HE L E G O L I GH T S E N S O R?
The new light sensor is an improved version of the somewhat older
MINDSTORMS for schools. This sensor is much more sensitive, so you can do
more precise light measurements on a scale of 0 to 100. It’s also possible to
turn off the infrared light that can be found just below the sensor. In this way
the sensor only measures light of the environment.
Here you can select the port the sensor is connected to.
Here you can set the moment of activation.
Here you can see the If you switch on the button ‘ Generate
current light value. light’ ,the light sensor will generate its own
light that will be reflected onto the light
sensor.
The button ’Generate light’ can be useful.
The button ’Generate light’ can be useful if the light conditions are difficult, such as in very sunny
weather. The sensor only detect differences in how much light reflects off an object. Closer objects
are brighter than further ones, light-color objects are brighter than dark ones, and redder objects will
seem brighter than blue ones.
How do you detect different light intensities on the NXT?
Switch on the NXT by pressing the orange button.
When the main menu appears, you press the right hand arrow twice so that you get ‘View’ on the
screen. Press the orange button again. Now scroll with the grey keys until you find the light sensor.
On the ‘Display’ screen you can now see the brightness that the sensor perceives. You can have the
light sensor generate light with the button ‘Reflected light’ or let it work with the light of the
environment with the button ‘Ambient light’. Select the port which the light sensor is connected to.
Direct the sensor to different objects and you will see the intensity, shown in percentage. Just like
the other sensors you can combine this sensor with the ‘Switch’ block or the ‘Wait’ block.
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 11
You can use the light sensor in different ways.
The first way is with the ‘Wait’ block. The program will wait until the
sensor perceives a certain light intensity. As soon as this condition has
been fulfilled the program will continue running.
The second way is using the ‘Loop’ block. The program part inside the
‘Loop' block will continue until the light sensor measures a specific light
intensity.
The third way is with the ‘Switch’ block. Here you can give the robot a
certain task when the desired light intensity is reached and another task
when this is not the case. This is called true/false programming. So for
example you have the robot drive forward until it meets an object with a
higher light intensity than the selected value and then you have the robot
turn.
H O W T O C AL IB R A T E THE L I G H T S EN S O R
Sensors can sometimes be influenced by their environment. Therefore it is useful to calibrate them to let them
work correctly in every environment. In order to do this the sensor must be connected to a computer (via the
NXT).
Place the sensor block in the programming window and select it.
In the menu you will find the submenu 'Extra'. In this menu you select 'Calibration of sensors'. Ensure the
sensor is connected to the correct gate. Aim the sensor at the darkest place and press the orange button. Next,
aim at the brightest place and press the orange button again. The calibration is now complete. For the NXT the
darkest place now equals 0 and the brightest place 100.
T A S K
What you need:
- NXT basic model with light sensor fitted onto a long arm.
- black tape.
Task
The NXT (basic model equipped with a light sensor) is placed inside an area, defined by a black line (as you can
see underneath). The NXT starts inside the area, at its edge. It has to make a complete lap along the edge of the
area, as fast as possible.
The NXT will have to detect the line with the light sensor and then execute a movement in order to stay in the
area and close to the line. The NXT must be able to fulfill this task no matter where it is positioned to start.
The task has to be completed as fast and accurately as possible.
12 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
Track
Write down every step of your program in the table below.
Which block do you use? Which are the settings you apply?
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 13
T A S K 4 : U SI N G T H E U LT R A S O N IC SE N S O R
W H A T I S AN U L T R A S ON I C S E N S OR A N D W H AT I S I T US ED F O R?
An ultrasonic sensor is a sensor that can measure distances. The sensor sends and receives a signal. The time
between sending and receiving determines the actual distance to an object. So, the longer it takes for the
sensor to get the signal back, the further away the object is.
This sensor is used in the parking aid system of new cars. In this case the sensor determines the distance
between the cars to prevent the cars from bumping into each other.
Name 2 other examples in which the ultrasonic sensor is used.
- ………………………………………………………………………………………………………….
- ………………………………………………………………………………………………………….
H O W T O U SE T H E L E G O U L T R A S O NI C S EN S O R
The ultrasonic sensor created by LEGO has a reliable range from 5 till 220 cm. The distance shown is the
distance measured from the back of the sensor, as it were the rear side of the ‘eyes’ of the sensor.
You can use the sensor with the ‘Switch’ block. With this block you can choose between two conditions: closer
or further away than the selected distance. Similar to a camera a flower suggests nearby, the closer or ‘less
than’ option. The mountain suggests further away, the ‘farther than’ option.
You can also use the ‘Wait’ block. The action of the next block can only start when the condition of this block
has been fulfilled. So the robot waits for the condition to be realized. This condition could be “a distance
smaller than or bigger than a selected value”.
14 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
T A S K
What you need:
- tape, to mark a zone
- LEGO NXT with the LEGO ultrasonic sensor
- free standing table.
Task
You let the robot drive along the edge of the table, but ensure that the robot does not fall off the table. The
robot must always drive within an area of 20 cm from the edge of the table. At the corners of the table the area
is slightly rounded.
Track
Write down every step of your program in the grid below.
Which block do you use? Which are the settings you apply?
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 15
T A S K 5 : U SI N G T H E S OU N D S E N SOR
W H A T I S A S O U N D S ENS O R A ND WH A T D O W E U S E I T F O R?
The main function of a sound sensor is registering sound. With most sensors you can also register the sound
level. The best known example of a sensor that can measure the sound level is the decibel meter, but a baby
alarm can also register the sound level. If a baby cries too loud the “alarm” in the baby intercom of the parents
will sound: they will hear their baby cry.
Can you think of some examples yourself ?
-------------------------------------------------------------------------------------
H O W T O U SE T H E L E G O S O U N D S EN S O R
We measure the sound level in decibel (dB). When you talk to a
person in a normal voice the sound level will be around 40 to 60 dB.
When you make a lot of noise the membrane of the microphone will
move much more and you will measure a level of sound that is higher
than 90 dB.
The sound level of this sensor is represented in %.
< 5 % : quiet room
5-10% : talking at a distance from the sensor
10-30% : talking into the sensor/ playing background music
30-100% : shouting into the sensor/ very loud music
The sensor can also be turned into dBA mode by a contact point in the data hub.
The human ear is not as sensitive for all frequencies . The dBA mode will adapt the level of the measured sound
more to how we experience the sound level as a human being.
The sound sensor can register the difference between a normal voice and a loud voice. You can programme the
robot to complete a certain task when one person is giving the command and another task when there are
more people giving the command simultaneously.
The sound sensor is also able to recognise several sound patterns. Clapping your hands twice can have a totally
different meaning to the robot than clapping once.
Apart from different sound patterns the sensor also has the capability to register the difference in tone. This
way you are able to programme different commands depending on the pitch.
You can use the sound sensor in different ways:
This block can measure the actual sound level and then send this in a logical signal
(true/false) via the data link. If the sound level is above a certain limit, then the
‘true’ signal will be sent. If it’s under a certain limit it will send a ‘false’ signal.
16 Use of sensors | Cursus Basiskennis LEGO MINDSTORMS
A second way is using the ‘Wait’ block. It allows you to make the NXT robot wait until
the sound sensor registers the required sound level. Once this demand has been
fulfilled, the robot will continue to the next task.
A third way is using the ‘Switch’ block. This way you’re able to give the NXT robot a
task when it does not hear the required sound signal and one when it does. We call
this a true/false function. For example you’re now able to make the robot move
forward as long as the sound sensor doesn’t register 50% of its sound range. When it
does reach this sound level it will perform another task, such as driving around in
circles until the sound drops below 50% again.
T A S K
What you need:
- NXT basic model without sensors
- the sound sensor which is mounted on the side of the NXT
- black tape to mark the starting position
- bell or toy that makes a noise when you drive a lego car into it
- a cardboard box which is used as a garage.
Task
In this task the NXT robot must start from the starting position (S) and activate the bell (B). When the sound
sensor registers the signal the robot has to drive to the garage (G).
Track
Cursus Basiskennis LEGO MINDSTORMS | Use of sensors 17
Write down every step of your program in the grid below.
Which block do you use? Which are the settings you apply?