I’m working on a project where I want to drive two motors based on signals coming from a cell phone. Something simple. Something that activates every time I get a text message on my phone. There are many ways to do this, I’ll outline the ones I tried and why they did or did not work for me.
Step 1: 99 Problems and a Working Connection Ain't One
There are a couple of options for passing signals from a cell phone to a motor. These are the ones I tried and my reasons for using (or not using) them.
tl;dr: use BT module
Spark Core: WiFi-enabled, Arduino-compatible, small board. Say what!? I Should be able to just send a signal from the phone to this thing directly via UDP/TCP, but as of April 2014 this was not possible. While the team at Spark is working towards a modification to their firmware, when I tested this board, it only ran if it was connected to the internet and to the Spark Core server. I just wanted local communication, so this was no good.
IOIO-OTG: Connects directly to the phone via USB cable, and allows the phone app to have a bunch of GPIO pins. Awesome! This would have been perfect if I had taken the time to figure out how to write my own firmware. As it comes, the firmware on the IOIO-OTG is pretty much like a firmata. All the logic has to run on the phone and the only thing it does is expose some I/O pins. Because I am using simple DC motors with limit switches, this seemed like a risky option. What if the phone loses connection to the board, or the app crashes, while one of the motors is on? The IOIO-OTG might not get the limit-switch signals to stop the motor.
Arduino ADK as USB host: Also seemed promising. Directly send messages to an Arduino from a phone, via a cable! Win, right? I could write my own Arduino code to deal with limit-switch and motor logic, and the phone would only send simple STOP/GO commands to the Arduino. Perfect, except the pairing between Arduino, phone, and app was, at best, crappy. The order in which I had to turn on the phone, the Arduino, and the app, and plug the cable, was very specific. I think it was turn phone on, turn Arduino on, plug Arduino into phone, unplug Arduino from phone, plug Arduino into phone, start app. Anything other than that would cause the phone to not be recognized by the Arduino ADK, and sometimes would even cause the phone to reset. Very picky !!
Arduino ADK with BlueTooth dongle: Works fine with some dongles. Other dongles from the same brand and type, just wouldn’t pair. I might have been able to make it work by adding some delays in the Arduino code, but at this point I was pretty disappointed with the ADK and the USB Host Library.
Arduino with BlueTooth module: I initially did not want to use BT because of how it has to be paired, and sometimes it loses its connection/pairing, and some packets get dropped. . . but in the end, it was the most sensible solution. It doesn’t matter if packets get dropped, I’m only sending a very simple STOP/GO kind of signal, and I can add redundancy. It also doesn’t matter if the phone gets un-paired from the BT module. I know it’s there, right next to the phone, so I can keep trying to connect to it using code in the Android app. While this might seem hard initially, it’s a lot easier than what I had to do to re-establish the cable ADK connection once the phone lost track of the Arduino (unplug, plug, re-start app, etc).
So in the end: BT for the win!
Step 2: Motor and Motor Prep
I’m using 12V car window actuators to move a modified megaphone in two directions (pan and tilt). I like using these motors because they are pretty beefy, easy to find, and usually cheap in surplus stores. I’ve bought these from U$9, U$15, and currently they’re $20 at surpluscenterdepot.com.
Some disassembly is required in order to get the motors out of their car-window linear-movement mechanism.
Tools I used: Hex/Allen key, pliers, flat head screwdriver.
There are 3 screws that connect the plastic gear box to a metal structure, that have to be removed. After taking them out, the motor can be twisted and freed from the rest of the mechanism. I find it useful to use the plastic shaft coupler that comes with the motor to attach it to things. It’s not necessary to use it, there are gears/sprockets that probably couple to the plastic piece on the motor shaft.
Removing the plastic piece from the linear mechanism is a bit of a pain. I used pliers to bend some of the metal that holds it down, then I wedged it free with a screwdriver.
Step 3: Motor Driver Circuit
These are 12V motors that can draw up to 5A when stalled. To move the loads I wanted to move, they draw around 1.5A to 2A. And even though they’re geared down, they’re still super fast at the full 12V, so I decided to do some PWM’ing in order to control their speed a little bit.
So, 12V, 2A to 5A, PWM, and bi-directional control. . . led me to this little H-bridge driver circuit: TLE-5206. I might be cutting it a little too close with the max continuous current spec, but for this application, I’m only using a 5A power supply for both motors, so it’s probably fine . . .
Here’s how to drive the chip.
And here’s my circuit for driving two of these, with limit switches. The board was made for an Arduino Mega ADK, because when I first designed this, I was still hoping to use the ADK, but it can be made for any other type of Arduino with 4 PWM pins and 4 digital input pins.
Step 4: Codez
Here’s the simplified version of the Android code necessary to establish Bluetooth pairing with the Arduino:
BluetoothDevice myBTDevice = myBTA.getRemoteDevice(BLUETOOTH_ADDRESS); BluetoothSocket myBTSocket = myBTDevice.createRfcommSocketToServiceRecord(SERIAL_UUID); myBTSocket.connect(); OutputStream mOutputStream = myBTSocket.getOutputStream(); InputStream mInputStream = myBTSocket.getInputStream();
Step 5: Test
Here’s the mechanism being tested at full 12V speed.