Feature

Bluetooth Controlled Motor

Control your models with a Smartphone!

Johnny "Meccano"

Issue 60, July 2022

This article includes additional downloadable resources.
Please log in to access.

Log in

Our friend, Johnny Meccano, has done it yet again, combining his love of Meccano with electronics. This month, Johnny sent us details on his recent build and welcomed us publishing it here for our readers.

Usually, we would introduce our maker to you, however, we already introduced Johnny to you back in Issue 42 with his joystick-controlled Meccano rocket launcher. If you want to know more about Johnny, we encourage you to read that feature. There is also Johnny’s Servo Operated Marble Maze to check out in Issue 50, and salvaged power supply feature from Issue 59 as well. Let’s get straight into Johnny’s project.

Remember the old days of Remote Control? Radio transmitters for model planes, infrared remotes that must be pointed at your TV. These days everybody has a smartphone in their pocket. Since COVID, even the Luddites have gone out and purchased smartphones to use apps for QR code check-ins and proof of vaccination to be allowed into places. All these phones can download apps and they all have Bluetooth so it’s not really that difficult to use these features to control your models.

This article will show you how to build the bare basics using a free app on your phone to control a motor with just 3 commands; Forward, Reverse and Stop. Once you have it working, it’s then easy to expand to 10 commands using the same components with just a few more connecting wires.

Let’s start with the KISS (Keep It Simple, Stupid) version. You need to do 3 things.

  1. Download the app to your phone.
  2. Connect the components.
  3. Install the supplied sketch for the Arduino (see the Resources section on our website).

Bluetooth Module

Make sure you use this HC-05 module. Others caused me problems with pairing.

The default password is 1234

The App

I use a Samsung A21S which is Android, so my apps come from Play Store. Apple users need to download apps from App Store. I chose Arduino Bluetooth Controller by Giumig Apps because it was free, simple and had a keyboard layout with 10 buttons similar to a PlayStation.

When you open the app, the first screen shows you available Bluetooth devices. Select HC-05.

Then it will ask what mode
you want.

Select Controller mode.

You will now see a PlayStation keyboard. Tap on the gear icon top right and you will get a screen showing the 10 symbols.

Tap on up arrow and set it to send the number 1. It could be A, B, C but let’s go with 1, 2, 3 for this project.

Prototype Build:

The Electronics using a breadboard

You need a HC-05 Bluetooth module to receive the data from your phone, an Arduino microcontroller to interpret the data and set output pins high or low, and a H bridge to control the motor because a microcontroller can’t supply enough current.

Connect the Arduino, L293D H bridge and Bluetooth module as shown. I’ve used a Nano but a Uno will work just the same. The resistors are there because the HC-05 Bluetooth module is designed for 3.3V operation and the Arduino uses 5V. So, although you can power up the Bluetooth module with 5V, if you apply 5V to the receive pin you may well release the magic smoke. I’ve used a voltage divider consisting of a 2.2k ohm resistor from RXD to Ground and a 1k ohm resistor from RXD to digital pin D3 on the Nano.

The 9V battery supplies enough power for the motor but you shouldn’t connect the Bluetooth module to 9V. Run the 5V from the Nano to VCC on the HC-05. Connect Ground and Vin on the Nano to the 9V rails on the breadboard.

Next connect D3 to IN1 (pin 2) and D4 to IN2 (pin 7) on the L293D then connect D6 to ENA (pin 1).

Pins 4 and 5 on the L293D go to Ground, and finally, pins 3 and 6 on the L293D go to the motor. Double-check then triple-check your connections BEFORE you connect the battery.

The next step is to write the sketch to tell the Arduino what to do if it receives a 1, 2 or 3 from the Bluetooth module.

The Code

You can build this with zero knowledge of the code required. Just copy paste my sketch into your IDE. (The Arduino app for writing sketches.)

Basically, the sketch starts with the library for the Bluetooth module and assigns pin D2 to RX (Receive) and pin D3 to TX (Transmit). Next, the integers are defined for the Enable and Input 1 and 2 pins on the H bridge. Set the ENA high to turn on the H bridge.

Then we have a loop that reads the data coming in from the Bluetooth module and if it’s a 1, set the IN1 low and IN2 high which results in the motor going forward. If it’s a 2 then set IN1 high and IN2 low resulting in reverse and finally if it’s a 3, set both to low which is stopped. That’s about it really. Later, when you’re comfortable with it all, you can use the other side of the H bridge and connect another motor and repeat the code for more pins.

Main Build

The Electronics on a strip board

Your mission, should you choose to accept, is to bravely go where bread-boarders rarely tread. Get your soldering iron out and make your own PC board.

Strip Board is also known as Vero Board and being a Meccanoboy, I cut a piece out the same size as a Meccano part 72 Flat Plate which is 2.5" x 2.5". These boards have hole spacing of 0.1" which means 10 holes per inch so when you hold a Meccano Flat Plate over the board as a template, you’ll notice every 5th hole in the Strip Board lines up perfectly.

Drill 4mm holes in each corner to match the Flat Plate then bolt on the Strip Board and sand or file it back using the Flat Plate as your template. Scrape off the copper track around each hole to prevent a steel bolt shorting things out. I’ve found a Stanley knife is best.

Now, the next part is very important. Position the header sockets on the board and turn it over to mark where you’ll cut keeping in mind that it’s a mirror image when you flip the board.

Cut away the track between the Nano header sockets and between the H bridge pins. Leave the track between the GRD pins.

Use a keyed 2-way header pin for the 9V input to prevent reverse polarity. See website for L293D H bridge pinouts.

Always use chip sockets and header sockets because if a component fails, it’s a nightmare trying to unsolder it. I’ve used two 15-pin header sockets for the Nano and a 16-pin chip socket for the H bridge.

The HC 05 Bluetooth module is mounted on a 6-pin header socket. You can buy 40 pin header sockets and cut them to length with a Stanley knife