From e9bf6498f0ba0a32480a276b8434022aa4f22f36 Mon Sep 17 00:00:00 2001 From: AutonomusParkingCar Date: Tue, 3 Dec 2019 16:28:51 +0000 Subject: [PATCH] Upload files to '' --- SENSOR.ino | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SENSOR.ino diff --git a/SENSOR.ino b/SENSOR.ino new file mode 100644 index 0000000..00a9336 --- /dev/null +++ b/SENSOR.ino @@ -0,0 +1,29 @@ +#define trigPin A1 +#define echoPin A0 + +void setup() { + Serial.begin (9600); + pinMode(trigPin, OUTPUT); + pinMode(echoPin, INPUT); +} + +void loop() { + long duration, distance; + digitalWrite(trigPin, LOW); // Added this line + delayMicroseconds(2); // Added this line + digitalWrite(trigPin, HIGH); +// delayMicroseconds(1000); - Removed this line + delayMicroseconds(10); // Added this line + digitalWrite(trigPin, LOW); + duration = pulseIn(echoPin, HIGH); + distance = (duration/2) / 29.1; + + if (distance >= 1000 || distance <= 0) { + Serial.println("Out of range"); + } + else { + Serial.print(distance); + Serial.println(" cm"); + } + delay(250); +}