Unit 1: Wake Up
Sensors, a brain, and two wheels.
Unit 1 of 8 in Robotics coding for kids. Its 4 lessons are First Orders, Left and Right, Sense, Think, Act and The Long Way Round — below is everything each one explains, and a question or two from it to try.
Every program on this page was driven round the simulated room before it shipped, and prints exactly what it says it prints.
This unit is free for ever, because the first two units of every track are. Try it in the app.
🤖 First Orders
Meet Bolt
A robot is only three things: sensors to notice the world, motors to move, and a brain to decide. You are the brain.
Bolt lives in a room two metres across. Everything is measured in centimetres. Press the button under the room and watch.
Python
robot.say("Rolling out")
robot.forward(60)
It prints
Rolling out
How far is 50?
robot.forward(50) drives 50 centimetres, not 50 steps and not 50 seconds.
The robot also knows where it is standing. robot.y() is how far down the room it has got, and it starts at 170.
Python
robot.forward(50)
robot.say(robot.y())
It prints
120.0
Try it yourself
Which part of a robot are you writing when you write code?
- The brain — the part that decides what to do
- The motors
- The sensors
- The battery
Answer it in the app
🔄 Left and Right
Turning on the spot
robot.right(90) spins the robot a quarter turn to the right without going anywhere. robot.left(90) is the other way.
robot.heading() says which way it is pointing, like a compass: 0 is up, 90 is right, 180 is down, 270 is left.
Python
robot.forward(40)
robot.right(90)
robot.forward(40)
robot.say(robot.heading())
It prints
90.0
Try it yourself
Bolt is facing up the room. It turns right twice, 90 each time. Which way is it facing?
- Down the room
- Up the room
- Left
- Right
Bolt starts facing up the room. What does this print?
Python
robot.left(45)
robot.left(45)
robot.say(robot.heading())
Answer them in the app
👁️ Sense, Think, Act
The robot can look
On Bolt’s nose is a rangefinder. It sends out a beam, waits for it to bounce back, and works out how far away the nearest thing is.
robot.distance() gives you that number in centimetres — measured from the nose, so touching a wall reads 0.
Python
robot.say(robot.distance())
robot.forward(50)
robot.say(robot.distance())
It prints
152.0 102.0
Sense, think, act
That is the whole job of a robot, forever:
Sense — read a number off a sensor.
Think — work out what it means.
Act — turn a motor.
Here the thinking is one subtraction. robot.distance() - 20 is "everything between me and the wall, except the last 20 centimetres".
Python
gap = robot.distance()
robot.forward(gap - 20)
robot.say(robot.distance())
It prints
20.0
Try it yourself
Why did the second number come out 50 smaller than the first?
- Because the robot drove 50 cm closer to the wall
- Because the beam got weaker
- Because distance counts down every time you call it
- Because the wall moved
The block ahead ends 60 cm down the room. What does this print?
Python
robot.say(robot.distance())
robot.forward(20)
robot.say(robot.distance())
Answer them in the app
🏆 The Long Way Round
Try it yourself
Which of these is the robot sensing?
- robot.distance()
- robot.forward(30)
- robot.right(90)
- robot.say("hi")
Answer it in the app