Ahh, you’ve noticed that I’ve been on a bit of a throttle jag lately. I just couldn’t help myself on this one. I saw the APDS-9960 RGB and Gesture Sensor in a recent SparkFun new-products announcement, and immediately knew what to do with it.
Don’t get me wrong. I love my PowerCab, but it’s a bit of a handful when you’re switching. Who needs access to all those functions, anyway, when you’re just spotting cars? Back, forth, stop…if that’s all you’re doing, why use a handset at all?
So, I saw the sensor. I read the specs, and perused the hookup guide. I ordered one, along with a logic level converter to make it play nice with my 5V Arduino. I already had everything else to do the job. Breadboarding everything together took ten minutes. The only real challenge I had was in software. Sometimes I’d get gesture data out of the sensor, sometimes it was just dead. The sample code for proximity and RGB sensing worked just fine. Connections checked out okay. Eventually, I stumbled into an adjustment of the gesture gain setting, and suddenly it worked. I grafted some of my code from other throttle projects onto the sample sketch, and a hands-off “Jedi” throttle resulted.
Wanna build your own?
Here’s the schematic:
To breadboard this like I did, you’ll need to solder some male header pins onto the sensor and logic-convertor boards. The Ardumoto board seen here is a veteran of several other projects, its stackable headers and screw terminals were purchased separately and soldered on, as well. A 12V wall wart into the Arduino provides enough power to run an N scale locomotive.
Here’s the code. It’s not fancy, but it works. I built in just enough momentum to prevent the locomotive from screeching to a halt. (You don’t want too much, lest you sail right past the uncoupling magnet and into the bumper.) The maxSpeed constant is set to a value that runs my Atlas GP-7 at a slow speed for switching; you may need to change the value for your own locomotive, or better yet, add a potentiometer for adjustment.
The “left” and “right” gestures move the locomotive. (If it runs the wrong way, just reverse the track connections.) Any other gesture brings it to a stop. There’s plenty of room for refinement here, but I’m impressed at how easy it was just to get something working. I did some test running on Susquehannock Industrial Park, and found that it works pretty well, even in this relatively raw state.
It will likely be a while before I rework this circuit into a polished-and-permanent version. I have some future switching-layout projects in mind, however, and I will certainly be including this in the plans. One remaining challenge is adapting this concept for DCC, since my locomotive fleet is gradually getting decoders. I’m working on that.