7. The visitor, the tell-tale

The visitor, the tell-tale

Make the mBot turn on its LED lights for a few seconds when the light turns on and someone is nearby.

Afterwards, let the mBot drive backwards to see if someone has been in your room. 

You will learn:

  • How to work with the light sensor in combination with the distance sensor. 
  • How to measure a light value and distance value and make them appear on your screen. 

Open the mBlock programme on your computer, turn on your mBot and connect.

PREPERATION

Check the steps in "execute". Answer the following questions:

  • Which steps should I follow?
  • Which steps can I take?
  • How much time do I need?
  • What tools do I need?

EXECUTE

Perform the steps one by one. Have you forgotten how to do it? Look at the hints or download the solution.

STEP 1

Displaying the values

We will need two sensors for this.  The light sensor, and the ultrasonic sensor (distance).  Do you know where they are located? 

You want on your screen to show what the light value (“light =...) and the distance value is (“distance =...”). To do this, you will need to merge some blocks.  We will show which blocks you can use for this. 

Try out different situations.  Make it darker, try out different distances. 

Notice how the distance is constantly changing.  You can solve this by setting the block “Ultrasonic sensor...” in a “rounded” block. 

blocks

STEP 2

Switching on the LEDs

As soon as someone is standing in front of the mBot, the lights must turn on.  IF the distance is shorter...  THEN. 

Do you know which blocks you will need to use? 

STEP 3

When the light turns on.

The mBot may only light up its LEDs when the light in your room comes on.  IF light sensor... THEN

Based on the previous step, you already know which blocks you can use for this.  Be sure to think about where you will write this in your programme.

Tip:

Dim the lights after the green flag is clicked.

blocks

STEP 4

Moving some more

Your mBot already signals when someone enters your room.  But afterwards, you won’t know.  Make sure that the mBot, aside from turning on its lights, also moves when someone is there. 

It only needs to move for one second.

uitdaging

If you want the mBot to check your room without being connected to your computer, start with "mBot program" instead of "When green flag is selected".

The programme will need to be uploaded. Switch out the blocks that aren't supported when you upload.

Congratulations, your room is now being guarded by your mBot.

REFLECTING

Look back at the project you just made. Ask yourself the following questions:

  • Does the programme work like I expected?
  • What is working well?
  • What is not working well?
  • How can I do things differently?

Download

Click on the links below to download the solutions: