Museum at night

Museum at night is an international project that allows exploration of museums, galleries and heritage sites after hours. During this time there are many events, themed talks and immersive workshops late into the evening.

First LEGO toy was produced in 1932. In Denmark there is the LEGO Museum. Imagine that at night the toys become alive in the museum. They can speak and move. Film lovers know such cases - Museum at night or Toy Story present similar situations.

The aim of the lesson is to programme our robot to do something you want but only when it is dark around – at night.

Mathematical problem: arithmetic average.

Preparing For This Tutorial:

  • The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body of the robot (I’ll refer to use the Base Unit), plus a color sensor directed up (to better see the light).

  • Lessons: Basic (all topics).

image0 image1


Create a programme that will cause the robot to do something you want but only when it is dark around – at night.

  1. Create a programme in which the colour sensor measures the intensity of ambient light. The programme should end after pressing any brick button.

  2. Put down the results of your classmates when it is dark and when the light is on and calculate the arithmetic mean. Create a programme in which the robot asks you about the average and compare the intensity of light with this average and then write the message: light or dark.

  3. Modify your programme such that your robot moves, says something or plays any music file, switches on the light on the brick and displays some eyes when the light is off and does nothing (or only snoring) and has sleeping eyes when it is dark around.


Mean (Arithmetic Mean, Average) - The sum of all the numbers in a list divided by the number of items in that list.

Short help on programming

Commands/functions needed for the exercise.

Library ev3dev2

#!/usr/bin/env python3

import the necessary libraries

from ev3dev2.button import Button

from import \*

or from import ColorSensor

from time import sleep

Property in the ColorSensor class Available settings mode


#!/usr/bin/env python3
COL-REFLECT 0-100 Reflected light. LED color: red
COL-AMBIENT 0-100 Ambient light.
LED color: blue (dimly lit)
LED color: white
Raw Color Components.
LED color: white

Function from Sensor class - Returns the value measured by the sensor value()



cl denotes an instance of ColorSensor

Function in class Button. Checks any if any button is pressed.


#!/usr/bin/env python3



Helpful function for motors (for details see Module Motors)

#!/usr/bin/env python3

from ev3dev2.motor import LargeMotor



sounds (for details see Module Sounds)

from ev3dev2.sound import Sound


for display and LEDs (for details see Module Display)

from ev3dev2.display import Display




image.paste(im, (0,0))

im #file handling

for display and LEDs (for details see Module Display)

from ev3dev2.led import Leds


set_color('LEFT', 'AMBER')

About class Leds, Display, Sound, Motors see Basics Modules.


Next Section - Point to point drawing function