Micro:bit - Controlling a Brushless Motor

by Thorsgaard Efterskole in Circuits > Microcontrollers

3532 Views, 4 Favorites, 0 Comments

Micro:bit - Controlling a Brushless Motor

IMG_0239.jpg

Brushless motors are great. Because of their great power to weight ratio they allow you to make light projects, that demands a lot of motor power, such as airplanes or drones. These days there is a lot of cheap brushless motor and controllers avaible and they are actuelly fairly easy to control with the micro:bit.

Supplies

1 x micro:bit

1 x Micro:bit breakout board (Which ono is not importent)

2 x male to female jumpwires (I am using 2 male to male and 2 female to female, since I had no male to female)

1 x Battery holder

2 x AAA batteries

1 x JW82019 2S 800mAh Li-Ion Battery T-plug

1 x 30A Brushless Electronic Speed Controller

1 x A2212/6t 2200kv Brushless motor (This motor is often sold heap bundled together with the speed controller)

Optional: A propeller and something to put it on the motor.

Wiring

IMG_0246.jpg
IMG_0244.jpg
IMG_0242.jpg

Wire up the circuit as seen on the drawing and picture above. Most of it is pretty straight forward, since the different connectors helps with showing what should be connected with each other.

The importent part is that you should not pull power from the speed controller to the micro:bit, since the speed controller supplies 5 volt and the micro:bit can only take 3.3 volt. So only connect the signal and ground.

The 5 volt from the power supply can be pretty handy. If you want to build something that also needs servo motors, such as an airplane for example, then the speed controller can supply 5 volt for the servo motors that controls the wings.

Theory

Electronic Speed Controllers are controlled with the standard 50Hz PWM signal that servo motors also uses. So during each 20 ms interval we send a pulse to the speed controller and the lenght of the pulse is what controls the speed of the motor. In theory 1 ms for the slowest speed and 2 ms for the fastest, but often they will be a bit off and you need to calibrat a bit.

Before you can power the motor you need to send an arming signale. The armind signal need to be in 1 ms pulses or slightly under. The motor will beep until it gets the arming signale. WHen it gets the arming signale, the motor will make a funny tripple confirmation beep and then it go silent.

Coding

image.jpg

First you go to the Makecode editor and start a new project. Be aware that since I am danish, these buttons have slightly different names in the pictures.

On start the program set the variable Speed to 0. The A and B buttons just add or remove 2 from the Speed variable.

Since the speed controller uses the same 50Hz PWM signal that servo motors also uses, we can use the servo set pulse block to control it. The puls is ontrolled in microseconds. A microsecond is 1/1000 of a millisecond, so we multiply the speed variable with 100.

Here is the program.

This is a rather safe program where ou have to push the A button a few times before the motor arms itself. You can try to set the starting value of speed to something like 7, so you don't have to push A that many times to arm the motor. You can also change the value that the A and B buttons to change how precise you can control the speed.

Test

Micro:bit and Brushless motor

Now you can test the program. You should not add a propeller to your motor before you have attached it to something, because you will properly not be able to hold it with your fingers.