Rajat Naruka
Published © GPL3+

parking sensor

In this project the sensor will detect the distance while reversing the car and make the driver alert to avoid collision.

BeginnerProtip2,631
parking sensor

Things used in this project

Code

parking sensor

Java
const int trigPin=7;
const int echoPin=9;
long Duration;
int Distance;
int led=6;
void setup() {

  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(led,OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
  
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  Duration=pulseIn(echoPin,HIGH);
  Distance=Duration*0.034/2;
  if(Distance<50)
  {
    digitalWrite(led,HIGH);
    
    
  }
  else 
  {
    digitalWrite(led,LOW);
  }
  Serial.print("Distance: ");
  Serial.println(Distance);
}

Credits

Rajat Naruka

Rajat Naruka

8 projects • 1 follower

Comments