Microbit Infared Controller

by tornadocoder8424 in Circuits > Microcontrollers

4430 Views, 6 Favorites, 0 Comments

Microbit Infared Controller

2021-10-23_19-28-50 (2).jpg

This instructible combines the Microbit with infrared technology. This project can be used as a wireless remote for a Microbit game, a wireless controller, and much more. This project is great for beginner users who want to learn the Microbit interface and those who want to integrate a wireless controller into their existing projects. In this project, I will be showing you how to connect any Infrared remote controller to your Microbit and how to start programming your Microbit to use the controller’s buttons. In this tutorial, we will be using MakeCode from Microsoft. It has an easy-to-use block code interface for beginner coders (it also has a JavaScript and Python interface). You can also use it without creating an account.

Supplies

  • Microbit
  • USB micro cord
  • IR Receiver (Can be found in electronics around the house or bought cheaply on amazon for 4-5 dollars for a pack of 10 or more)
  • IR Remote Controller (Any remote control)
  • 3 alligator clips (or wires)
  • Code 1
  • Code 2

Create Your Project

1.jpg

(For those who don’t want to learn how the code works you can download the code here and skip to step 6.)

First, you need to go to MakeCode for Microbit (link here: https://makecode.microbit.org). Then you click on New Project and give your project a name and then click the green create button. 

Extensions

2.jpg

You should now be at the Microbit interface. To use an IR receiver with your Microbit you need to add an extension so your Microbit knows what to do with the incoming data. Click on the Advanced button and then click “Extensions” at the bottom.

Installing the IR Extension Pack

3.jpg

In the search bar type “IR” and hit enter. The one to use is called “makerbit-ir-transmitter” and should be the first one. Click on it and it will begin to add the package to your project.

Starting to Code

4.jpg

NOTE: All of the blocks of code are color-coded with the corresponding tabs they are under.

First, delete the forever block in the coding space by clicking on it and hitting the backspace button on your keyboard (the delete key if you are a mac user).

Then click on the loops tab and drag the while loop into the code area.

Next, drag it into the “on start” block.

Click on the false button in the while loop and change it to true

Finishing the Code

5.jpg

Click the MakerBit button above the advanced button and drag the “connect IR receiver to pin…” block inside the while loop.

We will then change the decode mode from “Keyestudio” to “NEC”. (NEC is a transmission protocol for Infrared devices to communicate with the receiver).

Drag the “show string” block from the Basic tab and put it under the “connect IR receiver to pin…” block.

Then drag the “convert” block from the Text tab under the advanced tab into the “show string” block.

Next, drag the “IR datagram” from the MakerBit tab into the convert block.

This code on start searches pin 0 for an IR input using the NEC protocol. It then shows the input it receives as an IR datagram. The while loop repeats this program until we turn off the Microbit.

The Final code is shown above.

Installing on the Microbit

6.gif

Click the Download button in the bottom left corner or you can download the file below. The file will have a hex extension.

Connect your Microbit to your computer using the USB cable.

Drag the file to your Microbit, which will appear as a drive on your computer, and the code will install on the Microbit. On the Microbit you will initially see “0x00000000” scroll across the screen. This simply means it has not detected a button press.

Downloads

Connect the IR Reciever

7.jpg

Now we will attach the IR sensor to the Microbit. Connect the source pin to pin 0 and the corresponding voltage and ground pins. (The voltage pin is usually indicated with a plus sign and the ground with a minus sign.)

You can either look up the IR receiver you have (usually written on the back) or you can reference the chart above from EasyEDA (https://easyeda.com/winter2015/Infrared_IR_Remote-DqnTNjd7f).

Collecting the IR Datagrams

8.jpg

Now we can take our remote and click a button. You should now see numbers and letters scrolling across the screen in the same format. If you do not see anything, make sure your remote has charged batteries and the IR sensor is connected correctly (Some IR sensors do not follow the pattern shown above so you might need to change the connection). Jot down the IR datagrams across the Microbit and the corresponding symbol. We will use these later to code our Microbit.

Erase Code

9.jpg

Next, click on the JavaScript tab and delete any code in the space.

New Code

10.jpg

After you have all of the IR diagrams for your buttons you can download Code 2 below. This code is a text file. Paste the code into the field (NOTE: If you start a new project for this part you need to install MakerBit to your project again refer to steps 2 and 3).

Downloads

Back to Block Code

11.jpg

Now click on the Blocks tab to go back to block coding. The code from the JavaScript was translated into block code. 

Customize the Code

12.jpg

The first part of this code, before the while loop, just informs you that the Microbit is active. The next section connects pin 0 to the Microbit with the Infrared datagram. We then take the input from the IR receiver and set it equal to a variable we created: button1. We can then see a bunch of if statements. In the if statements are the commands that are going to be run when the buttons are pressed.

In the If commands replace the text with all of your buttons’ IR datagrams (add more of if statements if you have more buttons).

Integrate With Your Own Project!

13.jpg

Now the code is complete! You now have a working wireless remote for your Microbit. This can be integrated with tons of projects. All you need to do is change the commands in the if statements to do what you need them to do.