Arduino parking sensor

Arduino parking sensor

Welcome to the construction of the parking sensor with Arduino. First of all: “What is a parking sensor” and “What is the parking sensor for? Let’s consider the questions like. What is the parking sensor? Why is it used? Parking sensors are a technological device that, as an acoustic and digital display, informs the driver of the proximity of the vehicle to surrounding objects, allowing him/her to park more easily and in a more up-to-date way. We will realize this project with the help of sound and digital displays. We will learn how to use the 16×2 LCD and the ultrasonic distance sensor HC-SR04 in a single project. Let’s start with the materials needed for the Parking Sensor project.

Necessary materials:

10K Potentiometer
16×2 LCD
HC-SR04 Ultrasonic Distance Sensor
100R-220R resistor
Male-to-male jumper cable

LCD and Arduino connections

You can browse the 16×2 LCD datasheet we use in our project, or you can get an idea of the LCD pins by looking at the diagram below. We have a total of 16 pins on our LCD screen. If you look at the PCB, I am sure that the potentiometer has caught your attention. You can adjust the contrast of your LCD screen by playing with the potentiometer. Our anode and cathode tips of the 15th and 16th pins are connected to the 5V and GND pins respectively, thus switching on the backlight of our LCD screen. Since our article will be a bit long, I’ll keep the topic short with a diagram.

Don’t forget to solder the pins of your LCD screen to pin headers before starting the project, so that you can use your 16×2 LCD screen more conveniently on your breadboard, which we will use as a screen in the Park Sensor project. Let me add, without forgetting that if you want to dim the backlight of your LCD screen, you can put a 220R resistor between the cathode pin (pin 16) and ground.

Sensor and Arduino Connections

The sensor we will use in the Parking Sensor Project will be the distance sensor. The use of the ultrasonic sensor HC-R04 on the PCB is not as complicated as its LCD because it has only 4 pins. The Vcc end is connected to 5V on the Arduino and the Gnd end to the GND pin on the Arduino. You can connect the Trig and Echo pins to any 2 pins on the Arduino, in my project I divided the 9 and 10 pins into these.

include //icluded needed library

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Parameters: (rs, enable, d4, d5, d6, d7)

const int trigPin = 9;

const int echoPin = 10;

long duration;

int distanceCm;

int buzzer = 13;

void setup() {

lcd.begin(16, 2); //beginning lcd as 16×2

pinMode(trigPin, OUTPUT); //sends signal to sensor from arduino so it is output

pinMode(echoPin, INPUT); //sends signal to arduino from sensor so it is output

pinMode(buzzer, OUTPUT);


void loop() {

digitalWrite(trigPin, LOW);


digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW); //created signals to calculate things

duration = pulseIn(echoPin, HIGH); //measured time in created signal coming from echoPin by pulseIn

distanceCm = duration * 0.034 / 2; // convert time to distance

if ((distanceCm < 15) && (distanceCm > 10)) { //If object is between 15-10 cm

digitalWrite(buzzer, HIGH); //ring the buzzer

delay(500); //along 500ms

digitalWrite(buzzer, LOW); //stop buzzer

delay(500); //along 500ms


else if ((distanceCm < 10) && (distanceCm > 5)) { // If object is between 5-10 cm

digitalWrite(buzzer, HIGH); //ring the buzzer

delay(100); //along 500ms

digitalWrite(buzzer, LOW); //stop buzzer

delay(100); //along 500ms


else if (distanceCm < 5) { //If object is closer than 5 cm

digitalWrite(buzzer, HIGH); //ring the buzzer

lcd.setCursor(6, 1); //7. column 2. row

lcd.print(“DUR!”); //Writed “DUR!” on the screen (means STOP!)

delay(2500); //along 2500ms

lcd.clear(); //clear the screen


lcd.setCursor(0, 0); //1. column 1. row of LCD display

lcd.print(“UZAKLIK: “); //writed UZAKLIK: on LCD

lcd.print(distanceCm); //Writed distance

lcd.print(” cm”); //writed cm to the end

delay(10); //refresh it in each 10ms