Automated Car Parking Assistant using Ultrasonic Sensor, Arduino Mega, and 1Sheeld+

 

Automated Car Parking Assistant using Ultrasonic Sensor, Arduino Mega, and 1Sheeld+

01 Overview

Parking your automobile is sometimes a tiresome task. When negligence transpires, it can create damage to the vehicle and its surroundings. This project aims to mitigate the damage caused by careless vehicle parking.

The car parking assistant is composed of three major components: the HC-SR04, the RobotDyn Mega, and the 1Sheeld+. The HC-SR04 is an ultrasonic sensor capable of transmitting and receiving ultrasonic waves when they bounce off an object. The RobotDyn Mega is a microcontroller board, and this is where the HC-SR04 is programmed to measure distances. Lastly, the 1Sheeld+ is an easily configured shield for Arduino, connected to a mobile app that brings an Android smartphone's capabilities — LCD screen, accelerometer, magnetometer, GSM, Wi-Fi, GPS, etc. — into the Arduino sketch.

Project Use Case

This project suits drivers or makers who want an affordable, DIY parking-assist system that gives audible distance feedback while parking, rather than relying on a factory-installed sensor system.

02 Hardware and Software Components

Gather everything below before you start.

Hardware Components

Component Description
HC-SR04 Ultrasonic Sensor Transmits and receives ultrasonic waves to measure the distance to the nearest obstacle.
Arduino Mega 2560 (RobotDyn) Main microcontroller that reads the HC-SR04 and drives the 1Sheeld+ shield.
1Sheeld+ Arduino shield that connects to a mobile app, giving access to phone features like text-to-speech.
Breadboard (optional) Helps keep connections between components secure and organized.
Dupont Jumper Wires Connects the HC-SR04 and shield to the Arduino Mega.
Android/iOS Mobile Phone Runs the 1Sheeld+ app and provides the text-to-speech output.

Software Tools

Software Description
Arduino IDE Used to write, compile, and upload the sketch to the Arduino Mega.
1Sheeld Android/iOS Mobile Application Pairs with the 1Sheeld+ shield over Bluetooth and provides the Text-to-Speech shield feature.

Libraries Used

Library Purpose
OneSheeld.h Provides the interface for communicating with the 1Sheeld+ shield and its mobile-phone features.

03 Application Discussion

The car parking assistant aims to assist the driver in parking their vehicle while avoiding damage as much as possible. In this project, the RobotDyn Mega is used to program the HC-SR04 ultrasonic sensor to measure the distance between the car and the obstacle. To warn the driver, the 1Sheeld+ is programmed to use its text-to-speech platform in the mobile application — the driver is alerted through audible speech generated by the 1Sheeld+'s own mobile app.

04 Hardware Setup

The connections can be recreated using jumper wires. Using a breadboard is optional, but it helps ensure proper connectivity between the different components.

HC-SR04 Ultrasonic Sensor

Before using this sensor, it's important to know how it works. It has four pins:

Pin Connection
VCC 5V pin of the RobotDyn board
Trigger Supplied with a 10 µs pulse from the RobotDyn board
Echo Output pin — transmits a high pulse until the ultrasonic wave returns to the receiver
Ground Connected to ground

1Sheeld+ Shield

The 1Sheeld+ is an Arduino shield capable of using the sensors found on a mobile phone. These sensors include LCD screen, accelerometer, magnetometer, GSM, Wi-Fi, GPS, etc. Integrating these sensors with the RobotDyn board is achieved using the 1Sheeld+ app and its own library.

Important: The 1Sheeld+ board has a communication/upload switch. When uploading code to the board, the switch must be set to SW (upload). After uploading, switch it to HW (communication) so the shield and the mobile app can send and receive data.

05 Software Setup

Follow these steps before uploading the sketch.

Step 1 — Install the OneSheeld Library

The OneSheeld library can be installed using the Arduino IDE's Library Manager.

  1. Open the Sketch tab, and a drop-down menu appears.
  2. Click Include Libraries, then click Manage Libraries to open the Library Manager.
  3. Use the search bar to find OneSheeld.
  4. When the OneSheeld library appears, click Install below its description.

Step 2 — Upload the Code

  1. Open the Arduino IDE and paste in the code from the Code section below.
  2. Set the 1Sheeld+ switch to SW before uploading.
  3. Select Tools → Board → Arduino Mega 2560 and the correct COM port.
  4. Click Verify to compile, then click Upload.
  5. Once uploaded, switch the 1Sheeld+ back to HW for communication.

Step 3 — Set Up the 1Sheeld+ Mobile Application

Download the 1Sheeld+ mobile app from the Google Play Store.

The 1Sheeld+ mobile app scans for nearby 1Sheeld+ shields using Bluetooth. Click Scan to find your shield and connect.

After connecting the mobile app and the shield, select the Text-To-Speech option. Click the shield button located on the top-right of the screen, beside the 1Sheeld logo.

The Text-to-Speech screen appears. To confirm connectivity between the shield and the mobile app, click the orange button — this lets you connect or disconnect at any time.

06 Code

Copy the file below into the Arduino IDE as described in the Software Setup section. Read the Code Breakdown section to understand what each part does.

car_parking_assistant.ino

Arduino / C++
#include <OneSheeld.h>

#define CUSTOM_SETTINGS
#define INCLUDE_TEXT_TO_SPEECH_SHIELD

char charValue[4];  //charVal variable stores the words which are to be spoken

const int trigPin = 7;
const int echoPin = 4;

long duration;
float distance;
void setup()
{
  Serial.begin(9600);
  OneSheeld.begin();    //starts the 1Sheeld
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  long duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  Serial.println(distance);

  dtostrf(distance, 4, 1, charValue);
  if (distance <= 30)
  {
    TextToSpeech.say("Stop!");
    delay(1000);
    TextToSpeech.say(charValue);
    delay(1600);
    TextToSpeech.say("centimeters");
    delay(1900);
  }
  else if (distance > 30 && distance < 170)
  {
    TextToSpeech.say("Keep it slow! ");
    delay(1700);
    TextToSpeech.say(charValue);
    delay(1600);
    TextToSpeech.say("centimeters");
    delay(1200);
  }
  else if (distance >= 170)
  {
    TextToSpeech.say("Continue moving! ");
    delay(2500);

  }
}

07 Code Breakdown

The code is divided into three major parts: the declaration of variables, setup, and loop.

Variable Declaration

Arduino / C++
#include <OneSheeld.h>

#define CUSTOM_SETTINGS
#define INCLUDE_TEXT_TO_SPEECH_SHIELD

char charValue[4];  //charVal variable stores the words which are to be spoken

const int trigPin = 7;
const int echoPin = 4;

long duration;
float distance;

This is where the libraries are declared and the variables are initialized. In this project, the library used is the OneSheeld library, installed using the Arduino IDE's Library Manager (see Software Setup).

setup()

Arduino / C++
void setup()
{
  Serial.begin(9600);
  OneSheeld.begin();    //starts the 1Sheeld
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

The setup function assigns the trigger and echo pins as output and input, and starts the OneSheeld library so the shield begins working. It also sets the baud rate — the rate of information transfer in a communication channel. This project uses a baud rate of 9600, meaning the serial port can send and receive a maximum of 9600 bits per second.

loop()

Arduino / C++
void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  long duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  Serial.println(distance);

  dtostrf(distance, 4, 1, charValue);
  if (distance <= 30)
  {
    TextToSpeech.say("Stop!");
    delay(1000);
    TextToSpeech.say(charValue);
    delay(1600);
    TextToSpeech.say("centimeters");
    delay(1900);
  }
  else if (distance > 30 && distance < 170)
  {
    TextToSpeech.say("Keep it slow! ");
    delay(1700);
    TextToSpeech.say(charValue);
    delay(1600);
    TextToSpeech.say("centimeters");
    delay(1200);
  }
  else if (distance >= 170)
  {
    TextToSpeech.say("Continue moving! ");
    delay(2500);
  }
}

The loop function runs two processes repeatedly: distance measurement and text-to-speech alerts.

Distance measurement: The trigger pin is supplied with a 10 µs pulse, and the echo pin gives a high pulse until the ultrasonic wave returns to the receiver. The distance between the sensor and the obstacle is then calculated from the travel time using the speed of sound, where s is distance and t is the time between transmission and reception of the ultrasonic wave.

Text-to-speech alert: The TextToSpeech.say() method only accepts a String parameter. Its role is to relay that parameter to the mobile application, which — using 1Sheeld+ technology — converts the text to speech, alerting the driver through audible communication.

08 Conclusion

This Automated Car Parking Assistant shows how an ultrasonic sensor, an Arduino Mega, and a 1Sheeld+ shield can work together to help a driver park more safely. As the vehicle approaches an obstacle, the HC-SR04 continuously measures distance, and the 1Sheeld+ relays a spoken warning through the driver's phone — turning a simple distance reading into an audible, easy-to-understand alert that helps reduce the risk of parking damage.

09 References

  • Arduinomated Car Parking with Voice Assistance in Smartphone — Hackster.io
    (https://www.hackster.io/tech-duino/arduinomated-car-parking-with-voice-assistance-in-smartphone-c4d677)
  • Troubleshooting 1Sheeld: 5 Common Issues — 1Sheeld
    (https://1sheeld.com/troubleshooting-1sheeld-5-common-issues-1sheeld/)

10 Project Authors

  • Mikko Bryant Alinsub
Quality Checked by
  • Lukie-Mar Lonzaga
  • Miles Darren Bagnol
  • Elijah Joseph Orias
Automated Car Parking Assistant using Ultrasonic Sensor, Arduino Mega, and 1Sheeld+ – CreateLabz

 

1sheeld+, Arduino, Arduino mega, Car, Hc-sr04, Knowledgebase, Onesheeld, Parking, Robotdyn, Text-to-speech, Ultrasonic

Leave a comment

All comments are moderated before being published