# How to Make a Counter With Microbit?

566

2

1

Published

## Introduction: How to Make a Counter With Microbit?

When we have boarded airplane, we often encounter a situation like this: a beautiful stewardess carrying a small silver box keeps press it while passing by. She is murmuring:1,2,3,4,5,6...... You must guessed it--she is counting the total number of people sitting on the airplane. And the small silver box on her hand is a mechanical counter. Today, we are going to make an electronic one with BBC micro:bit.

Note:
For more funny creation, you can pay attention to : http://www.elecfreaks.com/

Our product store: http://www.elecfreaks.com/

## Step 1: Know What We Need

First, we have to know what function we want to realize with this electronic counter. I have a simple conclusion for it.

Basic Requirement:

1. Press button “A” , counter number minus 1;

2. Press button “B” , counter number plus 1 ;

3. Press button “A”、“B” together, counter number become 0.

## Step 2: Material

Second, in order to make a counter, we have to know what kind of materials we will need. Here is the material we have to prepare:

micro:bit ×1

USB ×1

You might wondering how can we make an electronic counter with a micro:bit board and a USB cable only. Don’t worry! It is very easy and simple. You will learn it soon.

## Step 3: Start Programming

After we gathered our materials, we have to program for it. Connect micro:bit board with your computer. Then click Makecode to open programming interface. We are going to use Block method to do programming. You can read the following steps to learn how to program.

## Step 4: Programming1

To start, we build a new variable named “counter” and set “0” as the initial value .

## Step 5: Programming 2

Write code for press button “A”、”B” and “A+B” separately.

1. Press button “A”:

The function of button “A” is deduct count number. We all know that no matter what we count, the count number would not be under 0. If negative number appears, then there must be something wrong. In order to avoid this mistake, we have to set counter judgment “≥ 1” in our program. If “counter≥1”, then press button “A”, it will deduct 1 automatically.

2. Press button “B”:

Every press increases 1 counter number.

3.Press button “A+B”:

Press button “A” and “B” together, the counter number become 0. Then you can start a new count.

## Step 6: Full Programming

After we finished button code writing, we have to use 5*5LED screen to show the counter number.

We can directly drag block “show number” under button code. Then the count number on screen will change according to the variable counter number.

You can see the whole program code in the picture.

## Step 7: Completed

You can rewrite code by yourself to enjoy programming by dragging different blocks within block editor. It is very simple and easy just like playing bricks.Or you can download code directly into your micro:bit through the link .

Now, let’s download the whole program code into micro:bit and see what will happen.

## Step 8: Usage

With this counter, we can know how many books we have placed on our book shelf, how many plates in the kitchen, how many eggs left in our fridge. Even, we can use it to count a basketball game. This tiny electronic is really powerful.

## Step 9: Question

How to revise our program if we want to limit the maximum value of counter? If you want to know more interesting creation, you can follow up our blogs.

Note:
For more funny creation, you can pay attention to : http://www.elecfreaks.com/

Our product store: http://www.elecfreaks.com/

## Recommendations

• ### Large Motors Class

8,754 Enrolled

• ### Casting Contest

We have a be nice policy.