The code in this repository allows you to build a simple remote-control car using an Arduino Mega and a motor driver shield such as the old Adafruit Motor Sheild or the OSEPPP Motor & Servo Shield. It uses the Adafruit Motor Shield Library to drive 4 DC motors based on inputs from a controller that is wired into the Arduino, eleminating the need for complex IR or RF modules and code. This does come with the downside of having a cord connected between the controller and the car, but if the cord is long enough, it shouldn't be too much of a problem. It also controlles 6 LED lights that are used for headlights and for decoration, with the lights reacting to the different directions the car is told to move in.
As for the hardware, you will need a V1 Adafruit Motor Sheild, an OSEPPP Motor & Servo Shield or some other motor driver compatible with the Adafruit Motor Shield Library. You'll also need four DC motors and wheels to go on them, an Arduino Mega, and a way to provide 12V to the car. I find that simply connecting lots of AA battery holders together in series works well. If you want to use the LED features, you'll need to have 6 typical LEDs handy. To enclose it all, you can go as fancy or as simple as you want. I used a long rectangular cardboard box, but you can use anything from a metal tin to a 3D-printed housing to a wooden enclosure. Just keep in mind the weight of the car and the power of the motors and the power source. To see photos of how I put my car together, visit the wiki page.
I have written all the code in Arduino C, as is typical with Arduino projects. I used VS Code and PlatformIO to write and debug my code, but I've included Arduiino IDE and raw C++ versions as well. Just use whichever platform you're used to working with - the code is pretty much the same, except for the importing of the Arduino.h
library in the PIO version.
Speaking of libraries, the only one required to use the motor shield is the Adafruit Motor Shield Library. You can install it by downloading the ZIP file from GitHub and installing it, or by searching for it in the Arduino IDE library manager. If you do this, mare sure you install the one called Adafruit Motor Shield Library
, NOT the one for the V2 sheild. NOTE: I wrote the code myself, but used Codeium AI for autocomplete and some code completion.
A great thing about this project is that, so long as you have the same inputs and motor driver, you can build pretty much any sort of car you want. The simplicity of this code opens up tons of room for improvement, redesign, customization, and more. Feel free to fork the code and change it as you like. I am placing this code under the GPL v3 license. Be sure to read and follow the license if forking and/or redistributing this code.