This is my first 'ible. It's an Arduino-controlled Lego RC car using XBee units for the "RC" part. The idea was shamelessly stolen from sath02's excellent 'ible, attributed above. We began and finished the project over winter break 2012, and I've been sitting on these pictures for about a year, and have finally found some time to get them posted.
I won't be providing a step-by-step instructional, but I will be highlighting what were some of our key challenges, and what our solutions were for them.
Here are the parts we used, in no particular order:
- LEGO Technic Dune Duster #8207
- LEGO Technic Power Pack #8720
- Arduino UNO R3
- Sparkfun Ardumoto Motor Driver Shield
- Sub-micro Servo ROB-09065 (Sparkfun)
- 2x XBee 1mW Trace Antenna - Series 1 (802.15.4)
- XBee Shield
- XBee Explorer USB
- Various terminals and cabling
- Miscellaneous LEGO bits (90% of the parts came from the kits, we just needed 2 or 3 pieces to fill in)
- 2x RadioShack 3 AAA battery holders
Most of the code was written by myself, and while I tried to pique my son's interest in it, a lot of it was over his head, though I think he got the basics. He's already been through the SparkFun Inventor's Kit with me, so he knew the basics of circuits and motors and the like, the code work was just too tedious for him.
The one thing I took away from this, besides spending some quality time with my son and building something really cool, was not to underestimate what children can grasp at any age. Don't let the "recommended age" guidelines put you off of introducing your kids to a learning experience like this. You're planting seeds for a lifetime of discovery and innovation.
And with that, on to the good stuff.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Powering the Drive Wheels
This was one of the more challenging aspects of the project believe it or not. Figuring out how to mate the 9v LEGO Technic motor with the Ardumoto was challenging. I had seen custom power bricks and the like, and I think LEGO even sells (or used to) adapters. In any case, I finally devised a hack using a soldering iron and a small LEGO brick to make an adapter for the jumpers from the Ardumoto. It took a couple of tries and some mangled bricks to get it right (much to my son's dismay), but what I ended up with in the end works fairly well. The whole assembly (including the motor drive itself) is rather fragile, since the whole thing is put together without glue, and a couple whacks into baseboard or cabinets will invariably loosen things up a bit. The little 9v LEGO Technic motor, while not speedy, has enough torque to squeal the tires when quickly changing from forward to reverse, and is definitely fast enough for a LEGO RC car.
Step 2: Turning Left and Right
Connecting the micro-servo to the Technic steering system was accomplished using a zip-tie, and one of the adapters and some screws that came with the servo, that just so happened to mate up to one of the Technic driveline pieces perfectly. After setting the limits in the software, the steering system was one of the easiest parts of the project. The LEGO Technic parts really helped here, as hacking something together for this could have taken quite a while without it. It is probably the primary reason why I decided to go with the Technic system.
Step 3: Making Sufficient Autonomous Power
To power the project, we started with a 9v battery and a simple adapter, hoping to eventually go to a LiPo and save space and weight. We quickly figured out however, that with running the XBee, the Ardumoto, and the Arduino, their was simply not enough battery capacity in a 9v for more than 5 minutes or so. After realizing that LiPo did not fit the budget, stepping up to 6x AAA was the only option as I had to have 9v for the Technic drive motor, and 6x AA, while providing great capacity, would have radically altered the design. With perseverance, and a little help from my 8 yo LEGO Master, we were able to stretch the body, remount the electronics platform, and came away with what I felt looked much more substantial, even without the articulating rear suspension. The original design had been much closer to the look of the Dune Duster kit, but just did not provide enough space to carry sufficient power.
To make the battery pack, we bonded two RadioShack 3 AAA battery holders together using Gorilla Glue and wired them in series to get the needed 9 volts. The pack provides 30 minutes to an hour of run time, by which time it has smacked into the cabinets, or has run afoul of the cat, and is in need of R&R anyway.
Step 4: Final Assembly and Tweaks
I wanted to avoid permanently affixing anything, since my son likes to redesign things quite often (turns out, he's left this like it is for a year), so I decided not to use double-sided tape or glue to mount the electronics and the batteries and instead opted for rubber bands. It's kind of a pain to change out the batteries, but since it is not one of those toys that gets used a whole lot, it doesn't cause any problems. I might try to devise a better system to mount everything, but going to that trouble might mean a complete redesign anyway.
Step 5: Cracking the Code
For a lot of people doing their first project, this might seem like the hardest part, but it's not. Writing code can be a bit tedious at times, but, especially when running on an Arduino project of your own design, when it all works, it provides a great feeling of accomplishment. The Arduino is programmed in C and C++, but the IDE that is packaged with it includes the "Wiring" library, which makes many powerful functions accessible to the novice programmer. Basically, if you can write a loop, you can program an Arduino.
I browsed many sample programs (including Sath02's) but when I set out to write my control code, I decided to start from scratch, since I wanted to access the controller directly over serial using the XBee to be able to adjust some of the parameters like the limits on the servo, speed of the drive motor, etc. My eventual goal is to write a more complete UI for it, but for now, it is controlled via a terminal directly accessing the XBee serial network. I use X-CTU (available from Digi's website) to send commands to the XBee on the car, which accepts four commands: forward (w), reverse (s), left (a) and right (d). X-CTU allows either direct input, or you can create a packetized sequence of commands and send in batch. In batch mode, you can insert a comma or commas to create a small delay.
I've included my code below, feel free to modify it for your use, with proper attributions of course, but if you are interested in really learning to code, you'll learn a lot more starting from scratch.
Step 6: Summary
All-in-all, it was a great way to spend some cold winter days indoors and provided an invaluable learning tool for my son, and dare I say myself. Check out the videos below for some quick action picks, and I have a (much) longer one that goes through the operation - if anyone is interested, I will put it up.
I think our next project will be something robotic, and I'll be putting it up as soon as we finish. Until then, Happy Making!