May 9, 2015

Arduino Auto-Pilot Boat

EDIT 5/26/2016
Over the two years since I first wrote this code, I received a lot of questions concerning the code of this project. I never expected that people would use it as an example for their own projects, so my code was very confusing and poorly organized, and for that, I apologize. I have since rewritten the entire code from scratch and have tested it. The only functional difference is that the turning is now more gradual and smooth than what you will see in the videos below. I have kept the remainder of the article below as it was originally written, however the source code links now link to the updated code. Thanks for your interest and good luck in your projects!

Download the updated Arduino sketch

After accumulating a generous amount of birthday/Christmas money, I got the itch to do a project. Somehow I settled on trying to build GPS autopilot system for some generic RC boat I found on Amazon. I immediately ordered the GPS shield and LSM303 magnometer/accelerometer breakout board from Highly motivated at first, I began soldering things and running little test programs. I started with a program where you would give it a direction, and it would beep faster as you oriented the Arduino in that direction.

It didnt take long to get discouraged as I did run into a lot of problems. Every week that passed in which I didnt work on it bothered me more. It didnt help that my current job site was right on the lake where I wanted to test it. One day I came home and said, “To hell with it, that boat is going into the water today! I dont even care if it comes back.” I added a few more lines of code, wired the engines up, and set out for the lake. I dropped it in the water and it began heading exactly where it was supposed to, and then it returned exactly where I told it to. The damn thing worked!

After the low-speed initial test I partnered up with my good friend Myke, who so graciously lent his GoPro knowing good and well that it might not come back. Myke and I did a lot of swimming those few weeks retrieving that damn boat. We ran into all sorts of problems from water leakage to burnt out transistors. It was all worth it though that day we cut it loose, watched it perform its lap, and then came back.

I considered cleaning up the code, but decided against it, instead leaving the glorious mess in-tact. Its a lot of boat-running function mixed in with the Adafruit GPS library, but the navigation/math section is pretty clean, and I had fun writing that part.

Here is a rough layout of the parts. The 9V battery hooked to the engine was actually one of those 7V rechargeable RC battery packs. The other 9V battery was to give the Arduino its own noise-free power source (Noise from the engines kept resetting the Arduino). Here I used the Adafruit GPS breakout board, when the project actually used the GPS shield, but they didnt have the graphic. Other than that, this should be pretty faithful to the actual design.