George Lucas Educational Foundation
Technology Integration

Coding a BBC Micro:bit to Explore Math Problems

Middle school teachers can have students do some simple coding to explore solutions to real-world math problems.

December 15, 2022
Aeriform / Ikon Images

As a math teacher, I constantly tell my students that math is everywhere and they will use it daily. It always brings me great joy when something so common as a box of cereal sparks an idea for a lesson. As I walked through my local grocery store recently, this is exactly what happened. I saw a box of cereal advertising one of six toys in every box, which made me wonder: How many boxes would we need to buy, on average, to get all six toys?

I knew this was a question I wanted my sixth-grade students to grapple with, as it would give them a real-life application of data collection and analysis, as well as graphing and representing data. I also knew this would be a great opportunity to bring in technology integration and coding with the BBC micro:bit.

Setting up the problem

I started the lesson by recapping my trip to the store, sharing the commercial advertising for the toys, and letting my students discuss what they heard. I have been deeply influenced by three-act tasks for the engagement they provide. In these tasks, students work through an engaging problem that is normally grounded with videos in three “acts.”

The first act builds student engagement by showing a clip of a phenomenon and having students identify what they wondered. The second act has students view an extended clip with information needed to solve the problem. Students then work together to solve the problem and eventually share their solutions. Finally, in act three, students are shown the full video, which includes the solution to the problem.

I started this lesson in a similar way, asking students what they wondered about this promotion. Students initially asked questions like why the cereal company only used six toys, while others questioned whether there was an equal number of each toy, or whether some were produced in greater numbers than others. One student asked the question I had been hoping for: how many boxes would it take to get all six toys?

We used this as a jumping-off point, discussing initial wonderings about the answer to the question. Students had guesses ranging from six to 30 boxes of cereal. I suggested we run a simulation to figure out how many boxes we should expect. I asked students to think of ways we could represent the toys without having to go buy them. Most students suggested putting things like cards, different color buttons, or 3D-printed models in a bag and drawing them at random. I told them that these were great ideas but I wanted to try using a micro:bit for this data collection.

BBC micro:bit

The BBC micro:bit is a pocket-sized computer that holds a single code at any given time and allows students to explore physical computing. The micro:bit has several built-in sensors, such as temperature and light, and outputs such as LEDs and sound, which make coding engaging for students. One of the greatest features of this tool is that, even if your school does not have the physical micro:bit, the online coding platform includes a simulator so that students can experience the use of this tool without needing to have one in their hands.

The coding platform for micro:bit uses a block coding system, similar to platforms like Scratch. I told the students we would be using the random-number-generator feature of the coding platform to help us in answering our focus question. This led to a discussion of why the micro:bit may be better at randomizing numbers than we would be, drawing tokens from a bag.

We also discussed how the toys would be represented in our code, with students eventually suggesting assigning each toy a number from 1 through 6. They also made the connection that each time a number was displayed would be a representation of buying a new box of cereal.

Coding and data collection 

Once students understood the focus of our simulation and the representation of our toys, it was time to code. The code used for this simulation is very simple, only requiring the use of a few blocks, which makes this more accessible to those who have not had the opportunity to code previously. In addition, as an extra layer of scaffolding, I included the blocks that students would need on the board and asked them to arrange the blocks so that our chosen input (shaking the micro:bit) would lead to our desired output (a random number between 1 and 6).

Once the code had been developed, it was time for data collection. Each student used their micro:bit (or the simulator) to collect their data. There is always one student who asks when they can stop collecting data, and this puts a smile on my face every time because I know they were thinking deeply about the problem. I stopped the class at this point to discuss this question, and we agreed that we could stop when each person got the numbers 1 through 6 exactly once.

I watched the students shake their micro:bits and organize and record their data. I saw as some got frustrated missing out on that elusive toy while others finished quickly. Authentic conversations began to emerge as some finished more quickly than others. Students found that they would need to buy, on average, 15 boxes of cereal to collect all the toys.

Analyzing and displaying the data

After collecting the data from all students on the total number of “boxes” they needed to buy, I displayed the data for the class and asked them for initial impressions. Many noticed the wide range of possibilities. I suggested they organize the data in three different ways to better analyze the data: a dot plot, a histogram, and a box plot.

The authentic engagement continued as students were interested to see what patterns emerged. Many noticed that the dot plot easily showed the mode number of boxes, the histogram showed a somewhat symmetric distribution, and the box plot showed variations in the quartiles for purchasing boxes.

By collecting and analyzing data in this way, I was able to get my students thinking deeply about data and graphing, while also incorporating technology, and to keep them engaged throughout using a focus question they were intrinsically motivated to solve. I encouraged my students to simulate the event one more time with 10 different toys that were being given out in McDonald’s Happy Meals. They all looked at me, and one said, “We are going to need to shake the micro:bit a lot for that!”

 Once students become comfortable with the micro:bit, there are a wide range of applications for how this can be integrated into the mathematics classroom, as well as other classes in the school. For example, in eighth grade, I have had students collect data using the same random-number-generator code but applied it to a scenario where they would simulate an exponential decay. Students can also use the built-in sensors and data-collection options to collect data on natural phenomena in their science classes to explore scientific principles.

Share This Story

  • email icon

Filed Under

  • Technology Integration
  • Math
  • 6-8 Middle School

Follow Edutopia

  • facebook icon
  • twitter icon
  • instagram icon
  • youtube icon
  • Privacy Policy
  • Terms of Use

George Lucas Educational Foundation

Edutopia is a free source of information, inspiration, and practical strategies for learning and teaching in preK-12 education. We are published by the George Lucas Educational Foundation, a nonprofit, nonpartisan organization.
Edutopia®, the EDU Logo™ and Lucas Education Research Logo® are trademarks or registered trademarks of the George Lucas Educational Foundation in the U.S. and other countries.