Wednesday, 9 April 2025

TinkerCad microbit traffic light simulator (now with video)

Have you ever wondered how the traffic lights at the end of your street actually work? They aren’t just on timers; they are controlled by small computers. Today, we’re going to build and code our own traffic light system using a free online tool called Tinkercad.

The best part? You don’t need to buy any expensive equipment. You can build the whole thing virtually on your computer.

What is Tinkercad?

Tinkercad is a free, web-based tool from Autodesk. While many people use it for 3D design, it also has a "Circuits" section where you can drag and drop electronic components—like batteries, LEDs, and micro-computers—to see if they work before building them in real life.

The Project: The Micro:bit Traffic Light

In this project, we use a BBC micro:bit (a pocket-sized computer) to control three lights: Red, Orange, and Green.

To make this work, we connect the micro:bit to a "breadboard" (a plug-and-play board for electronics) or can get away with just wiring them togther with wires (as seen in the circuit below).

  • The Lights: We use three LEDs (Light Emitting Diodes).

  • The Safety: We add resistors.

  • The Connections: * Pin 0 controls the Red light.

    • Pin 1 controls the Orange light.

    • Pin 2 controls the Green light



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 by 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)


Here is how the logic works:

  • The Start: When the micro:bit turns on, it displays a Smiley Face on its screen to show it’s ready.

  • The Loop: 1. Green Light: The micro:bit sends a signal to Pin 2 to turn the Green light on. It shows the letter "G" on its screen. 2. Orange Light: After a few seconds, it turns Green off and turns Pin 1 (Orange) on. It shows the letter "A" (for Amber). 3. Red Light: Finally, it turns Orange off and turns Pin 0 (Red) on. It shows the letter "R".

  • Repeat: The code "loops" forever, just like a real traffic light!









Why Give This a Go?

  • It’s Safe: Since it’s a simulation, you can’t break anything or cause a short circuit.

  • Professional Tools: Tinkercad can automatically generate a "Parts List" and a professional "Circuit Diagram" for you—great for school projects or portfolios.

  • Endless Creativity: Once you master the traffic light, you can change the timings, add a "Pedestrian Walk" button, or even change the colors of the LEDs.

Ready to Build?

Head over to Tinkercad.com, create a free account, and look for the Circuits tab. Search for "micro:bit" and start dragging components onto your workspace.


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

Whether you're a student looking for a cool weekend project, a parent wanting to spark a child's interest in engineering, or a STEM maker exploring IoT (Internet of Things), the Elecfreaks Micro:bit Smart Home Kit http://bit.ly/43ooJF is a fantastic gateway

Smart home technology isn't just for big tech companies; it’s something you can build on your dining room table. In this post, we’re refining a project that mimics real-world smart building technology: a Voice-Activated Night Light.

What is the Elecfreaks Smart Home Kit?

The Elecfreaks Smart Home Kit is an all-in-one ecosystem designed to work with the BBC micro:bit (both V1 and V2). It comes packed with sensors—temperature, sound, soil moisture, and light—as well as actuators like servos and motors. It’s designed to be "plug, code, and play," removing the frustration of messy wiring so you can focus on the logic and creativity



The Challenge: The Smart "Energy-Saving" Light

Imagine a light that only turns on when it’s dark and when it hears someone in the room, then automatically turns off to save power. This is a classic "Smart Home" scenario.

What You’ll Need:


Step 1: Setting Up the Environment

Before coding, you need to tell MakeCode how to talk to the Smart Home sensors.

  1. Open a new project in .

  2. Click on Advanced, then Extensions.

  3. Search for "smarthome" and select the official Elecfreaks library. This adds new blocks specifically for the kit's components.







Step 2: The Logic (The "Brain" of the House)

For this project, we need the micro:bit to make a decision based on two conditions:

  1. Is it dark? (Light level is low)

  2. Is there noise? (Someone is moving or talking)

Pro-Tip for Makers: To get the most out of your LED strip, you might need to enable it. In MakeCode, click the LED category, then click the [+] or "More" option to find the led enable block.

The Variables

Create three variables to keep your code clean:

  • light: To store the brightness reading.

  • noise: To store the sound level.

  • strip: To control your Rainbow LED.


Step 3: The Code

Here is the logic you’ll build:

  • On Start: Initialise your LED strip to the correct pin (usually P1 in the Smart Home kit).

  • Forever Loop:  Set the light variable to the value of the light sensor.

    • Set the noise variable to the value of the noise sensor.

    • The "If" Statement: If light is less than a certain threshold (e.g., 50) AND noise is greater than 78dB, then turn the LEDs on.

    • The Timer: Use a pause block for 10,000ms (10 seconds) so the light stays on while you walk through the room, then turn it off.

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.


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


Why This is Useful for STEM Learning

This project isn't just about making an LED blink; it teaches the fundamental pillars of modern engineering:

  • Sensor Integration: Understanding how machines "sense" the physical world.

  • Boolean Logic: Using "AND/OR" statements to create complex triggers.

  • Threshold Calibration: Students learn that "78dB" or "Light level 50" are variables they must test and adjust based on their specific environment (a great introduction to the scientific method!).


Final Thoughts

The Elecfreaks kit is a "cool set of components" that bridges the gap between screen-based coding and physical reality. Once you've mastered the voice-activated light, try adding the OLED display to show the noise level in real-time, or use the Servo to create an automatic door opener!

Ready to start? Head over to and start building your future home today.







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

Saturday, 24 August 2024

Remote Data Logging with V1 Microbit


Remote Data Logging with Two Micro:bits

In a previous post, we used a single micro:bit to log sensor data. That worked well, but it came with a significant limitation: the micro:bit had to stay plugged into the computer the whole time. In many real situations, you want to place a sensor somewhere away from your computer — across a room, outside a window, or just somewhere more useful.

The solution is to split the job between two devices: one micro:bit collects and transmits sensor data wirelessly, while the other receives it and passes it to your computer for logging. This is actually very close to how remote monitoring systems work in the real world.


The Plan

We'll build on the previous data-logging project and turn it into a simple wireless monitoring system. 

Tip: To avoid confusion, program each micro:bit separately. Only plug one in at a time, and use a separate MakeCode window for each.


Micro:bit 1 — The Transmitter

This micro:bit handles the sensing. It reads the light level and temperature, then broadcasts those values wirelessly using the micro:bit's built-in radio. You can read more about how the radio works here.

The key idea is that both micro:bits are set to the same radio group — just a shared number that lets them communicate with each other while ignoring other devices.

Once programmed, this micro:bit doesn't need to stay connected to the computer. Attach a battery pack and you can move it wherever you want to take measurements. That's what makes it remote.




 

 

Micro:bit 2 — The Receiver

This one stays plugged into your computer. It listens for incoming radio signals from the transmitter and, when it picks one up, stores the received values in variables. It then writes those values to the MakeCode data viewer, exactly as the single-micro:bit version did.

To make this work, it needs to:

  • Use the same radio group number as the transmitter
  • Identify which value has been received (light or temperature) based on the label sent with each reading
  • Log the value to the serial output for the data viewer to display

.

Figure 2 Reciever

 

 

Seeing It in Action

Once both micro:bits are running, open the Show Data panel in MakeCode on the receiver's window. You should see graphs updating in real time, just like before.

Temperature changes slowly, so don't be surprised if that line looks fairly flat at first — try holding the transmitter in your hand to warm it up gradually. Light is easier to experiment with: point the transmitter's LED panel toward a bright screen or lamp and you'll see the values respond immediately.

To save your data as a CSV file and open it in a spreadsheet later, use the blue download icon in the data viewer — same as before.

figure 3 Data logging remotely


 

Ideas to Take It Further

  • Add a visual indicator on the transmitter. When it's running without the computer, there's no obvious sign it's doing anything. Could you add something to the display to show it's actively sending data?
  • Experiment with sampling rate. Right now the transmitter sends data as fast as it can. Try replacing the forever loop with one that sends data at set intervals — like once per second or every five seconds. This mirrors what we did in the single micro:bit version and can make your graphs much easier to read.


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

Thursday, 22 August 2024

Microbit V1 datalogging

Often we need applications that allow collection of data over time, for example temperature or light levels through the day. Allowing us potentially analyse the data for trends. The microbit is a fantastic tool, with some of these sensors already in place (e.g. light and temperature) or can be added to with extra sensors from add-on boards (such as Kitronik Air Quality and Environmental Board for micro:bit https://shop.pimoroni.com/products/kitronik-air-quality-and-environmental-board-for-micro-bit?variant=39475687227475 )

 

Datalogging with a V2 microbit is relatively easy all the details are available here: https://microbit.org/get-started/user-guide/data-logging/ to get started.

 

But what about the older V1 can it do it?

 

The answer is yes but it is a little more work and is generally a little more limited but still very worth while. In this post we are going to look at doing this.

 

In Figure 1 starting the process off in MakeCode (https://makecode.microbit.org/#editor) is shown below. Basic mechanism every 1sec

  • -            The light level is write from the microbit to the computer (via the USB) a value at a time – serially
  • -            Same thing will be done for temperature

That is it to start with.

Figure 1

Figure 2 shows where various elements are in menu. To get the Serial ones you will need to open up the Advanced menu and then Serial menu options (see figure 3)

Figure 2

 

Figure 3


Figure 4


Once everything is set up,  under the similar microbit (Figure 4) you will see another button “Show data Simulator” We can play with the microbit simulator to simulate light and temperature levels; click on new data simulation button and graphs starts rolling across the screen – drag the temperature and light levels on the microbit simulator and you see the graphs change – it is logging the simulate data – it works!

Now for the fun bit.

Click on Download we need to pair the computer and microbit. Figures 5 to 8 show the steps.

Figure 5


Figure 6


Figure 7


Figure 8





We can now take values from the real device. A new button should have appeared along with the “Show data Simulator” button; “Show data Device” Click on this button and instead of simulated data we get data from the  microbit (see figure 9)

Figure 9

 

So in figure 9, the top graph is light level the bottom is temperature taken from the room. Play with covering the sensor the LED grid and light levels change.

 

Collecting data is great, but we are taking it one step further logging the data over time and then sharing it To do this click on the blue download button above the graphs to save the logged data as a CSV file. Once it is in CSV format it is yours to play with in other tools such as spreadsheets.

 

 

Activity

-            how can this be more meaningful?

-            How do we do this with so a microbit can see data – some more remote monitoring (see https://microbit.org/projects/make-it-code-it/makecode-wireless-data-logger/ )

-            How could you do this in Python





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

Thursday, 4 April 2024

Top posts on this blog in March 2024

The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots.






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

The "Hug Avoider": A Coding Journey from Blocks to MicroPython

This project journey follows the evolution of a simple social-distancing idea into a fully realized "Hug Avoider" wearable. Writte...