Page 156 - KEC Khaitan C5 Flipbook
P. 156
HANDS-ON PROJECT
PROJECT NAME: Step Counter Gadget with Micro:Bit
Objective:
Design and build a step counter using Microsoft MakeCode for Micro:bit.
Program the Micro:bit to detect motion, count steps, and show the total on its LED
screen.
Learn how to use sensors, variables, and loops through hands-on coding.
Step-by-Step Instructions
Step 1: Setting Up the Micro:bit Program
Open MakeCode Editor:
Go to MakeCode for Micro:bit.
Start a new project and name it “Step Counter.”
Design the Code:
Use blocks to:
o Detect motion using the Micro:bit’s built-in accelerometer.
o Count steps using a variable.
o Display the step count on the LED screen.
Basic Blocks to Include:
On Start Block: Initializes the step count to zero.
On Shake Block: Increases the step count when the Micro:bit is shaken.
Forever Block: Continuously displays the step count.
Example Code:
On Start:
Create a variable stepCount and set it to 0.
Drag the on start block and attach the set stepCount to 0 block.
On Shake:
Drag the on shake block from the input category.
Attach the change stepCount by 1 block to increment the counter.
154 Premium Edition-V

