Category:
Ardunio
Title:
Simple Parking Sensor with Ardunio

Things you can do with Ardunio depend on your limits. Many technologies we see in everyday life are actually "how is this?" kind of One of them is the parking sensor used in vehicles. In the following example, first the circuit diagram will be used and then the source code will be given.

The purpose of this project is to emit noise from the buzzer after 20 cm when an object is detected with ultrasonic distance sensor. As the distance gets closer, there will be more frequent sounds. The desired distance and sound intervals can be adjusted by making the desired changes

Project Scheme

Necessary materials

  • Ardunio Uno
  • HC-SR04
  • Buzzer 
  • Breadboard
  • Jumper cables

Ardunio Source Code

byte trigger = 10; //HC-SR04 trigger pin

byte echo = 11; //HC-SR04 ECHO pin

int buzzerpin = 2; //Buzzer pin

unsigned long timedelay; // Activation time variable interval of echo pin (microsecond) 

double totalPath; 

int distance; 

void setup() {

  pinMode(trigger, OUTPUT); // We do OUTPUT so that we can apply voltage to the trigger leg.

  pinMode(echo, INPUT); // We do INPUT so that we can read Echo pins value

  pinMode(buzzerPin, OUTPUT); //We do OUTPUT to ring the buzzer

  Serial.begin(9600); 

}

void loop()

{

  digitalWrite(trigger, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigger, LOW);

  // With the pulseIn function, we record the time that the sound wave will reach the Echo leg and switch to the HIGH state

  sure = pulseIn(echo, HIGH);

  // time-distance conversion

 totalPath = (double)timedelay*0.034;

  distance = totalPath / 2;

  Serial.print("Distance between HC-SR04 and the surrounding surface:");

  Serial.print(distance);

  Serial.println("cm.");

  sound_play();  // We call sound_play funtion 

  delay(500);

}

void sound_play()

{

if(distance <= 4)    // If the distance is less than 4 cm, continuous sound will be played

  {

      digitalWrite(buzzerPin,HIGH); //Giving voltage to buzzer.

     delay(100);                 

  }

else if(distance >= 5 && distance < 8)

  {

     digitalWrite(buzzerPin,HIGH);

     delay(100);              

     digitalWrite(buzzerPin,LOW); 

     delay(100);  // Between 5-8 cm to 0.1 second interval

  }

  else if(distance >= 8 && distance < 10)

  {

     digitalWrite(buzzerPin,HIGH); 

     delay(100);             

     digitalWrite(buzzerPin,LOW);   

     delay(400); // Between 8-10 cm to 0,4 second interval

  }

  else if(distance >= 10 && distance < 15)

  {

     digitalWrite(buzzerPin,HIGH); 

     delay(100);                 

     digitalWrite(buzzerPin,LOW); 

     delay(800);  // Between 10-15 cm to 0,8 second interval

  }

 else if(distance >= 15 && distance < 20)

  {

     digitalWrite(buzzerPin,HIGH);

     delay(100);                 

     digitalWrite(buzzerPin,LOW); 

     delay(1000);   // Between 15-20 cm to 0,8 second interval

  }

}
619 views
COMMENTS