In this tutorial, we will be guiding you through the 5th experiment from the Kitronik Inventors Kit. We will guide you through setting up the circuit and coding the program using block programming in the MakeCode software.
Setting Up the Experiment
Parts List
- 1x Transistor
- 1x 2.2kΩ Resistor (Red, Red, Red, Gold)
- 1x Terminal Connector
- 1x Motor
- 1x Fan Blade
- 3x M/F Jumper Wires
Building the Circuit
Adding the Resistor
Insert the pins of the 2.2kΩ Resistor into holes C9 and E17 of the breadboard.
Adding the Transistor
Add the transistor onto the breadboard by inserting the pins into holes D16, D17 and D18, with the flat side towards the bottom of the board.
Adding the Motor
Place the red (positive) wire in the left-hand side of the terminal connector and the black (negative) wire into the right-hand side. Using a small flat head screwdriver tighten the screws to secure the wires in place.
Insert the pins of the terminal connector into holes A14 and A16 on the breadboard. Push the fan blades securely onto the motor.
Adding the Jumper Wires
- 0 to E9
- 3V to E14
- 0V to E18
Coding the Experiment
MakeCode Software
Regardless of which OS you are using go to the MakeCode website with any internet browser. The page is broken down into a series of sub-categories with your created projects being at the top along with some premade programs for Tutorials, Games, Radio Games, Fashion and many more!
You can click on any of these to load the code, however, if you wish to start your first or a new project click on the big purple box labelled New Project.
You have 2 coding options within this which can be changed by using the At the top of the page you will notice a slider-style button, click on it to change the coding window to JavaScript mode.
Block Mode |
JavaScript Mode |
You should now have a screen that looks similar to this.
Coding Guide
This program doesn't require the use of the on start function. Remove it by click and dragging the 'On Start' block from the main coding window over the block categories until you see an image of a bin then release the mouse button to remove it from the program.
Click on the ADVANCED category to expand the menu
Click on the PINS category and drag the 'Analog Write Pin P0 to 1023' block into the Forever block.
From the MATH category, drag the 'absolute of 0' block and place it over the value 1023 in the analog write block.
Click on the INPUT category and drag the block 'acceleration (mg) X' and place it on the 0 of the absolute block.
Click on the little arrow next to the letter X, from the dropdown menu select the option Y.
Uploading to the Micro:Bit
In the bottom left corner of the MakeCode page, you will find a textbox along with a purple download button. Click on the word untitled in the textbox and give your program a new name.
Press the Download button and the file will download to your downloads folder unless you specified a specific place.
Once the file has downloaded, open up the window for the download location and a separate window for the MICROBIT. Click and drag the file from downloads over to the micro:bit.
Once it has finished, the MICROBIT window will close and reopen, please note that while the file you just copied does not appear in the window, it will have been copied across.