My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.


Inventors Kit Experiment 4 Full Experiment

In this tutorial you will find Experiment 4 Using a Transistor to drive a Motor from the Kitronik Inventors Kit for the BBC micro:bit. We've included the entire experiment as a free example of the great practical experiments that are contained within the Inventors Kit. Learn how to build the circuit and how to code the micro:bit to control the circuit.

Experiment 4 Using a Transistor to drive a Motor-main-image-870

You can complete this experiment with or without the Inventors Kit. If you do not have the Kitronik Inventors Kit you will have to source all of the required components separately, a full list of the things you will need can be found below.


This Experiment Requires:


The Aims Of This Experiment Are:

  • To use a transistor to drive a fan motor.
  • To control the speed of the motor using Pulse Width Modulation (PWM).


Experiment 4 Video Walk Through:


Experiment 4 Using A Transistor To Drive A Motor:

The output pins on most microprocessors can only supply a small amount of current, not enough for a power hungry device such as a motor. The BBC micro:bit is no exception to this. A transistor can be used to solve this problem.

A transistor is like a gate for electricity, a small amount of current can be used to open the gate to let a lot of current flow through to power hungry components.


Creating The Code Using The Microsoft Block Editor:

Below is an example of how to write the code for the experiment in the Microsoft Block Editor.




If you're having difficulty producing your own code for this experiment, we've created the code for you that you can compile, you will find the links for the code towards the end of the article.


Building This Circuit On The Prototyping System:

It is possible to build this circuit using the Prototyping System for the BBC micro:bit and the components listed at the top of the page, you can follow the diagram below.


Building This Circuit With Crocodile Leads:


If you don't have the Kitronik Inventors Kit for the BBC micro:bit or the Prototyping System you can still build this circuit using the circuit diagram for reference and Crocodile Leads to join the components together. You can see an example of this in the picture below.

When connecting the Transistor it is important to correctly identify the Base, Collector and Emitter leads. These can be seen in the picture to the right. Care should also be taken when connecting the transistor to ensure that there are no shorts, you should bend the pins away from each other before you connect the crocodile leads.


Circuit Diagram:



What Will Happen:

The motor should, after a few seconds start to spin slowly, then faster until it reaches a maximum speed. At this point it will slow down and stop and the cycle will begin again.


What's Going On (How Does It work)?:

If the transistor is turned on and off very quickly and it spends half its time on and half its time off then the fan motor will spin at half speed. By changing the percentage of the time that the transistor spends on (known as the duty cycle) the speed of the motor can be finely controlled. As the power pulses on and off and the width of the pulses are controlled, we call this process Pulse Width Modulation (PWM).

The code works in two stages. The first loop writes the duty value to Pin P0 then increases the duty value by one and writes the value to P0 again. This repeats until the value reaches the maximum of 1023 (full speed). The second loop then kicks in and reduces the duty by 1 and writes it to P0 until the value reaches 0 (stopped). This whole cycle is inside a forever loop so the motor will speed up and slow down forever. The PWM output varies the duty cycle of the output voltage, as show below, to vary the speed of the fan motor.



Inventors Kit Experiment 4 Further Help Code Examples:

Although we advocate moving over to the Microsoft MakeCode Editor, we will continue to provide links to legacy code examples for as long as the links work or until the legacy editors are no longer available. Please select your desired option below and the options for your choice will open up.

The MakeCode option is a download, the file has been zipped and will need to be unzipped before transferring to a microbit. You can also drag and drop the unzipped file directly into the MakeCode editor for viewing or editing.



Kitronik Inventors Kit Resources:

Exp No#. Experiment Name. Resource Type.
1 Say Hello to the BBC micro:bit. Further Help.
2 Using an LDR and analog inputs. Full Experiment + Further Help.
3 Dimming an LED using a potentiometer. Further Help.
4 Using a transistor to drive a motor. Full Experiment + Further Help.
5 Using the accelerometer to control motor speed. Further Help.
6 Setting the tone with a piezo buzzer. Further Help.
7 Wind Power. Full Experiment + Further Help.
8 Making a game using the compass. Further Help.
9 Capacitor charge circuit. Further Help.
10 Using an RGB LED. Further Help.
11 Making a pedestrian crossing. Full Experiment + Further Help.
12 Making a random dice. Full Experiment + Further Help.


Get The Kitronik Inventors Kit For The BBC microbit:

We do two versions of the Inventors Kit for the BBC micro:bit, with or without the BBC micro:bit included. Chose the option that is right for you from the links below.

Electronic Project Kits
← Previous Post Next Post →

2 thoughts on “Inventors Kit Experiment 4 Full Experiment”

  • Paul Raftery June 24, 2017 at 10:22 pm

    I've just purchased your inventors kit for the microbit and one of the first experiments I wanted to try was experiment 4 (using the motor + fan) as the temperature here in Bilbao is pretty hot at the moment. As I am learning python, I decided to download your python code to run the motor. Unfortunately your code didn't seem to work. I compared it to the block editor code and noticed that the python code is lacking the 10 ms delay. I added 'sleep(10)' to your micropython code and now it runs perfectly. Please could you update the code on your website.
    Good job with the kit.

    • Mark Donnison July 5, 2017 at 12:27 pm

      Hi Paul, good spot. I'll update it as soon as is possible. Thanks again!

Leave a Reply