Autonomous RC Car

2,242

19

3

With the rise of self-driving, autonomous cars today, I decided to take on the challenge of making one of my own. This project also served as my capstone project in my Engineering Design and Development and Robotics classes and received an award for best autonomous vehicle at a high school STEM competition.

Instead of starting from scratch, I opted to use an RC car that we already had and paired it with a RedBoard Arduino Uno board. I chose the Arduino due to its relative ease of use and programming.

For those wondering, this car has a Redcat Racing 03061 Splash-Resistant ESC with a brushed motor. The ESC was already programmed using the controller that came with the car. I have not tested this with a brushless motor since we do not have one on hand, but anyone is welcome to try this project with a brushless motor.

In brief summary, this car collects data from (5) HC-SR04 Ultrasonic sensors. This data goes back to the Arduino, where it makes decisions on how to move. The Arduino then controls the steering servo and motor accordingly. The program uses the standard Arduino servo library to do so, and no additional libraries are necessary.

The car is capable of variable speed control via a potentiometer and backing up from a wall when it hits one. In addition, the car can correct itself if it drifts too close to a wall by easing itself away.

Step 1: Parts List

Disclaimer: I am not including the parts needed for the car itself, only the additional parts beyond the car. An ESC, motor, chassis, battery, etc. will all be necessary for this.

You will need:

(1) Arduino Uno - knockoffs will work just fine

(1) Breadboard - for this project, I took the +/- rail from one breadboard and used another, smaller breadboard. Any size will do.

(5) HC-SR04 Ultrasonic Sensors

(1) Potentiometer - used to control the speed of the car

(20) Female-Male Dupont wires - I highly recommend having more to use as extenders for other wires if needed

Soldering Iron with solder

Arduino Power Supply - in this case, I used (6) 1.2v AA batteries wired in series. External phone and tablet power banks like this one will also work well when plugged into the USB port.

Tape, hot glue, and/or any other items used to fasten items together

(1) Toggle Switch (optional -- I use it to turn the Arduino on and off)

Step 2: Position the Sensors

First, you will want to correctly position and fasten the sensors. I have (1) sensor facing forward, (2) sensors angled about 45 degrees, and (2) sensors on the sides of the car. I 3D printed mounting brackets for the sides and front, and used hot glue to fasten the angled front sensors since hot glue is non-conductive. The mounting brackets for the sides and front can be downloaded and 3D printed.

Step 3: Add the Breadboard and Potentiometer

Next, you'll want to add in the breadboard and speed-controlling potentiometer before you begin wiring. This is where I used a small breadboard and the +/- from another breadboard due to space on the car's body, but a standard breadboard will also do just fine.

Step 4: Wire Everything

This one is probably the biggest step, and one wrong wire can cause the car to not function properly. Refer to the Fritzing diagram above for extra guidance.

Start by connecting the 5v pin of your Arduino to the positive rail on the breadboard and the GND pin of your Arduino to the negative rail of the breadboard.

Next, wire up the sonar sensors. The HC-SR04 sensors have each of their four pins labeled. They are:

VCC -- 5v power

Trig -- trigger to send an ultrasonic pulse out

Echo -- receiving pin that measures the duration of the pulse

GND - ground pin

Use female-male Dupont wires for this. Each of the VCC pins should be connected to the positive breadboard rail, and each of the GND pins should be connected to the negative breadboard rail. I used extra female-male Dupont wires as extenders for this part since I had an issue with some of the wires not being long enough.

Next, wire the Trig and Echo pins into the Arduino. These will be connected to the digital pins of the Arduino as such:

Front Center Sensor:

Trig -- pin 6

Echo -- pin 7

Left Side Sensor:

Trig -- 4

Echo -- 5

Right Side Sensor:

Trig -- 2

Echo -- 3

Front Left Sensor:

Trig -- 10

Echo -- 11

Front Right Sensor:

Trig -- 9

Echo -- 8

Next, wire the steering servo, motor ESC, and speed control potentiometer.

First, start with the steering servo. The servo on my car had red, orange, and brown wires. The colors may vary a little bit, but they will all be wired similarly:

Brown wire (ground) -- connect to negative breadboard rail

Red wire (5v power) -- connect to 5v breadboard rail

Orange wire (signal) -- connect to pin 13 on your Arduino

The ESC -- or Electronic Speed Controller -- that controls the motor is wired very similarly. In this case, the wires are white, red, and black.

White (signal) -- Connect to pin 12 on your Arduino

Red (5v) -- do NOT connect to anything. Due to a surge of electricity that flows backward when the motor stops, the 5v should not be connected. You could fry a USB port or, possibly, your Arduino.

Black (ground) -- connect to negative breadboard rail

Finally, wire the potentiometer that you put on your breadboard earlier. Small numbers are likely printed on it somewhere. It should be wired as:

1 (left pin) -- connect to negative breadboard rail

2 (middle pin) -- connect to pin A0 on your Arduino

3 (right pin) -- connect to positive breadboard rail

The wiring will look very messy, so if you want to do some wire management, now would be the time to do it.

Step 5: Powering the Arduino

Next, you will want to set up a power solution for the Arduino. Two separate power sources are used in this project: the battery for the car, and the battery for the Arduino. In this case, I used (6) 1.2v rechargeable AA batteries wired in series. Portable cell phone power banks will also work, just make sure to have a cable that plugs into your Arduino's USB port (such as mini-USB).

Please note that 9v batteries will NOT work with this project. Due to the way that 9v batteries are designed, the voltage is sufficient to run the Arduino, but the current coming out of the battery will cause it to die in no time. I also had issues with random reboots on the 9v battery.

If you choose to use the solution that I used, you will need:

(6) AA batteries (alkaline batteries work fine as well)

AA battery holders for all (6) batteries. This one would work great and doesn't even require you to use a soldering iron. For the supply that I made, I daisy-chained (3) two-battery holders together as pictured, soldered the positive/negative wires together, took the DC power plug from a 9v battery adapter, and soldered it to the end positive and negative wires. I then soldered a power switch in series with the power supply for ease of turning the Arduino on and off. This is completely optional.

Step 6: Upload the Arduino Program

Next, you will need to upload the program to the Arduino. Download the program here, and upload it to your Arduino through the Arduino IDE.

For those of you who might look into modifying the code, I have included some pseudocode explaining what each part does.

EDIT 9/25/18 - I added a second program to make it drive in the middle of two walls. I have not had the chance to try out the code due to not having access to the car, but feel free to experiment with it.

Step 7: Plug Everything in and Turn It On

Finally, you will need to plug everything in. First, connect the car battery to the car and turn on your ESC. The ESC should beep, indicating that it is ready to be "armed" by the Arduino. Next, power up the Arduino. The ESC should beep three times, and the wheels should begin turning. If the ESC beeps, but the wheels do not begin turning, turn the potentiometer to the right to increase the speed. If the car is moving too fast, turn the potentiometer to the left.

If the potentiometer works the opposite of the way it should, you can flip the positive and negative wires to solve this.

The video shows the car working, how to change the speed, and the order to turn it on in.

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • PCB Contest

      PCB Contest
    • Big and Small Contest

      Big and Small Contest

    3 Discussions

    0
    None
    ShlokM3

    Question 3 months ago

    Hey, i had a couple of questions and was wondering if anyone could answer it.

    Q1) I wanted to know how i could increase the distance from where it's supposed to turn away from the wall, for eg, right now it avoids the wall from a distance of 5 cm, how can i increase that to 10 or 15. Thanks.

    Q2) Since the distance will be increased, is there any way to make it turn away from the wall without stopping for it to be much smoother.

    Q3) is there any way to make it run in the centre of 2 walls, just like lane driving, so it runs with equal distance on each side, basically a combination of the features asked about in question 1 and 2.

    thanks, any help would be appreciated.

    1 answer
    0
    None
    KyleN38ShlokM3

    Answer 3 months ago

    Q1) To change the thresholds of the sensors, you can change the numbers of the threshold variables. You can find them in lines 45-47 of the code.

    Q2) The car should turn smoothly away from the wall as it is. Personally, I didn't have issues with my car, but there could be some obscure issue that's hiding somewhere that is causing it to stop. I don't really have an answer for this one.

    Q3) I'm working on changing some code right now to make it run between two walls. I will try and upload it once I am finished with it.

    EDIT: I uploaded the code but haven't had a chance to try it out yet. Feel free to experiment and change it as needed.

    1
    None
    seamster

    7 months ago

    Very cool, thanks for sharing!!