microbit in breadboard

Practical project step 6 – Coding the Microbit

With the cabinet assembled and servo motors fitted, I could now wire up the breadboard to the motors and code the Microbit to make the dial pointers to move in response to real or simulated data.

Selecting data to monitor

I had designed the face of the gauges to display two different types of data measurement:

  1. Positive or negative readings (from -100 to +100, centred on zero). This is similar to the display on a zero-centre ammeter (which measures electrical current). For my data monitor, this type of display would be suitable for measuring variations from a neutral point, to track whether data was going up or down. This could include data such as employee/customer satisfaction or product ratings, or constantly changing environmental data (eg monitoring live data on energy use compared to the average, to see if it is above or below that).
  2. A continuous scale or percentage from zero to 100. This sort of gauge is similar to a car speedometer, and in this context is suitable for monitoring data that has a top limit (100). It would be a good way to monitor performance against targets, where the top limit is 100%. This could include sales targets, fundraising, rate of project completion, attendance, or any other data with a set target.

The ultimate intention is for the data monitor to display data that is transmitted via Bluetooth direct from the Internet. However for the purposes of this project, I will simulate the data by hard-coding it into the Microbit program.

Coding

I used the Microbit Makecode online visual coder to do the Javascript coding. First, I set up a bit of code to display random fluctuations on dial 1 (which was wired to pin zero on the breadboard). I experimented with different variables to adjust the amount and speed of fluctuation on the dial.

code screenshot
Code to display random fluctuations

Next, I set up some code for dial 2 (wired to pin 1), to show a gradually increasing progression from zero to 100, with a couple of minor fluctuations along the way. I included some random timings and some prescribed pauses, where the data didn’t change for a few seconds. Once the dial reached 100, it stayed there for a while, then reset itself to the start. This was to simulate the example of gradually increasing the amount of sales or funds raised up to the desired amount (100%).

Here is a short clip showing the dial being tested. I had it connected up to the breadboard but not mounted in the cabinet, for easier testing.

Here is the final code:

screenshot of code
The final Microbit code

With the coding done, it was simply a matter of reassembling the dials/gauges, putting the cabinet back panel on, and checking all was good to go!

Next > Practical project step 7: The final product


Back to…

< Step 5: Finishing the cabinet
<< Design technology project index
<<< Enhanced Design Tools index

 

Scroll to Top