Last active
June 27, 2018 07:39
-
-
Save elktros/77dda098248c4ec06d8d9eaa81dac230 to your computer and use it in GitHub Desktop.
Code for Arduino based Car Reverse Parking Sensor Circuit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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