9-10 STEM

Science | Technology | Engineering | Maths

Lego robotics


Term 1: Dancing robot project

TEAM 1 - Teachers

  1. Mrs Davies

  2. Mr Harrison

TEAM 2

  1. Lucas J

  2. Cam

  3. Otto

TEAM 3

  1. Dom

  2. Kenneth

  3. Preston

TEAM 4

  1. Leith

  2. Tobi

  3. Trent

  4. Siyan

TEAM 5

  1. Lukas D

  2. Sam

TEAM 6

  1. Lucas B

  2. Mathew

TEAM 7

  1. Brody

  2. Devon

  3. Luke G

  4. Ollie

dancing robot - image from: https://dribbble.com/shots/1797277-TechTown-Lego-Robot-Animation

The brief

In assigned groups, you will program your robot to "dance" to music of your choice. Naturally a dance competition will have a restricted dance floor area.

Your robot is not as swift on their wheels as you are on your feet, so the choice of music is important.

And no doubt its not as debonair as you either.

Specifications:

    • dance moves must be within the 1.5m squared dance floor

    • dance routines must be between 15 and 20 seconds

    • music selection is up to you (no offensive lyrics)

    • music may be played through the robots speaker or on another device

    • you may decorate your robot

    • you may modify your robot

Getting started

Try Makecode for Lego. Use Code with Blocks or Javascript. Test on the simulator.


To get started with MakeCode for LEGO MINDSTORMS Education EV3, you’ll need:

  • A computer with a USB port and internet access through a browser

We had a lot of fun building this code editor, and hope that you have fun creating amazing programs for your LEGO MINDSTORMS Education EV3 creations!

Have fun Making Code for LEGO MINDSTORMS Education EV3!

LEGO MindStorms Online Lessons 1-7

Before you start coding with LEGO Mindstorms

Projects and programs

Project creation and Recent projects; group all similar programs within the same project & create multiple projects if it makes sense to do so. E.G: create a project for your Mini Skills and another to meet the Dancing Robot Brief.

Program creation and renaming; always rename your programs with a descriptive name and create new programs for different tasks.

Getting connected

P-brick power ON & OFF

P-brick connection and Port View

Input (sensors & input ports); default input ports:

● Port 1; touch sensor

● Port 2; no sensor

● Port 3; colour sensor

● Port 4; infrared sensor

Output (actuators & output ports); default output ports:

● Port A; medium motor

● Port B & C; two large motors

● Port D; large motor

Changing devices and their settings in the Port View

Running a program

Running a program directly

Downloading a program

Inspiration: an advanced robot maze competition

Inspiration: Amazing LEGO bots

Follow the line & Maze Runner

10 More Amazing LEGO creations

Projects, programs & connecting the P-brick

P-brick navigation

mini task skills project

mini task: 01_forward

task 01: 01_forward

go forward

  • move forward at speed 20 on for 1 rotation.

mini task: 02_steer

task 02: 02_steer

steer left & then right

  • steer left 30º at speed 20 on for 360 degrees,

  • steer right 30º at speed 20 on for 360 degrees.

mini task: 03_lights

task 03: 03_lights

use the P-bricks display lights

  • light on red no flashing, steer to the left 30º at speed 20 on for 1 sec, wait 2, light off,

  • light on green flashing, steer to the right 30º at speed 20 on for 1 sec, light off.


When you write more complex code, setting the P-brick lights can be help you determine what part of your program is active.

mini task: 04_loop and 05_loop

task 04: 04_loop

loop once to go forward

  • loop 1 times:

[motor ON at speed 20],

  • motor OFF & brake


How far did the Robot travel? Any idea why?

Task 05 will answer the question

What does turning on the brake do?

task 05: 05_loop

Understanding how CPU speed effects your code

  • light on red no flashing,

  • loop 1 times:

[motor ON at speed 20],

  • motor OFF & brake, light off, wait 2,

  • light on green no flashing,

  • loop 9 times:

[motor ON at speed 20],

  • motor OFF & brake, light off, wait 2,

  • light on yellow no flashing,

  • loop 900 times:

[motor ON at speed 20],

  • motor OFF & brake, light off.

How far did the robot travel for each loop? Any idea why?

Answer: CPUs (even a low spec LEGO CPU) work extremely fast, so by the time the CPU has actioned the turn motor ON command, then exited the loop and turned the motor OFF, the motor has not even begun to turn. Loop 9 times and not much happens; you need to loop many times before the motor has a chance to turn before the CPU turns it OFF.

mini task: 06_sound

task 6: 06_sound

sound from the internet

download an mp3 sound file from internet,

use the Tools/Sound editor to break the sound file into a max of 7 sec chunks,

save to your project.

  • loop until touch sensor bumped:

[play sound until end of file].

mini task: 07_if

task 07: 07_if

using a switch / if block

  • light on yellow no flashing,

  • loop forever:

[if ultrasonic sensor dist < 20, light on green no flashing, else light on red no flashing].


mini task: 08_compare

task 08: 08_compare

within a range?

  • light on yellow no flashing,

  • loop forever:

[ultrasonic sensor passes dist to compare block, if within range (15 to 20), light on green no flashing, else light on red no flashing].


mini task: 09_display

task 09: 09_display

display information on the P-block

  • loop forever:

[ultrasonic sensor passes dist to, display via wire].


Extension tasks

extension task: 01_variables

extension 01: 01_variables

variables & constants

  • ight on yellow no flashing,

  • create minRange variable with number 15, create maxRange variable with number 20,

  • loop forever:

[read variables minRange & maxRange and ultrasonic sensor passing values to compare block, if within range, light on green no flashing, else light on red no flashing].

extension task: 02_gyro

extension 02: 02_gyro

using gyro to turn

  • {calibrate & reset gyro to zero},

  • loop until gyro >= 90º

[L/H motor ON, at speed 20],

  • motor OFF & brake,

  • reset gyro to 0º,

  • loop until gyro <= -90º:

[R/H motor ON, at speed 20],

  • motor OFF & brake.

This will require the Gyro to be correctly calibrated, which can only be done successfully if the Gyro is completely still during this process.

One way is to plug it into the Brick, but this results in the Gyro being disturbed and so may fail to calibrate correctly.

The other is via issuing commands; use the Teacher supplied My Block code {reCalGyro.ev3p} to calibrate the Gyro at the start of your program.