Lego Mindstorms EV3: Using the Color Sensor

The Color Sensor can detect the color or intensity of light that enters the small window on the face of the sensor. The Color Sensor can be used in three different modes: Color Mode, Reflected Light Intensity Mode, and Ambient Light Intensity Mode.
Color Mode

In Color mode, the Color Sensor can detect the color of a nearby object, or the color of a surface near the sensor. You can use the Color mode to detect, for example, the color of a LEGO part held close to the sensor, or the color of different markings on a piece of paper.

Tips and Tricks
When the Color Sensor is in Color mode, red, green, and blue LED lights on the front of the sensor will turn on.
The sensor can detect seven different colors: black, blue, green, yellow, red, white, and brown. An object that is not one of these colors may be detected as “No Color”, or it may be detected as a similar color. For example, an orange object might be detected as red or yellow, depending on how much red the orange has in it, or as brown or black if the orange is very dark or too far away from the sensor.

Διαβάστε περισσότερα «Lego Mindstorms EV3: Using the Color Sensor»

Lego Mindstorms EV3: Using the Ultrasonic Sensor

The Ultrasonic Sensor can measure the distance to an object in front of it. It does this by sending out sound waves and measuring how long it takes the sound to reflect back to the sensor. The sound frequency is too high for you to hear (“ultrasonic”).

You can measure the distance to an object in either inches or centimeters. You could use this to, for example, make your robot stop a certain distance from a wall.

You can also use the Ultrasonic Sensor to detect whether another ultrasonic sensor nearby is operating. For example, you could use this to detect the presence of another robot that is using an ultrasonic sensor nearby. In this “listen only” mode, the sensor listens for sound signals but does not send them.

Ultrasonic Sensor Data
The Ultrasonic Sensor can give the following data:
Data Type Range Notes
Distance in Centimeters Numeric 0 to 255 Distance to object in centimeters.
Distance in Inches Numeric 0 to 100 Distance to object in inches.
Ultrasound Detected Logic True/False True if another ultrasonic sensor is detected.
Tips and Tricks
The Ultrasonic Sensor works best to detect objects with hard surfaces that reflect sound well. Soft objects, such as cloth, may absorb the sound waves and not be detected. Objects with rounded or angled surfaces are also harder to detect.
The sensor cannot detect objects that are very close to the sensor (closer than about 3 cm or 1.5 inches).
The sensor has a wide “field of view” and may detect a closer object off to the side instead of a farther object straight ahead.
Examples Using the Ultrasonic Sensor
Some examples of how you can use the Ultrasonic Sensor in your program are shown below.
Example 1: Stop a Certain Distance before a Wall
This program makes a robot drive forward until the Ultrasonic Sensor detects something closer than 10 inches, then the robot is stopped. The program uses the Wait block in the Ultrasonic Sensor – Compare – Distance Inches mode to wait for the detected distance to become less than 10 inches. If the Ultrasonic Sensor is facing forward, the robot will stop about 10 inches before a wall.
Tips and Tricks
Remember to use the On mode of the Move Steering block when you want to drive while waiting for a sensor.
Example 2: Sound an Alarm when an Object is Detected Nearby
This program has the robot make a sound whenever the Ultrasonic Sensor detects an object closer than 50 centimeters away. The program uses a Switch with the Ultrasonic Sensor – Compare – Distance Centimeters mode to test whether the distance detected is less than 50 centimeters. If so, the Switch plays a tone. The Switch is repeated in a loop so that the test is repeated continuously.
Tips and Tricks
While running this program, try moving objects around in front of the sensor to experiment with how wide the sensor’s “field of view” is.
Example 3: Gradually Slow Down Before Reaching an Object

This program makes a robot gradually slow down and then stop about 10 cm away from anything it detects in front of it. The closer it gets to the object, the slower it will drive.

The program uses the Ultrasonic Sensor block in the Measure – Distance Centimeters mode to get a distance measurement and get the resulting number on a data wire. A Math block then subtracts 10 from the distance, and the result is wired to the Power input of a Move Steering block. Shorter distances result in lower power, and when the distance reaches 10 cm, the power will be zero, and the robot will stop. The process is repeated in a loop so that the motor power is adjusted continuously based on new distance measurements.

Tips and Tricks
You can also try moving the object while this program is running. The robot will continuously adjust its speed.
Ultrasonic Sensor Blocks and Modes
The table below shows all of the programming blocks and modes that you can use with the Ultrasonic Sensor. The Distance modes have sub-modes that let you choose between centimeters and inches.
Block Mode Use
Wait Ultrasonic Sensor – Compare – Distance Wait for the distance to reach a certain value.
Wait Ultrasonic Sensor – Compare – Presence/Listen Wait, in “listen only” mode, for an ultrasonic signal to be detected.
Wait Ultrasonic Sensor – Change – Distance Wait for the distance to change by a certain amount.
Loop Ultrasonic Sensor – Distance Repeat a sequence of blocks until the distance reaches a certain value.
Loop Ultrasonic Sensor – Presence/Listen Repeat a sequence of blocks until an ultrasonic signal is detected, in “listen only” mode.
Switch Ultrasonic Sensor – Compare – Distance Choose between two sequences of blocks based on the distance.
Switch Ultrasonic Sensor – Compare – Presence/Listen Choose between two sequences of blocks based on whether an ultrasonic signal is detected in “listen only” mode.
Ultrasonic Sensor Measure – Distance Measure the distance and get the result on a Numeric data wire.
Ultrasonic Sensor Measure – Presence Listen for other ultrasonic signals in “listen only” mode, and get the result on a Logic data wire.
Ultrasonic Sensor Compare – Distance Compare the distance to a threshold, and get the result on a Logic data wire.
Ultrasonic Sensor Compare – Presence/Listen Listen for other ultrasonic signals in “listen only” mode, and get the result on a Logic data wire.
Ultrasonic Sensor Measure – Advanced Similar to Measure – Distance, but with the option to make only a single sound ping.
Data Logging See Data Logging.


Lego ΕV3: Eντολή Switch

EV3 Robot Educator Tutorials : Switch
Use the Switch block to make dynamic sensor-based decisions.

Build the Driving Base model and the Color Sensor Down Module.


Recreate the program shown, then download and run to test.

The Port View App on the EV3 Brick can also be used to view real-time sensor readings.

Program Summary

Move Steering – Degrees[685], Steering[100]
Wait – Time[1s]
Move Steering – Degrees[1380], Steering[50]
Wait – Time[1s]
Move Steering – Rotations[2], Steering[25]


A threshold sets the upper and lower limits of a sensor and uses them to find the average, which then becomes the threshold. On the following pages, you will set the threshold of the Color Sensor’s sensitivity to light.


First, make sure the Driving Base is connected via USB and then move the Color Sensor over the dark line.


Next, open the Hardware Page and note down the value shown on Port 3. This is the minimum value (x).

Now move the Color Sensor away from the dark line.


Note down the new value shown on Port 3. This is the maximum value (y).

To set the threshold, calculate the equation (x+y)/2 and enter the result in the Wait block (your value may differ from the example shown).

Next, download the program.


Now it’s your turn! Test if your Driving Base works when following a lighter-colored line! If not, try setting the threshold again.

At some point, the sensor light reflecting off the line will exceed the threshold, causing the Driving Base to drive in a circle. If this occurs, change the threshold Value.

If the difference between the x and y values is too small, the line will not be detected. If this occurs, try recalibrating the sensor.

LEGO EV3: Eντολή Move Objects

EV3 Robot Educator Tutorials:   Move objects

Program the Driving Base to move and release the Cuboid.
STEM Engineering Robotics Technology. Grades 6-8  0-30 min. Beginner 2-4

Build the Driving Base model, the Medium Motor Module, and the Cuboid.



Recreate the program shown, then download and run to test. Make sure the Medium Motor Module is vertical before you start.

The model can be manually reset by lifting the Medium Motor Module by hand.

Lego EV3: Eντολή Curved Move

EV3 Robot Educator Tutorials: Curved Move

Use the Move Steering block to steer the Driving Base.

STEM Engineering Robotics Technology, Grades 6-8 0-30 min, Beginner 2-4

Build the Driving Base model.  VIEW BUILDING INSTRUCTIONS


Recreate the program shown, then download and run to test.

Use the Wheel Pointers to help understand the relationship between motor and Driving Base rotation.
Students often assume a 90 degrees motor turn is equal to a 90 degree driving base turn.
Note that the distance between the driving wheels will affect the turning radius.

Lego EV3: Eντολή Move Tank Block

The Move Tank block can make a robot drive forward, backward, turn, or stop. Use the Move Tank block for robot vehicles that have two Large Motors, with one motor driving the left side of the vehicle and the other the right side. You can make the two motors go at different speeds or in different directions to make your robot turn.

Left motor
Right motor

Tips and Tricks
Robot vehicles with two drive motors can also be controlled by the Move Steering block. The Move Steering block is similar to the Move Tank block, but has a different way of controlling turns.
Choose your Motor Ports and Control Mode

Port Selector
Mode Selector