Skip to content

Instantly share code, notes, and snippets.

@elktros
Last active June 27, 2018 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/77dda098248c4ec06d8d9eaa81dac230 to your computer and use it in GitHub Desktop.
Save elktros/77dda098248c4ec06d8d9eaa81dac230 to your computer and use it in GitHub Desktop.
Code for Arduino based Car Reverse Parking Sensor Circuit.
const int trigPin = 11;
const int echoPin = 10;
const int buzzPin = 6;
long duration;
float distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzPin, OUTPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = 0.034*(duration/2);
if (distance < 100)
{
digitalWrite(buzzPin,HIGH);
}
else
{
digitalWrite(buzzPin,LOW);
}
delay(300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment