Controlling a Lego train motor with a micro:bit
What you will need:
- One micro:bit, USB cable to load the program onto the micro:bit
- A Lego train motor
- A motor controller this is the best one I have found link
- A battery box that holds 4 x AA batteries
- 4 x AA batteries
- A small phillips head screw driver
What you will learn:
- How to assemble the micro:bit to the motor controller and put cables in the correct way using a screw driver
- How to create the code to get your train motor moving at the push of a button
- How to operate your code controlled train
Lets get started:
Please read this first ....
Parents and young people word of warning. To get this to work you will need to cut off the connector on the train motor so that you can attach it to the motor controller. You can buy new ones from Lego for (at the time of writing 22/04/20) £11.99 + £3.95pp or get them cheaper on ebay. If you are human and under 16 just check with parents I don't want to get you into trouble.
Parents and young people word of warning. To get this to work you will need to cut off the connector on the train motor so that you can attach it to the motor controller. You can buy new ones from Lego for (at the time of writing 22/04/20) £11.99 + £3.95pp or get them cheaper on ebay. If you are human and under 16 just check with parents I don't want to get you into trouble.
Lets get cracking...
Step 1. Cut off the plastic connector as seen on the picture above.
Step 2. As you can see there are four metal wires that run along the cabling. You will need to CAREFULLY strip off some of the plastic coating so that you can see each of the four wires. This is easy enough but ask for adult help if you are not confident doing this. It needs to be enough so that you can either a) wrap the two left wires around each other and the two right wires around each other or solder them(See picture below, I have only ever done this once wrapping is just as good).
Step 3: Get your battery box something like this link
Step 4: Screw the black wire from the battery into the bottom left screw and the red wire into the right screw(Orange circle on the diagram).
Step 5: Screw the two wires from the train motor into the screws highlighted with the red circle on the diagram above.
Step 6: Add 4 x AA batteries to your battery box.
Step 7: Using a computer go to the makecode editor link
Step 8: Click New Project
Step 9: You will need to scroll down on the menu and click advanced as we need to add two additional libraries. (This gives you access to key blocks that you will need later)
Step 10: After you have clicked on "Extensions" you will need to select the radio broadcast extension. This may appear like below, but if it doesn't you can search for it and then it will appear. Double click on it to import the blocks to your menu.
Step 11: You need to repeat step 9 this time you need to search for "drivebit" then double click on the icon.
Step 12: Time to code... all the blocks can be found at the relevant coloured part of the menu for example the blue on start is selected from the blue "Basic" part of the menu. The only part that may not make sense is the speed variable. You will need to go to the red "Variables" part of the menu and click "create new variable" and call it Speed. The final code is below.
Code:
Demo
Blog video Make Code Microbit express button push pic.twitter.com/dFNMx88R3e— Warksjammyblog (@warksmessabout1) April 23, 2020
Enjoy :)
No comments:
Post a Comment