Overview
Parking your automobile is sometimes a tiresome task. When negligence transpires, it can create damages 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: HC-SR04, RobotDyn Mega, and 1Sheeld+. The HC-SR04 is an ultrasonic sensor, which is capable of transmitting and receiving ultrasonic waves when bounced off. On the other hand, the RobotDyn Mega is a microcontroller board. This is where the HC-SR04 is programmed to measure distances. Lastly, the 1Sheeld+ is a new easily configured shield for Arduino. It is connected to a mobile app that allows the usage of all of Android smartphones’ capabilities such as LCD Screen, Accelerometer, Magnetometer, GSM, Wi-Fi, GPS, etc. into the Arduino sketch, according to its founders.
Hardware Used
You can buy all this Hardware at Createlabz.
Software Used
- Arduino IDE
- 1Sheeld Android/iOS Mobile Application
Libraries Used
- OneSheeld.h
Application Description
The car parking assistant aims to assist the driver in parking his/her vehicle while avoiding damages as much as possible. This system is built using the components as mentioned above. 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 alarmed through audible speech generated by the 1Sheeld+ own mobile app.
Set-Up the Hardware
The image shown above is the schematic diagram for this project. These connections can be recreated using jumper wires. It is an option to use a breadboard to ensure proper connectivity between the different components.
The image above shows the HC-SR04 ultrasonic sensor. Before using this sensor, it is important that one must know how this sensor works. This sensor has four pins. These are the VCC pin, trigger pin, echo pin, and the ground pin.
The VCC pin is connected to the 5V pin of the RobotDyn board. The trigger pin is supplied with a 10 µs pulse. The RobotDyn board is programmed to do such task. On the other hand, the echo pin is the output pin of the sensor. The echo pin transmits a high pulse until the ultrasonic wave returns to the receiver. Lastly, the ground pin is connected to ground.
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 the sensors to the RobotDyn board is achieved using the 1Sheeld+ app and its own library.
In the 1Sheeld+ board, a switch can be seen, as labeled above. This is the communication and upload switch. When uploading the code to the board, it is imperative that the switch must be favored to the upload part or SW. After uploading, turn the switch to HW, or communication, to allow the shield and the application to receive and transmit data.
Set-Up the Software
#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); } }
The snippet shown above is the code needed for this program. The code is divided into three major parts: the declaration of variables, setup, and loop. Each section will be thoroughly explained below.
#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;
The first part of the code is the declaration of variables. This is where the libraries are first declared and the variables are initialized. In this project, the library used is the OneSheeld library. This library can be installed using the library manager of the Arduino IDE.
The library manager of the Arduino IDE is found on the Sketch tab. When clicked, a drop-down menu appears. Click “Include Libraries” and another drop-down menu appears. Click Manage Libraries to open the library manager.
The image shown above is the library manager. Use the search bar to find OneSheeld. When the OneSheeld library appears, click the Install button located below the library’s written description. This allows the Arduino IDE to install the said library.
void setup() { Serial.begin(9600); OneSheeld.begin(); //starts the 1Sheeld pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); }
The snippet shown above is the second major part of the code. This is the setup function. The setup function allows the program to assign different pins as inputs or outputs. This is also where the code turns the needed libraries on. In this project, the OneSheeld library starts to work through the setup.
Also, the setup function assigns the required baud rate. Baud rate is defined as the rate of transfer of information in a communication channel. In this project, a baud rate of 9600 is used. This means that the serial port is capable of sending and receiving a maximum of 9600 bits per second.
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); } }
The third and final major part of the code is the loop function. The processes inside this function are done repeatedly by the RobotDyn board. There are two processes inside the loop function. These are the distance measurement and the text-to-speech processes.
The distance between the sensor and the incoming obstacle is measured and calculated by the first process. As stated earlier, the trigger pin of the ultrasonic sensor should be supplied with a 10µs pulse. Also, the echo pin gives a high pulse until the ultrasonic wave returns to the receiver. Then, the distance between the sensor and the obstacle can be calculated using the speed of sound. The formula is shown below:
Where:
s = distance
t = time between the transmission and reception of the ultrasonic wave
The second process found inside the loop function is the text-to-speech platform of the 1Sheeld+. This is where the TextToSpeech.say() method is first introduced to the code. This method only accepts the String data type as its parameters. The method’s primary role is to relay the parameter to the mobile application. Using the 1Sheeld+ technology, the relayed parameter is converted from text to speech. This allows the user to be alerted in the form of audible communication.
1Sheeld+ Mobile Application
Download the mobile application on Google Play Store.
The 1Sheeld+ mobile app scans different 1Sheeld+ shields nearby using Bluetooth. Click Scan to find shields 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 portion of the screen, beside the 1Sheeld logo.
The Text-to-Speech screen appears. To ensure connectivity between the shield and the mobile app, click the orange button. This allows the user to connect or disconnect the connectivity at any time.
References
- https://www.hackster.io/tech-duino/arduinomated-car-parking-with-voice-assistance-in-smartphone-c4d677
- https://1sheeld.com/troubleshooting-1sheeld-5-common-issues-1sheeld/
The post Automated Car Parking Assistant using Ultrasonic Sensor, Arduino Mega, and 1Sheeld+ appeared first on CreateLabz.