Arduino Proximity Sensor Attachment for RC Car

by mae4 in Circuits > Arduino

748 Views, 3 Favorites, 0 Comments

Arduino Proximity Sensor Attachment for RC Car

IMG_9796.jpeg

This circuit was created by Moira Iñiguez, Alaiza Preciado, Ashley Preciado, Valeria Bedolla, and Ibrahim Sanno as part of the Compton College Spring Make It Happen Project, in association with the Compton College STEM Center.

The goal of this project was to equip an RC car with a proximity sensor, displaying the data in real time on an LCD. Other project goals included displaying the time on the LCD, having an RGB LED with colors coordinating with distances, and a buzzer going off at a set distance. All project goals were met, and our group was awarded second place in the final project competition and first place in the school-wide science symposium.

~

The main challenge that we encountered was piecing together the code. Because no one in our group had prior coding experience, we at first put together a code that was unusable. After understanding more about what was needed from the code, we used a pre-existing code that connected the LCD to the ultrasonic sensor as a base to build our final code on. 

It would have been helpful if we had found a project online that already had the components that we chose, but we found no such source. Because of this, we decided to put our project up on Instructables.com so that anyone else looking to do what we did would have an easier time doing it. 

For the future, we would like to add an SD card to our design so that we could collect the proximity data. Given more time, we also would have wire-wrapped and/or soldered our circuit together in order to make it more secure.

Supplies

IMG_9756.jpeg
  • Arduino Mega
  • Breadboard
  • Battery pack with USB
  • Remote Control Car
  • Ultrasonic Sensor
  • Liquid Crystal Display (LCD)
  • Real Time Clock Module (RTC)
  • RGB LED
  • Active Buzzer
  • LCD I2C adaptor
  • (3) 220 Ohm resistors
  • (8) male-female wires
  • (15) male-male wires
  • Electrical tape


Helpful references:

https://www.instructables.com/Ultrasonic-Distance-Sensor-Arduino-HC-SR04/

https://youtu.be/HynLoCtUVtU

https://arduinogetstarted.com/tutorials/arduino-ultrasonic-sensor-lcd

Wiring It Up

IMG_9714.heic.jpeg

We apologize that there are no diagrams to go along with the setup, but we've include the parts of the Arduino manual that we used to wire up all the components.

We wired everything up according to the manual, except for the LCD–we used this reference to wire up this component.

Wire up all components per Arduino manual, running the power from 5V on the Arduino to the power column on the breadboard. Do the same for ground, running the wire from ground on the Arduino to the ground column on the breadboard.

Any components with duplicate pins can be wired through the same row on the breadboard.

Code

We drew from three main sources gathering code:

https://www.instructables.com/Ultrasonic-Distance-Sensor-Arduino-HC-SR04/

https://youtu.be/HynLoCtUVtU

https://arduinogetstarted.com/tutorials/arduino-ultrasonic-sensor-lcd


Here is the code:

//MAKE IT HAPPEN GROUP 4 FINAL PROJECT
//"Arduino Proximity Sensor for RC Car"
//by Valeria Bedolla, Ashley Preciado, Alaiza Preciado, Moira Iniguez. and Ibrahim Sanno

//sources:
//https://www.instructables.com/Ultrasonic-Distance-Sensor-Arduino-HC-SR04/
//https://youtu.be/HynLoCtUVtU
//https://arduinogetstarted.com/tutorials/arduino-ultrasonic-sensor-lcd
//ELEGOO: THE MOST COMPLETE STARTER KIT TUTORIAL FOR MEGA 2560

//code cleaned up using ChatGBT

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DS3231.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); 

const int trigPin = 9;   // TRIG pin
const int echoPin = 8;   // ECHO pin

const int buzzerPin = 12; // active buzzer pin

const int redLedPin = 2; // RGB LED pins 
const int greenLedPin = 3;
const int blueLedPin = 4;

float duration_us, distance_cm;

DS3231 clock;

void setup() {
 lcd.init();
 lcd.backlight();
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(redLedPin, OUTPUT);
 pinMode(greenLedPin, OUTPUT);
 pinMode(blueLedPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);
 Serial.begin(9600);
 clock.begin();
 clock.setDateTime(__DATE__, __TIME__);
}

void loop() {
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 duration_us = pulseIn(echoPin, HIGH);
 distance_cm = duration_us / 58.0;

 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Distance(cm):");
 lcd.print(distance_cm);

 RTCDateTime dt = clock.getDateTime();
 lcd.setCursor(0, 1);
 lcd.print("Time: ");
 lcd.print(dt.hour);
 lcd.print(":");
 lcd.print(dt.minute);
 lcd.print(":");
 lcd.print(dt.second);

// distances can be changed for needed requirements 
 if (distance_cm <= 10) {
  digitalWrite(redLedPin, HIGH);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(blueLedPin, LOW);
  digitalWrite(buzzerPin, HIGH);
 }
 else if (distance_cm <= 25) {
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(blueLedPin, HIGH);
  digitalWrite(buzzerPin, LOW);
 }
 else if (distance_cm <= 1200) {
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, HIGH);
  digitalWrite(blueLedPin, LOW);
  digitalWrite(buzzerPin, LOW);
 }
 delay(300);
}

Test It!

IMG_8878 (1).jpeg
IMG_9806.jpeg

After loading the code to your circuit, it's time to test your project. If you find that it's not working, check that all your wires are connected correctly. If it still won't work, check each sensor and display separately, making sure each individual component works.

After getting the code to run, go ahead and play with the code, modifying the distances to your own specific needs.

The LCD should display the distance in centimeters and the time.*


*if you want it to display the date as well instead of saying "time", delete the line that says

lcd.print("Time: ");

and replace it with

 lcd.print(dt.month); lcd.print("-");
 lcd.print(dt.day); lcd.print("-");
 lcd.print(dt.year);  lcd.print(" ");

Tape Circuit to RC Car

IMG_9798.jpeg
IMG_9794.jpeg
IMG_9758.jpeg
IMG_8882.jpeg

Using electrical tape, tape the project onto the RC car. If you have time on your hands, clean up the circuit a bit and wire-wrap or solder it, and the attach it to the RC car using a studier method. If you're on a tight deadline like we were, though, just tape that sucker down.

You can use the electrical tape to secure some of the looser wires so that they don't come undone when the car is in motion.


Place the portable battery pack in the back of the RC car. Plug the Arduino mega into the battery pack.


And that's it! You now have a functional proximity sensor attachment for your RC car.