Thursday, 5 March 2026

Detecting and logging magnetism with a microbit

Producing a data logger using the microbit to detect and log changes in the magnetic field.

Traces

The micro:bit includes a built-in compass that can also be used as a magnetic field detector. With a small amount of code, we can use this sensor to measure changes in the magnetic field and log the data to a computer.

If you are new to this idea, a useful introduction is the video from Mr Morrison below, which explains the basic concept.





The video demonstrates how the micro:bit can detect magnetic fields and display the readings on the device itself. Let’s extend that idea by turning the micro:bit into a data logger that continuously records magnetic field changes.


Coding and Sending data to a Computer

Instead of displaying the magnetic readings directly on the micro:bit’s LEDs, we can send the data through the USB cable to a computer.

The MakeCode editor already provides blocks that allow data to be sent using the serial connection. By placing the magnetic measurement inside a command that continuously sends serial data, we can stream the readings to the computer.

In the example code, two values are transmitted:

  • X-axis magnetic field

  • Y-axis magnetic field

These correspond to two directions in which the magnetic field can change. Each measurement is sent repeatedly through the USB cable so the computer can record it.

From a coding perspective, this modification is very simple: instead of showing the value on the device, we send it through the serial interface.


Code needed


After downloading the program to the micro:bit, keep the USB cable connected, as this is how the data is transmitted.

Once the program starts running, the MakeCode interface should display a “Show Data Device” button similar to the one shown below.

On the Computer ready for data logging


Clicking this button opens a data viewer that shows the incoming magnetic readings in real time.

Data logging in action

Example: rocking the magnets
The graph above shows data recorded when a small set of circular magnets was rolled towards the micro:bit and then allowed to rock back and forth.

The rocking motion produces a clear oscillating pattern in both the X and Y magnetic field graphs. As the magnets move, the magnetic field detected by the sensor changes direction and strength, producing the wave-like traces you can see.

It’s a simple experiment, but it demonstrates how the micro:bit can be used as a low-cost scientific data logger for investigating magnetic fields and motion.








All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Monday, 23 February 2026

What does Gen AI 'think' of this blog?


Ok, no surprise that I enjoy playing with Generative AI :-) A few of the recent posts are around this. Here is the question, though: what does Generative AI pick out from the blog when asked?

Using the Gemini and the following two prompts:
Prompt 1: Go to the following blog https://robotsandphysicalcomputing.blogspot.com/ read it in and summarises it as a 400 word blog post to go on the blog and urls will not count in the word limit

Prompt 2:Embed urls to make it easier for the reader to access the posts

The result

Exploring the Intersection of Code and Hardware: A Look at "Robots and Physical Computing"

Welcome to a comprehensive overview of Robots and Physical Computing, a dedicated space where the digital realm directly meets the physical world. Authored by Dr. Scott Turner, this blog operates on a delightfully simple yet profound premise: getting computers to interact with their physical environment is incredibly fun. It serves as an ongoing digital notebook that documents personal experiments, educational coding projects, and hands-on building experiences in the ever-expanding field of physical computing.

For educators, hobbyists, and STEM advocates, the blog is an absolute treasure trove of accessible, step-by-step tutorials. The core philosophy here centers on lowering the barrier to entry for coding and electronics. By heavily featuring user-friendly platforms like the micro:bit, TinkerCad, and various smart electronics kits, the blog demystifies the often-intimidating world of hardware design. Whether you are looking to integrate physical computing into a university computing curriculum or just tinkering on your workbench over the weekend, the content is consistently geared toward practical and immediate application.

A quick dive into the most recent posts perfectly highlights the blog’s dynamic range. In early 2025, the focus successfully bridged simulated environments with smart technology. For instance, a recent tutorial explores how to build a TinkerCad microbit traffic light simulator (note: exact URL path based on blog archives). This post beautifully illustrates how free, online CAD systems can be leveraged to prototype electronic circuits and test neural networks before you ever touch a physical wire. Similarly, a review of the Elecfreaks micro:bit Smart Home kit walks readers through creating a voice-activated light solution, demonstrating how simple code and accessible sensors can mimic real-world smart building technology.

Interestingly, the blog also seamlessly ventures beyond traditional hardware. A late 2024 post explores producing AI-generated cartoon strips, proving that the blog's scope continuously evolves alongside modern technology trends. Additionally, practical data applications remain a recurring theme, as seen in the detailed tutorials on setting up remote data logging systems using older V1 micro:bits and local Microbit V1 datalogging to monitor environmental conditions.

Ultimately, Robots and Physical Computing is much more than just a technical guide; it is a celebration of curiosity and maker culture. It encourages readers to pick up a microcontroller, write a few lines of block code, and watch an LED light up or a motor spin. If you are eager to bridge the gap between software and hardware, delving into this blog’s rich archives will undoubtedly spark your next great project.


Not bad as a summary! Little more gushing than I would have written.


Next task: summarise this as an image. Still using Gemini (and automatically Nano Banna) the following prompts were used
Prompt 1:Use the text produce an image that encapsulates what was summarised and make the image downloadable

Prompt 2: Compress the image so it is suited to the web and allow it to be downloaded

The result, in my opinion, was good and can be seen as the image at the top of the post.

This is just a bit of fun and normal service with Physical Computing will be resumed soon.



All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Wednesday, 9 April 2025

TinkerCad microbit traffic light simulator (now with video)

Back to playing with TinkerCad in a previous post called explaining-tinkercad-microbit-neural, I used it to produce a simulation of a microbit-based neural network built around microbits. 

If you haven't played with this free tool to TinkerCad https://www.tinkercad.com/dashboard from AutoCad, I highly recommend it as a versatile, simple CAD system (that includes coding for microbits) with a load of support material. If that wasn't enough, it is free and online.

So, to experiment, I have made a simple traffic light simulator (an oldie but a goodie), so I can see what it can do a little more. Essentially, Red, Orange and Green LEDs (with appropriate resistors) are controlled by pins 0,1,and 2 on the microbit.


So here is a circuit with a microbit. The anode (the one with the bent leg)connects to the microbit pins through resistors. The cathode goes to the ground connection.





Here is the code for the microbit turning the LEDs on and off, and when it starts up putting a smiley face onto the microbit.









For those who like circuit diagrams, it can produce a more formal circuit diagram and the parts list (see below)- nice feature.









Have a play with the simulator below it goes a little bit further and changes the smiley face to letters (see the code below)



Possible ideas, change the LEDs to those that change colour, and now the approach can be used to provide a bit of control on the timings of those. Also experimented with replacing the smiley face with letters for LEDs colour (e,g, R for Red) - actually done that in the simulation above with the code below :-)





All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Friday, 28 February 2025

Using Elecfreaks microbit Smart home kit

Using Elecfreaks microbit Smart home kit http://bit.ly/43ooJFo a cool set of comments to build simulated Smart Building activities using a Microbit it works with either V1 or V2 microbit.




Go to extensions (see below) and then search for smarthome and add the package to the editor (ie, click on the extension and makecode does the rest)






Attach the microbit to the sensorbit


Making the voice activated light solution - the first activity follow the circuit in the book


To get "led enable" you will need to click in makecode like on LED option and then + to find it. You will also need to set up three variables light, strip and noise.
Here is the code

Only turns on the LED for 10 seconds when the light level is low and noise is above 78dB.


Playtime
Slight adaptation to the code, makes the LED change with sound level
The circuit is the same.


Conclusion
Based on this one activity it is a nice bit of kit. The range of actuators and sensors justifies the cost with things like moisture sensor , servo, water pump, OLED screen, temperature sensor, fan and more. It is worth a look.






All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Sunday, 24 November 2024

Who wants to produce AI produced cartoon strips

Question: How easy is it produce a comic/cartoon using genetative AI?


Let's start with using ChatGPT4o to produce cartoons. The idea was inspired by a tweet by Dr Thomas Lancaster see below




Slightly modifying the prompts it is possible to get it to create the images and combine them in a GIF. I have split the two task into two prompts 

The first prompt applies some principles of prompt engineering
Persona: In this case two the persona of the writer "You are an experienced comic book designer and a witty writer" and who it is for "Computing student in Higher Education in the UK"
Task: Creating a guide that educational and entertaining, but with minimal textual output.
Action: The details a comic with 8 panels of consistent style, create each panel as a separate image; using speech bubbles with a maximum of 5 words.

The first prompt
The language is British English. You are an experienced comic book designer and a witty writer. Create a guide to being a Computing student in Higher Education in the UK using a comic book narrative. This should be educational and entertaining. The comic will have 8 panels and the style consistent between panels, You will generate the graphics for each panel separately; as seperate images. using speech bubbles (a maximum of 5 words). Reduce all other textual output to a minimum. 


The second prompt is all output generating the images and then combining them into a named gif.

generate the images and combined the images into a file called computing_student2.gif



It is fun to do, the text can often get a bit mangled though.




We don't just have to use ChatGPT; Google's Gemini can go someway to also produce a comic or the artwork. There is a differences though (whether it is an advantage or disadvantage depends on what you want); Gemini can not
- Produce images but can find them online;
-Can't combine them into a GIF so that would have to be done outside of this.

So the prompt
The language is British English. You are an experienced comic book designer and a witty writer. Create a guide to being a Computing student in Higher Education in the UK using a comic book narrative. You will use images you find on the web to do this. This should be educational and entertaining. 

The result

A Guide to Computing Student Life

Panel 1

Student: "So, you've chosen to study computing. Brave soul!"

Panel 2

Student: "Endless coding marathons. Your new best friend: caffeine."

Panel 3

Student: "Group projects: where chaos meets collaboration."

Panel 4

Student: "All-nighters are a rite of passage. Bring snacks."

Panel 5

Student: "Nail that presentation and you'll feel like a coding rockstar."

Panel 6

Student: "Remember, breaks are essential. Your sanity depends on it."

Panel 7

Student: "The job market loves computer grads. Your future is bright!"

Panel 8

Student: "You made it! Celebrate your hard work. You earned it!"

Note: I couldn't combine the images into a GIF as I don't have access to image manipulation tools. However, you can easily combine these images into a GIF using online tools or software like Photoshop.

Would you like to focus on a specific aspect of computing student life for the next comic?




So because it is getting image online rather generating them as in the ChatGPT4o approach, the image style may not be as consistent. It does do a good job and  does include the sources of the images; and is quick.


So overall, this was fun to play with; both approaches met the goal though in different ways.


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Detecting and logging magnetism with a microbit

Producing a data logger using the microbit to detect and log changes in the magnetic field. Traces The micro:bit includes a built-in compas...