Robotics Book Level2
Robotics Book Level2
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
Table of Contents
UNIT-1 ______________________________________________________________ 3
WAIT FOR DISTANCE AND LIGHT _______________________________________ 3
CHAPTER-1 _____________________________________________________________________ 4
WAIT FOR DISTANCE BLOCK ____________________________________________________________ 4
CHAPTER- 2_____________________________________________________________________ 9
LIGHT __________________________________________________________________________________ 9
UNIT-2 ___________________________________________________________________________ 19
LIGHT SENSOR AND TASK RELATED TO LIGHT SENSOR _________________________ 19
CHAPTER 1 ____________________________________________________________________ 20
LIGHT SENSOR ________________________________________________________________________ 20
CHAPTER – 2___________________________________________________________________ 29
TASK RELATED TO LIGHT SENSOR _____________________________________________________ 29
CALIBRATION __________________________________________________________________________ 32
LINE FOLLOWING WITH OBSTACLE DETECTION AND REMOVING ________________________ 33
UNIT- 3_____________________________________________________________ 40
PARALLEL PROGRAMMING WITH RECORD & PLAY ______________________ 40
CHAPTER- 1____________________________________________________________________ 41
SEQUENTIAL & PARALLEL PROGRAMMING _____________________________________________ 41
CHAPTER- 2____________________________________________________________________ 46
RECORD AND PLAY BLOCK_____________________________________________________________ 46
UNIT-4 _____________________________________________________________ 52
DATA LOGGING & COLOR SENSOR ____________________________________ 52
CHAPTER 1 ____________________________________________________________________ 53
DATA LOGGING ________________________________________________________________________ 53
CHAPTER-2 ____________________________________________________________________ 62
LEGO COLOR SENSOR _________________________________________________________________ 62
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
2
UNIT-1
WAIT FOR
DISTANCE AND
LIGHT
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
3
CHAPTER-1
WAIT FOR DISTANCE BLOCK
Ultrasonic sensor:-
The Ultrasonic Sensor enables the robot to see and recognize objects, avoid obstacles,
measure distances, and detect movement. The Ultrasonic Sensor measures distance in
centimeters and inches. It is able to measure distances from 0 to 2.5 meters with a
precision of +/-3 cms.
Working Principle:
• The Ultrasonic Sensor measures distance by calculating the time taken by an
ultrasonic wave sent out by the emitter to bounce off an object and come back to
the receiver.
• The Sensor has two openings on its front; one emits ultrasonic waves, while the
other receives them.
• If the radio button to the left of the slider is chosen, the block will be triggered
when it detects an object that is closer than the trigger distance; select the right
radio button to trigger the block when it detects an object farther away than the
trigger distance.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
4
• In the configuration, the panel selects the unit (i.e. centimeter or inch) first
according to the condition.
Use the slider to set the trigger distance or type a value directly into the input box
(0-250 if configured for centimeters or 0-100 if configured for inches).
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
5
• Move block, forward, duration 500 degrees, port b
*******
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
6
CAN YOU ANSWER THIS?
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
7
6. What is a TABLETOP robot?
Answer: The tabletop robot is a robot that has an ultrasonic sensor
attached facing down. It can move on the edgeless tables without falling
off from the table.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
8
CHAPTER- 2
LIGHT
Before learning about the light sensor let us learn about what is light and some of the
terms related to light.
Light is the natural agent that makes things visible. We are able to see the objects and
things due to the presence of light. Like for example when we enter the dark room we
are not able to see anything due to the absence of light, but when we switch on the
lights we are able to see due to the presence of light. This clearly explains that light is
the only agent that makes things visible.
Sun is the biggest source of natural light. It makes things visible during day time, and no
artificial light source is required to make the things visible. At night time we are able to
see the things and objects due to the presence of the moon and stars. The light from
the moon and stars are not sufficient enough to make the things visible so we require an
artificial source of light during night time.
No? Then let us have a look at some of the real-life examples and figure out the path of
light.
The torch is one of the examples that can describe the path in which light travels.
When you lit the torch and do not specify the direction whether it is horizontal or vertical.
We see that light from torch always travels in a straight line. Let us proof this statement.
1. Take three index cards, use a ruler to draw lines connecting opposite corners of
the card.
2. At the intersection of the two lines, punch a hole in the center of the index cards.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
9
3. Make all the three index cards stand vertically and at an equal distance from
each other, just the way shown in the diagram.
4. Place the flashlight at one end of the row of index cards and turn off the light in
the room.
5. Arrange the index cards so that light can be seen through all the holes.
Now, you will notice that the light will come out from the holes which will prove that light
travels in a straight-line path.
A beam of sunlight can also justify the path of light. When there is a small hole in a
door or window of the room, we might be able to see a beam of sunlight entering the
room through that narrow opening.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
10
This explains the path of the light that is straight. Let us have a look over the below
diagram.
Laser light can also be one of the examples of light traveling in a straight-line path.
During childhood, we all must have played with the laser light. When we press the laser
light irrespective of the direction, we see that a beam of red light comes out from the
laser light and the light beam is always straight.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
11
Fig:1.2(iii) Light travels in a straight line path through the laser
Thus, all these examples prove that light travels in a straight-line path.
Shadow: Shadow is formed when some light rays continue to travel in straight lines
while other rays are stopped by an object. In simple terms, we can say that when an
object blocks the light’s path, then darkness appears on the other side. This darkness is
called the shadow.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
12
Fig:1.2(v)Shadow of a boy
From the figure above, we see that when the rays of the sun fall on the tree (dark
object) then the shadow of the tree is formed opposite to it. As we have already studied
that light travels in a straight-line path, so the rays of sunlight travel in a straight-line
path and when the tree blocks the path of the sun’s rays then a shadow is created on
the opposite side of the tree.
The same concept is applied to the second figure also. A boy standing, blocks the path
of sun’s rays and thus a shadow is formed on the opposite side.
When the object is solid then the shadow formed will be darker and when the object is
transparent or is not solid then none or very little shadow is formed.
REFLECTION OF LIGHT:
The bouncing back of the light rays after hitting any surface is known as a reflection of
light.
If the surface is smooth and shiny, like glass, or polished metal, the light will reflect at
the same angle as it hit the surface. The rough surface scatters the light instead of
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
13
reflecting it. Have a look at the diagram shown below to get a clear idea of the reflection
of light through different surfaces.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
14
We are able to see different colors of the objects due to the reflection of light. Objects
appear to be colored because some of the colors are being absorbed and some of the
colors are reflected.
White objects appear white because they reflect all colors. Black objects absorb all
colors so no light is reflected. The same is the case with all the colored objects. When
white light falls on the object some color is absorbed and the rest is reflected, the color
which is reflected back is the color of the object.
Dark color objects tend to be a good absorber and bad reflector while the light color
objects are good reflectors and bad absorber. As dark color objects absorb more light
and thus, reflect less light so they appear dark in color. While the white color objects are
capable of absorbing less light because they are already light in color that is full of light
and so they reflect more light.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
15
When the ray of light coming from an object strikes the smooth surface of a mirror, they
bounce back at the same angle. Our eyes are able to see these reflected rays like a
mirror image. The same is the case when we stand in front of the mirror. We are able to
see us in the mirror as our mirror image.
Look at the figure below to see the mirror image formation of a kid.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
16
CAN YOU ANSWER THIS?
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
17
4. What makes a different object to appear different in color?
a. Shadow
b. Light
c. Reflection of light
d. None of the above
Answers: 1) a 2) b 3) c 4) c
2. What is the reflection of light? Explain in detail what happens when light falls
on different types of surfaces.
Answer: The bouncing back of light rays after hitting the surface is known as
a reflection of light. If the surface is smooth and shiny, like glass, or polished
metal, the light will reflect at the same angle as it hit the surface. The rough
surface scatters the light instead of reflecting it.
4. Why white color object appears white and black color surface appears black
in color?
Answer: When white light falls on the surface of the white color object then it
reflects all the light so the surface of the white color object appears white in
color. Whereas when the white light falls on the surface of the black color
object then it absorbs all the light so the surface of the black color object
appears black in color.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
18
UNIT-2
LIGHT SENSOR
AND TASK
RELATED TO LIGHT
SENSOR
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
19
CHAPTER 1
LIGHT SENSOR
The light sensor is the sensor that enables the robot to distinguish between light and
dark surfaces. We use light sensors to measure the amount of light in a room. It also
helps to measure the amount of light over the colored surface. The port for the light
sensor is PORT 3. The figure given below shows the light sensor.
When we are in a dark room we are not able to see anything similar when we are in the
lighted area we can see everything because of the presence of light, similarly, robots
too have the ability to read the amount of light and can distinguish between dark and
light surrounding.
(If we switch OFF the room light the amount of light will decrease and when switched
ON intensity of light increases.)
The light sensor has two bulbs at its front. The above bulb is known as phototransistor
which is the receiver and the bulb just below it is the LED bulb which is the emitter.
The LED bulb acts as an emitter emits the red color light. This light falls on the surface,
after this, the light reflects back and is received by the phototransistor which acts as a
receiver.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
20
This is the working of two bulbs.
One emits the light and the other receives back the light after striking the surface.
Reading of light sensor: We can read the values of the light sensor by going into
view function in the brick. In View function, we select the option for reflected light and
then we select the default port for the light sensor that is PORT 3. Now, we can read the
light sensor values of different colored surfaces by facing the light sensor just two
modules above the surface of the object.
When we take the reading for different colored surfaces, we notice that the value for
dark colors is less than the value for the light colors as we have already studied that
dark colors are good absorber and bad reflector while the light color objects are good
absorber and bad reflector.
If 100% light falls on the dark surface then a maximum of 40% light will be reflected and
rest 60% of light is absorbed. And when 100% of light falls on the light surface then a
maximum of 70% of light is reflected and rest 30% of light is absorbed.
A wait block is a block that pauses the program at its current point until its condition is
achieved. We have already studied the different wait for blocks that are waiting for time,
wait for touch, wait for sound, etc. The figure shown below is the “wait for light” block.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
21
This wait for a block is called wait for light block because it waits for a particular light
condition. Wait for light block waits for the light sensor to detect the condition set for the
sensor (either intensity of light more than 50 or less than 50).
We all know that the dark objects absorb more light and thus reflect less light and the
light surface absorbs less light and thus reflects more light. That is why in summers we
are advised to wear light color clothes as light color absorbs less light and we will not
feel that much hot as we feel when we wear dark color clothes.
So, the same concept is applied over here also. When the light is emitted from the LED
bulb, it falls on the surface. The light is then reflected back and is received by a
phototransistor that is a receiver. Based on the light received we differentiate weather
the surface is dark or is a light surface. And to find out about this we have to first learn
about one more term that is “threshold value”.
Threshold value: Threshold value can be simply said as an average value or the
minimum value. When learning in terms of the light sensor then you can have two
values. One is the value for light surface and the other is the value for the dark surface.
We calculate both the readings one by one. First, connect the light sensor to its default
port that is PORT 3 then bring the light sensor to face the surface of the white surface
and similarly with the black surface. When the LED of the light sensor starts emitting red
light it means your connection is right and you can now take the readings. These
readings can be taken through the View function. Note that the distance between the
surface and the sensor should not be more than two modules so that we get the
accurate readings.
Now after taking the reading to add both the values and divide the sum by 2 to get an
average.
Now we compare the threshold value to the value we get through the phototransistor. If
the received value from phototransistor is greater than the threshold value then it means
that the surface is light surface (as light-colored surface reflects more and absorbs
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
22
less) and if the value received is less then it means that the surface is dark surface ( as
dark surface reflects less and absorbs more).
Thus, we can differentiate that the surface is light-colored or dark-colored with the help
of the threshold value. This calculation takes place in brick.
So wait for the light block will wait for the particular condition to be satisfied, i.e the
condition set for the light sensor. Till the condition is not satisfied, it keeps on waiting for
the particular condition to get satisfied. When the condition is satisfied, then only the
function of the next block is performed.
The above figure depicts the configuration panel of the “wait for light” block.
CONTROL: It allows you to select whether you want to use a Sensor or a Time-
based block.
SENSOR: It allows you to select which sensor you want to select. When you
select Wait for Light Block by default it will select Light sensor only.
PORT: It allows you to select the respective port where Light Sensor to be
plugged in. By default, the block will be set to Port 3 for a Light Sensor. Port can
be changed if you want to.
UNTIL: You can use the slider to set the trigger value or type a value directly into
the box provided. You have to select the radio button to the right of the slider if
you want the block to be triggered by light levels higher than the trigger value and
select the left radio button to trigger the block with light levels lower than the
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
23
trigger value. You can also use the pull-down menu to set the value greater
than(>) or less than (<).
We take the reading through the view function of the brick. In the view function when we
go for light sensor we see two light. One is the reflected light and the other is the
ambient light. Let us have a look at both forms of light.
Reflected light: The normal light which the phototransistor receives is known as
reflected light.
Ambient light: Except for the reflected light which is received, we have another type of
light also that is the ambient light. In surroundings also we have light present, this
surrounding light is known as ambient light. The ambient light may sometimes affect the
reading of the sensor, as this surrounding light is the unwanted light. So in order to take
the appropriate reading, we need to eliminate the surrounding light and this we do by
calibration.
We take the readings through reflected light. Move on to both the light surface and the
dark surface one by one and take the readings and find the threshold value and set the
value to the configuration panel.
Design and program a robot that will move forward until it detects
a black line and then the robot should take a turn parallel to the
line.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
24
• Move block, direction – stop, ports – B and C.
Design and program a robot which can detect the 3rd black
line and stop by using only 6 programming blocks
*******
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
25
CAN YOU ANSWER THIS?
2. In the configuration panel, if we select the value greater than 50 then the color
of the surface will be?
a. Dark
b. Light
c. Both a and b
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
26
d. None of the above
3. In the configuration panel, if we select the value less than 50 then the color of
the surface will be?
a. Dark
b. Light
c. Both a and b
d. None of the above
Answers: 1) c 2) b 3) a
1. What is the purpose of the light sensor and tell the default port for the light
sensor?
Answer: Light sensor is used to differentiate between the dark surface and the light
surface. The default port for the Light sensor is PORT 3.
2) What is the threshold value and tell the formulae for the same?
Answer: The threshold value is the average value of the dark surface and light
surface. The values taken from the light sensor are compared with the threshold
values to detect whether the surface is dark surface or are light surface.
3) How many bulbs does light sensor has and also explain their function?
Answer: There are two bulbs in the light sensor. The above one is called a photo-
transistor and the below one is called LED. LED bulb acts as an emitter and
emits light rays. These light rays fall on the surface of any object and some rays
are reflected back to the phototransistor.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
27
4) What is the “wait for light” block?
Answer: Wait for light block is used to pause the program for the particular light
condition, either dark or light
*******
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
28
CHAPTER – 2
TASK RELATED TO LIGHT SENSOR
LINE FOLLOWING
In this chapter, we will learn the concept of following any line that is either a black color
line or a white color line.
You will have to design the robot and program it in such a way that your robot should
follow either dark line if your mat is white or should follow the white line if your mat is
dark.
As we all know it is impossible for anything to move in a straight line, we can just
visualize that objects move in straight line path but in reality, no object can move in a
straight line on its own.
Example: You all have seen the railway tracks and the train moving on that railway
track. The train always moves over the railway track or you can say it always follows the
railway track.
Same goes with the robots, they never move in a straight line even if you program it to
move in the forward direction. It will move forward but never straight. It is somewhat
curvy.
So in order to design a robot that moves in a straight line path then, you would be
requiring a light sensor. As the light sensor is used to differentiate between the dark
color surface and light color surface.
So when you use a light sensor then you can easily differentiate between black lines
and white lines on the mat and can make the bot follow the dark line.
CONSTRUCTION:
Design a four-wheel robot with standing motor in such a way that great lines face in
backward direction and attach one light sensor in front of the robot such that the light
sensor should face in downward direction and it should be noted that the light sensor
should be just two modules above the surface of mat so that it can take the reading
precisely.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
29
CONCEPT AND WORKING:
Suppose your mat is white in color and you have a black line on it and the robot has to
move on that line only or you can say the robot has to follow that black line only while
moving so that it moves straight.
So pace the robot in such a way that the light sensor is facing just above the black line.
Now program in such a way that it should detect black and white only so that when
black color is detected by the light sensor than one of the motors move forward while
others are at the stop. And when the light sensor detects white then second motor
moves which were earlier at the stop and the one which was moving will now stop and
this process goes on in repetition. So you can see that it follows a zig-zag pattern as to
when one motor moves while other is stop making a swing turn pattern.
PROGRAM:
STEP 1: Take a switch block and set it to “Light Sensor”. You can set either “light >50”
or “light<50”.
STEP 2: In the true part of the switch, select a move block with Port: C, Direction:
backward, Duration: unlimited, Power: 50.
STEP 4: In the false part of the switch, select a move block with Port: B, Direction:
backward, Duration: Unlimited, Power:50.
STEP 7: Go to the tool and do calibrate the sensor and calibrate the light sensor and
download and run the calibrate program in the brick.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
30
Fig:2.2(i) Line following
APPLICATIONS:
There are various applications of line follower robot especially industries for carrying
various loads and other works. Some of the applications are listed below:
1) Line following robots is used for industrial purposes for transporting the goods
from one place to another place usually within the industrial compound.
As you all might have seen robot cars are used in the industries to carry heavy
loads. These are used to carry heavy loads to reduces human efforts and save
time.
In the figure below you can see, there is a robot car which is following the black
line on the floor and carrying the load. These types of robots are used in
industries to carry a heavy load and transport it from one place to another place.
This way a lot of time is saved as it is a robot so we can load lots of weight to it.
It follows the black line on the floor, the light sensor is attached which is is used
to follow the black line. Black line is drawn on the path such that the robot should
follow the path and reach the destination and transfer the parcel.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
31
Fig:2.2(ii) Robot car following the dark line
4) In hotels, they are being used for the transfer of things from one place to
another following a straight path.
CALIBRATION
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
32
instrument by comparing it to the standard values.
While taking the reading of the light sensor, the readings might get affected by the
surrounding light that is the ambient light. So at that time, we need to calibrate the light
sensor so as to get an accurate reading.
It is to be noted that we calibrate the only light sensor and sound sensor as these are
the only two sensors which get affected due to the surrounding.
• Select “Light Sensor” and choose the port number to which the light sensor is
connected.
• Press the Calibrate button to download the “Calibrate” program into the NXT brick.
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
33
Here, three concepts will be used. One is the basic line following and the second one is
obstacle detection. One new concept of the third motor is used here.
You will be using the third motor and that motor will be used for hitting the obstacle that
comes in the path.
You have already learned the concept of the basic line following, that is your robot will
follow the dark line only which is done using Light sensor. And while moving it has to
detect the obstacle also, so you can make your robot detect any obstacle using
Ultrasonic sensor.So here both Light sensor and Ultrasonic sensor will be used.
The robot has to follow the dark line on the mat until it detects any obstacle on its way.
Once an obstacle is detected, the robot has to stop until that obstacle is removed from
its way. As soon as the obstacle is removed, the robot should again start following the
black line.
It is clear from the above explanation that the concept of “if-else” is used that is you are
having two conditions.
Condition 1- Robot will follow the line and no obstacle is detected that is the obstacle is
out of range to which the ultrasonic sensor is set to.
Condition 2- Robot has to stop when the obstacle is detected that is the obstacle is
within the range to which the ultrasonic sensor is set to.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
34
Fig:2.2(iii) Line follow and obstacle detection
PROGRAMMING STEPS:
STEP 1: Take a switch block and set it to “ Ultrasonic Sensor” with distance < 15 cm.
STEP 2: In the true part of the switch select Move block with port: B and C as Stop.
STEP 3: Select another move block with port: A, duration: 110 degrees.
STEP 4: In the false part of the switch select another switch block and set it to “ Light
sensor “ with a light value greater than 50 in the configuration panel.
STEP 5: In the true part of the second switch block select Move block with Port:” C”
Direction: “Forward”, duration:” Unlimited “ and another Move block in series with Port:
“B”, Direction: “Stop”
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
35
STEP 6: In the false part select Move block with Port:” B” Direction: “ Forward”,
duration:” Unlimited “ and another Move block in series with Port: “C”, Direction: “Stop”
STEP 8: Go to the tool and do calibrate the sensor and calibrate the light sensor and
download and run the calibrate program in the brick.
*******
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
36
CAN YOU ANSWER THIS?
So pace the robot in such a way that the light sensor is facing just above the black
line. Now program in such a way that it should detect black and white only so that
when black color is detected by the light sensor than one of the motors move
forward while others are at the stop. And when the light sensor detects white then
second motor moves which were earlier at the stop and the one which was moving
will now stop and this process goes on in repetition. So you can see that it follows a
zigzag pattern as to when one motor moves while other is stop making a swing turn
pattern.
2) What are the cautions kept in while doing the task of the dark line following?
Answer: While making the bot for dark line following, the light sensor should be
attached facing a downward direction and the sensor should be placed two modules
above the ground.
3) Write down the application where the concept of line following is used.
Answer: Some of the application where the concept of the dark line following is
used is a follows:
a) line following robots is used for industrial purposes for transporting the goods from
one place to another place usually within the industrial compound.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
37
d) In hotels, they are being used for the transfer of things from one place to another
following a straight path.
4) Write down the programming steps for the dark line following.
STEP 1: Take a switch block and set it to “Light Sensor”. You can set either “light
>50” or “light<50”.
STEP 2: In the true part of the switch, select a move block with Port: C, Direction:
backward, Duration: unlimited, Power: 50.
STEP 4: In the false part of the switch, select a move block with Port: B, Direction:
backward, Duration: Unlimited, Power:50.
STEP 5: Take another move block with Port: Direction: stop.
STEP 7: Go to the tool and do calibrate the sensor and calibrate the light sensor
and download and run the calibrate program in the brick.
5) Which are the sensors which require calibration and why?
Answer: There are only two sensors that require calibration, they are light sensors and
sound sensors. These are the only sensor which gets affected by the surrounding. Like
sound sensor is affected by the surrounding light that is the ambient light and the sound
sensor gets effected due to the environmental sound that is noise or extra sound.
6) Write down the programming steps for line following and obstacle detection and
hitting the obstacle that comes to the path using the third motor concept.
STEP 1: Take a switch block and set it to “ Ultrasonic Sensor” with distance < 15 cm.
STEP 2: In the true part of the switch select Move block with port: B and C as Stop.
STEP 3: Select another move block with port: A, duration: 110 degrees.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
38
STEP 4: In the false part of the switch select another switch block and set it to “ Light
sensor “ with a light value greater than 50 in the configuration panel.
STEP 5: In the true part of the second switch block select Move block with Port:” C”
Direction: “Forward”, duration:” Unlimited “ and another Move block in series with Port:
“B”, Direction: “Stop”
STEP 6: In the false part select Move block with Port:” B” Direction: “Forward”,
duration:” Unlimited “ and another Move block in series with Port: “C”, Direction: “Stop”
STEP 8: Go to the tool and do calibrate the sensor and calibrate the light sensor and
download and run the calibrate program in the brick.
5) Explain the concept and working of line following and obstacle detection and
hitting the obstacle that comes to the path using the third motor concept.
Answer: This task is based on the concept of the line following using a light sensor
and obstacle detection using the ultrasonic sensor.
Firstly, it checks if the obstacle is not within the range then the robot keeps on
moving by following the dark line. If any obstacle comes within the range then the
robot stops and the third motor moves and hits the obstacle and removes from the
path.
********
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
39
UNIT- 3
PARALLEL
PROGRAMMING
WITH RECORD &
PLAY
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
40
CHAPTER- 1
SEQUENTIAL & PARALLEL PROGRAMMING
Like for example, if you want to make your robot stop when it detects any obstacle and
then moves backward.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
41
Fig:1.1(ii) Simple sequential programming
This whole program will be executed sequentially, which is one by one in a series. Like
the first move block moves forward, then wait for distance block will be executed then
again move the block with stop and finally move the block with backward direction is
executed.
Once the action of the first block is performed then only it will perform the actions of the
next block. No two blocks are performed together or in a jumbled form. But what if we
want to perform the actions of two blocks simultaneously means when the actions of
two blocks should be performed in parallel?
For example, if you want your robot to stop when the touch sensor is pressed or you
want to stop your robot when it detects any object inside 10cm of range. Then this
sequential programming we do will not work because at a time it can execute just a
single block action and then checks for the next block. But we want to check for both the
conditions at once.
first make the program for the robot to stop when it detects any obstacle at a distance
less than 10cm. Now just below this program make another program for the robot to
stop when the touch sensor detects any obstacle and the touch sensor is pressed. You
will see that the program made in the second line is grayed out. Now from the start of
the mainline program take the wiring and extend the wiring downward and join the grey
line program so that both the programs are parallel and will be executed simultaneously
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
42
Fig: 1.1(iii) Simple parallel programming
So now the robot will check for both the sensors simultaneously. And when either of the
condition is fulfilled the robot will pause and when both the sensor’s task is executed
that is when the touch sensor is pressed as well as the object is found inside the range
of 10 cm then the robot will stop.
Hence, in parallel programming, the blocks which are placed in parallel will execute
simultaneously.
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
43
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
……………………………………………………………………………………………………...
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
44
3) Explain the steps for parallel programming to pause the robot when the touch
sensor is pressed and also pause at the same time when the object is
detected inside the range of 10cm.
Answer:
******
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
45
CHAPTER- 2
RECORD AND PLAY BLOCK
Record and play is the second block of the Common Palette. This block helps you to
record the actions that you act upon the robot and later on, we can play those recorded
actions. It does this by remembering each number of times the motor has been turned
on your robot and record all the actions of the robot and later on play these movements
with exactly the same number of turns that have been recorded by selecting the “Play”
option in the Record and Play block.
1) Record: To record the actions you will have to select the motors with which you
want to perform the actions from the recording section. In the recording section,
you would see the ports for selecting the motors. Then select the time frame for
which you would like to record your actions. The time duration selected will be in
seconds. Even if your work is accomplished before the selected time frame, the
robot will be in pause state till the time selected is over.
Like if you have selected the time frame as 10 seconds and your task is done
within 6seconds then for the remaining 4 seconds your robot will be in pause
state.
2) Play: It will just play all the actions which you have recorded for the particular
time frame. It should be noted that the name by which the actions have been
recorded should be the same when played.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
46
Fig:1.2(ii) Play Action
For example, if you want to make your robot move forward for 4 rotations and
then moves backward for 4 rotations.
Let us check the steps for record and play block and learn how to program the
robot and learn the concept of the record and play block.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
47
Fig:1.2(iv) Configuration panel for play
Suppose the selected time is 10 seconds for recording the actions. So when you run the
program for the first 10 seconds your running program will be for record, so you have to
move your selected motors and perform the actions for 10 seconds and these actions
will be recorded and will be saved. Then leave your robot and for the next 10 seconds,
your robot will perform the actions which have been recorded in the previous 10
seconds.
Suppose you want to construct the robot which has to move forward until it detects any
obstacle and then comes back to its initial position when the object is detected.
STEPS:
1) Select “Move” block with port B and C both in the forward direction, the duration
will be unlimited.
2) Select wait for distance block and the duration will be less than 10 cm.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
48
3) Select move block with motor CB forward direction and change the steering by
bringing the notch under any of the port, either B or C port. So that it takes a
point turn.
4) Now parallel to the above program select one record and play block, extend the
line from the above program and join it the record and play block.
5) In record and play block first select action as “record” and select the motors from
the recording that is B and C. Now select the time frame for which you would like
to record this action(nearly 10seconds).
6) Now select again record and play in serial to the first record and play block. And
set the action as “play” in it.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
49
CAN YOU ANSWER THIS?
2) Write the steps to make your robot move forward until it detects an
obstacle at the range of 10 cm and then comes back to the initial position
when the object is detected.
Answer:
1) Move B and C motor, the direction forward and duration unlimited.
2) Wait for distance block with a distance < 10 seconds.
3) Move B and C stop.
4) Move B and C motor, the direction forward and duration 540 degrees,
the notch of the steering should be under motor C.
5) Select the record and play block in parallel to the above program line
and select action as “record” and Port B and C with time 10 seconds.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
50
Select the line from the mainline program’s first block and extend it
downward and join it to the record and play block.
6) In serial to the record and play block select another record and play
block and select the action as “play.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
51
UNIT-4
DATA LOGGING &
COLOR SENSOR
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
52
CHAPTER 1
DATA LOGGING
Before we study the NXT data logging, we have to learn about the concepts of the
graph and some terms related to the graph.
GRAPH: Graph is basically the representation of data in a quick way, or it shows the
relation between two or more variables. A basic two- dimensional graph consists of a
horizontal axis and a vertical axis.
ORIGIN: The point where x and y-axis meets is known as the origin.
COORDINATES: At any given point on the graph, the value of the variable on the x-
axis is paired with the value of the variable on the y-axis, and these two values are
known as coordinates. The value of the variable on the x-axis is known as x-coordinate
and the value of the variable on the y-axis is known as y-coordinate.
The above figure shows the simple 2-dimensional graph with (2,3) as its coordinates
where x-coordinate value is 2 and the value for y-coordinate is 3.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
53
USES OF GRAPH:
The main purpose of the graph is to present data that are too complicated to be
described in the form of text as it can display a lot of information in an easy to
understand format. Graphs are basically used to track changes over a short or long
period of time. These are used to check the trend at some particular period and
compare the data. It is much simpler to understand the data, numbers, etc which are
expressed in the form of a graph than when written in the form of statements. As it is
easier to see the relationship between the two sets of data and also we can get a better
understanding of the broad meaning.
Like for an instance, if we want to check the trend of the population for certain years so
we generate a table with the year in one column and population of that particular year in
another column.
It will take a lot of time to get to know about the trend, whether the population is
increasing or decreasing after a particular year. We can’t figure it out with a glance.
But when we build a graph for population versus year, we can easily get to know the
trend, whether the population is increasing or decreasing. As the line graph is drawn is
easy to understand and takes less time.
Hence, the graph helps us to understand the trend easily as compared to the table or
raw statements. As now we are clear about the graph and its uses, let us learn about
data logging in NXT.
Data logging is the process of collecting and storing data over a particular period of time
in order to analyze the specific record of the data-based events of an experiment. The
data can be distance measurement, temperature, intensity measurement, humidity,
sound intensity, etc. It is very helpful in our day to day life, like for an instance if we want
to if you wanted to know how the temperature changes during the course of an entire
day, you could sit by a thermometer, carefully recording the temperature every five
minutes on a sheet of paper, and then graph the results later but it will take a huge
amount of time to record the temperature manually and then plot the graph accordingly.
So now comes Data logging into the picture, with data logging we can easily get the
data in a graphical format about the temperature changes with respect to time and can
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
54
get to know easily the trend that is when the temperature is increasing and when it is
decreasing.
As we have learned that NXT data logging requires some information in the form of data
so that to form a graph and we all know that Robots have the ability to sense and get
the information from the surrounding with the help of different types of sensor we have.
So this information taken by the robot from the surrounding will act as data.
We have two blocks for data logging, named start data logging and stop data logging.
We have already studied 5 different types of sensor till now that is Touch Sensor,
Sound Sensor, Light Sensor, Ultrasonic Sensor, and Color Sensor.
NXT data-logging experiments can be done to form a graph that will help us to provide
the reading of the sensors like maximum value, minimum value, mean, median, mode,
etc. All the experiments provide the accurate value of the sensor’s reading at a
particular point in time.
Touch Sensor: Using NXT data logging we can build the graph for all the three
conditions of the touch sensor that is pressed and released over a particular period of
time with the help of a touch sensor.
Sound Sensor: Using NXT data logging we can build the graph for variation in the
intensity of sound at any place at some particular period of time with the help of a sound
sensor.
Light Sensor: Using NXT data logging we can build the graph for light-colored surface
and dark-colored surface over a particular period of time with the help of a light sensor.
Ultrasonic Sensor: Using NXT data logging we can build a graph for change in
distance over a particular period of time with the help of an ultrasonic sensor.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
55
Color Sensor: Using NXT data logging we can build a graph for various different
colored surfaces over a particular period of time using a color sensor.
Also, NXT data-logging experiments can be done to form a graph that will help us to
provide a reading for the movement of the motor. The motor which we use is the servo
motor. Servo motor is used to take accurate readings in rotation or in degrees and this
happens, with the help of a sensor. It has one sensor attached inside it, which is the
Rotation Sensor. This rotation sensor helps to measure accurately how much rotations
or degrees the motor has been rotated. So, using NXT data logging we can build the
graph for the motion of motors in various directions and for different durations.
NXT data logging block is present in the “Complete Palette”. The last block of the
Complete Palette has two blocks for data logging. One is “Start data logging” and the
other one is “stop data logging”.
In the “start data logging” block you will have to select the name of the experiment, time
for the experiment and the motors or sensors you will be using and their dedicated
default ports.
Also, you can directly go to the data logging block from NXT G 2.1 software itself. When
you open the software, a screen will pop up with a “start new program”. Write the name
and then click on “Go”.
Then, a control panel will be popped up like the one shown below.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
56
Fig:2.1(v) Control panel for NXT data logging block
Name: Write any name with which you would like to save your experiment.
Duration: This will show you till how much duration you would like to take the readings.
By default, we see 10 seconds, but from the drop-down, you may change it to minutes
also and can also change the number.
Rate: It depicts the rate number of samples generated over a particular duration which
you have selected. We have two options for this. By default we see “5 samples per
second”, you may also change it to “seconds between samples”.
Like if you have selected duration as 10 seconds and rate as 5 samples per seconds
then the graph you will get will show 5 samples of reading for each second.
Now you see “None” on the right side. Here you have an option to select for any sensor
for which you would like to take the reading, you can select any of the 5 sensors but you
would be able to select 4 sensors at a time. The ports for sensors are 1, 2, 3 and 4 and
the ports for the motor are A, B and C. Also, there is a drop-down menu just to the right
side. Select the port number in which the sensor is connected from there. After making
all the selections click on “OK”.
Click on download and run and then identify the formation of the graph.
You will see a screen with the x-axis and y-axis.the x-axis will show an interval of 5 per
second. Now, you will be able to see the panel from where you can download the
program.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
57
Fig:2.1(vi) Download icon for NXT data Logging
In this way, you will get the readings of the particular sensor over a particular period of
time in a graphical format.
In this, we have the additional features of “upload” which we do not have in simple
NXT programming. In upload, we can upload the experiments which we have created.
Later on, when we want we can use and see this uploaded experiments which are
present by the log name with particular date and size.
Create any experiment, download it and now in the data logging upload the same
experiment and do remember the name by which you have created the experiment.
Later on, when required you can have a view over the uploaded graph at any place and
at any time. So this is another advantageous feature of data logging.
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
58
………………………………………………………………………………………
………………………………………………………………………………………
1. What is a graph?
Answer: Graph is basically the representation of data in a quick way, or it
shows the relation between two or more variables in an easy to understand
way.
i) First, open the NXT-G Software and Enter the Program name, then
click on "GO".
ii) Then put one move block set to 5 rotations and then using the
parallel programming place the NXT-Data Logging Block and then
Choose the "Rotation Sensor" and their respective port i.e. B&C.
iii) To get the Values and Graphical representation of "NXT DATA
LOGGING - Rotation Sensor " we need to follow steps as
mentioned below :
STEP 4:| Click on analysis Tools (Location: North West- 12th option) |
Select Section Analysis |
3. At any given point on the graph, the value of the variable on the x-axis is
paired with the value of a variable on the y-axis, and these two values are
named as?
a. X- coordinate
b. Y-coordinate
c. Coordinates
d. Origin
Answers: 1) c 2) b 3) c
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
61
CHAPTER-2
LEGO COLOR SENSOR
We have already read about the light sensor, they are used to differentiate between the
dark surface and the light surface. As light sensor treat all the light color shades as the
light color and all the dark color shades as dark color. It does not tell the exact color of
the object whether it is yellow or white or black. We have another type of sensor that is
a color sensor that has the ability to differentiate among various different ranges of
colors.
The color sensor is used to detect the different colors of the object, unlike the light
sensor they do not differ only between dark and light colors. Rather, they are used to
detect various different types of colors. The color of any object is resulted due to the
interaction of light source, object, and observer. The color sensor is used to measure
the intensity of light just like the light sensor and is also used to detect the color of the
object.
Lego Color sensors can detect only 6 colors in the range 1-6 whereas the Hi-Technic
color sensor is used to detect 18 different types of colors in the range 0-17. The colors
that are detected by the Lego color sensor are “black”, “blue”, “green”, “yellow”, “red”
and “white”. The figure below shows the Lego color sensor.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
62
Whenever we attach the color sensor with the brick through connecting cables, we see
that it start emitting a combination of 3 different colors that is “blue”, “green”, “red” from
the RGB LED which shows that the Lego color sensor is working properly.
When we place the color sensor above any surface then we get the numerical value
when any target color is identified. You should keep in mind that the color sensor is
placed 2 modules above the surface of the target object and not more than 2 modules
so that to get the accurate reading.
We have already read about the wait for time, wait for touch (touch sensor), wait for
sound (sound sensor), wait for light (light sensor), and wait for distance (ultrasonic
sensor). Now we will study the wait for color block.
Wait for color, waits for the particular color we have selected.
In common palette, we have a wait block, select wait block and in the configuration
panel, we see sensor option with the drop-down, from there we select the color sensor.
Whenever we select color sensor we see that by default port 3 is selected as the default
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
63
port for the light sensor is PORT 3 and the color sensor acts just like the light sensor
except that the light sensor differentiate between the light and dark surface while the
Lego Color Sensor has the ability to differentiate among 6 different colors.
In color sensor we have the option for selecting 6 different types of colors, at a time we
can select single, or can select two consecutive colors at a time or can select all the six
colors at a time and command the robot accordingly.
Fig: 3.1(iii) Different set of color that is detected by the Lego Color Sensor
For that purpose, we have the option of inside range and outside range. Let us learn
about them briefly:
Inside range: In the configuration panel we see an option for inside range and outside
range. We can move the notch in the color range we wish to choose. Suppose we
select “White” so we will move the notch in such a way that white is selected. And when
we have selected for inside range then the robot will wait for white color. Similarly, we
can select any of the 6 colors and move the notch accordingly. Also, we can select any
number of colors at a time or even all the six colors at a time. Inside range denotes the
colors which are selected between the notches.
In the image shown above the range that is selected is only of yellow color. This means
that the condition that needs to be attained is only of yellow color.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
64
Outside range: the Outside range is just the opposite of the inside range. The colors
which are outside the notches are called the outside range color. If in the configuration
panel we go for outside range and select “White” so the robot will wait for the rest of the
5 colors except the white color. Here also we can select any number of colors from the
panel which we want.
In the image shown above the selected condition is for outside range. This means that it
will select colors other than yellow.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
65
Fig:3.1(vi) Hi-Technic Color Sensor
In the case of the Hi-Technic color sensor, there is no need for doing calibration as
these are unaffected by ambient light.
When we talk about the placing of the sensor then, Lego color sensor can be placed
straight also and at an angle also but when we come to Hi-Technic color sensor then
they are always supposed to be placed at an angle because the light that is emitted
from the sensor can cause obstruction while reflecting.
Lego color sensor differentiates among 6 different colors so it is somewhat easy but in
Hi Technic color sensor, it differentiates among 18 different colors. So, because of the
large range of colors we will have different shades of same color and the bot may mis-
interpret the color because of the amount of light present in the surrounding.
Write a program that will make a sound for all the different six
different colors that it will detect.
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
………………………………………………………………………………………………………
……………………………………………………………………………………………………..
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
66
CAN YOU ANSWER THIS?
B. True or false:
2) The hi-technic color sensor can detect the color efficiently from a distance of
5 modules. True
4) Calibration is required for the Hi-Technic color sensor as they are affected by
ambient light. False
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
67
C. Answer the following questions:
1) Give any two difference between the Lego color sensor and the Hi-Technic
color sensor.
Answer: The two differences between Lego color sensor and hi-technical color
sensor are as follows:
a) Lego color sensor can distinguish among 6 different types of colors
while the Hi-Technic Color sensor is used to differentiate among 18
different types of colors.
b) Lego color sensor works efficiently when the sensor is kept at a
distance of 2 modules from the surface whereas Hi-Technical color
Sensor can work efficiently up to 5 modules.
Answer: Inside range: If we select any of the colors from the configuration panel
with the help of notch, so the colors enclosed within the notch is called inside the
range.
Outside range: If we select any of the colors from the configuration panel with the
help of notch, so the colors which are not enclosed within the notch will be
outside range. This is just the opposite of the inside range.
3) How many colors can be distinguished by the Lego color sensor? Name
those colors also.
Answer: The Lego color sensor can distinguish among six different colors.
The colors are as follows: “Black”, “Blue”, ”Green”, ”Yellow”, ”Red” and “White”.
Answer: Wait for block is used to pause the robot for some particular color we
have selected, depending upon the inside range or the outside range.
Disclaimer:
All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the express written permission of ROBONITE Robotics and STEAM Education
PVT LTD except for the use of brief quotations in a book review.
68