RC Car hack using the Microbit and Motor Driver Shield

In one of my previous posts, I showed my toy truck modified with an Arduino Uno and a motor driver. It’s a great way to make use of what is usually working condition RC toys, but are chucked away because either batteries have leaked or the remote doesn’t work anymore. Salvation army and Mary Potter Hospice shop ( NZ thrift shops) are places to visit for used RC cars (under $5). The idea is to use the chassis, motor+axle combo and wheels to save time. However, you could build one yourself with some bits of wood and an ice cream container if you wanted.

Basics of motors to begin with. A motor is what drives the car as well as steers it. They are cheap and easy to procure. Usually the cheaper RC cars all deploy a 3v motor (one to drive the back wheels and one for the steering axle). The steering motor is heavily geared at times. More expensive RC cars would use a geared motor called a servo. You would know its not your usual motor, when you see more than two wires coming out of it (servo is usually 3 and geared motors have more). When you connect a motor to a battery it will spin one way and when you flip the terminals around, it will spin the opposite way. You could connect the terminals to the motor driver whichever way you wanted as you can program it to go the right way.

Open up the RC Car. Remember, DO NOT BUY A NEW ONE (or steal your child’s favorite RC car), as most likely you will end up wrecking it. Modding it, involves undoing the body, chopping up cables, removing old electronics and refitting with Microbit. Ideally you are looking for a mid sized RC Car which will accommodate the Microbit motor driver (6.5cms by 6cms) and the Microbit on top – most likely you will have to cut a hole through the driver seat 🙂 Buggies / trucks are the best as they have space for hosting the board but other cars can be modified too. [insert pic of open car here]

You will have to modify your space accordingly to get the board in. Hot glue works just as good if you can’t get screws in. It needs to be easy to pull out if needed to use in another project.

Finding the motor cables should be relatively easy. Ensure there are no batteries in the battery compartment. The cables are usually color coded going into the battery compartment and to the motors from the electronics. (red – dead or also known as positive and black is negative). From the back of the car, identify where the motor and axle sit, trace the cables coming out of there. If you have two motors then there will be four cables, otherwise there should be just two cables coming from one motor driving both wheels [insert pic of cables]. Those cables need to go into Motor 1 port on the driver shield. Similarly with the steering, identify cables coming out from the front , isolate them from the electronics of the car and pop them in Motor 2 port.

Connect the cables coming out of the battery port into Power on the motor shield. Ensure you put black-ground, and Red-positive into the right connectors. Time to test and see if it works before you start putting everything back together.

You will need to install code separately for both the Transmitter (Microbit which will be the remote control for the car) and the receiver (Microbit on the car). Download the code for Transmitter here and Receiver here

The code (in Javascript) has been copied below if that’s more convenient. Feel free to modify as needed. I used roll to control the steering. You can also use Pitch if you like.

//RCTransmitter Code - goes to the remote
let roll = 0
let steering = 0
let throttle = 0
radio.setGroup(12)
radio.setTransmitPower(7)
basic.forever(function () {
    throttle = 0
    if (input.buttonIsPressed(Button.A)) {
        throttle = 100
    } else if (input.buttonIsPressed(Button.B)) {
        throttle = -100
    }
    radio.sendValue("throttle", throttle)
    steering = 0
    roll = input.rotation(Rotation.Roll)
    if (roll > 45) {
        steering = 100
    } else if (roll < -45) {
        steering = -100
    } else if (roll == 0) {
        steering = 0
    }
    radio.sendValue("steering", steering)
})
//RC ReceiverCode - goes into the Microbit on the car

radio.onReceivedValue(function (name, value) {
    led.toggle(0, 0)
    if (name == "throttle") {
        if (value > 0) {
            kitronik_motor_driver.motorOn(kitronik_motor_driver.Motors.Motor1, kitronik_motor_driver.MotorDirection.Reverse, 100)
        } else if (value < 0) {
            kitronik_motor_driver.motorOn(kitronik_motor_driver.Motors.Motor1, kitronik_motor_driver.MotorDirection.Forward, 100)
        } else {
            kitronik_motor_driver.motorOff(kitronik_motor_driver.Motors.Motor1)
        }
    } else if (name == "steering") {
        if (value >= 100) {
            kitronik_motor_driver.motorOn(kitronik_motor_driver.Motors.Motor2, kitronik_motor_driver.MotorDirection.Reverse, 80)
            basic.pause(40)
            kitronik_motor_driver.motorOff(kitronik_motor_driver.Motors.Motor2)
        } else if (value <= -100) {
            kitronik_motor_driver.motorOn(kitronik_motor_driver.Motors.Motor2, kitronik_motor_driver.MotorDirection.Forward, 80)
            basic.pause(40)
            kitronik_motor_driver.motorOff(kitronik_motor_driver.Motors.Motor2)
        } else if (value == 0) {
            kitronik_motor_driver.motorOff(kitronik_motor_driver.Motors.Motor2)
        }
    }
})
radio.setGroup(12)

After you transfer the code separately to each microbit, you are ready to test. Press buttons A and B on the remote individually then tilt the remote. If the remote is flat (parallel) to ground with LED’s facing up, then the roll is zero. When titled to left or right, it will accordingly rotate the steering. It might need tweaking and that’s where you will have to play with the code. I can’t give you all the answers either. I modified the code from here

Troubleshooting: Hardware – 1) If motors spinning in opposite direction of what you want it to do, change the values in the code.

2) If motors do not spin at all, try giving the motor direct power from batteries and see if they spin. If they still don’t unfortunately you have to replace the motor. (Check) Batteries, they die fairly quickly on the motor driver so I recommend rechargeables for long use.

Software – 1) Radio connects directly and there is no switch unless you add one, which means the minute you put your batteries in, it will start steering unless your remote is straight upwards ( its programmed to start steering when the remote is rotated side to side ). You can modify that by changing how you would like it to be steered ( maybe add more buttons and connect them to pins on the microbit).

The next awesome mod would be to wire up LED lights on the car connected to the pin outs on the Microbit.

Please feel free to contact me if you come across any issues with the tutorial and I can try provide some support.

Lesson 1 – Intro to Arduino – Year 10 Programme

PS: Download link is now updated with the fixed PowerPoint! Thanks for letting me know.

Trying to continue what my predecessor(John Barrow) started with Arduino! A complete junior programme that teachers in schools can pick up and run in class. All you will need is an Arduino kit ( Probably don’t need to buy a complete kit but customise one as per requirements). Kits are readily available on NZ sites like Surplustronics, Jaycar NZ and Trademe; however, if you would like something cheaper (and in bulk quantity) then Aliexpress would be the way to go. Bear in mind, sometimes it can be painfully long for those goods to arrive from overseas! So if you need it urgently, I do not recommend it.

Starter kit as found on www.ebay.com

I have attached what I think is a simple introductory PowerPoint lesson to the Arduino. It starts off with what and why, followed by practical uses before getting into setting up and running the blink example. Most of the images used are from copyright free sources and I have done my best to reference them. There is no commercial benefit from this PowerPoint! I have also attached a Unit Plan for the Arduino. Feel free to modify as per requirement. The objectives and outcomes are slated for a year 9 / 10 class to get into electronics rather than learning it for an assessment.

Lesson-01-(updated)Introduction-to-Arduino