Thursday, 23 April 2020

REMOTE Controlling a Lego train motor with a micro:bit




REMOTE Controlling a Lego train motor with a micro:bit


What you will need:



  • TWO micro:bit's, TWO USB cable's 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 create the code to get your train motor moving at the push of a button on a remote controller micro:bit
  • How to to operate your remote controlled Lego Train

Lets get started:


Step 1. This blog assumes you have followed blog one controlling a lego train link if not start there first.


Step 2: Now we need to add some code for the train to listen for messages from the remote control. This uses the radio set of blocks(I'm saying its purple coloured blocks). You will need to create add new messages to be able to send them. Like below:


Other than that the code should be pretty clear for the train's micro:bit.


Here is the code for the train micro:bit, this needs all the code from tutorial 1 as well:



Step 3: Next up we need to create the code for the second micro:bit which will act as the remote controller. It is very simple:

Press a for "fwd" to be sent

Press b for "rev" to be sent

press a and b to send stp

Below is the code for the remote:




Now you should be able to control your Lego train like the demo below. 

Demo






Enjoy :) 








No comments:

Post a Comment