From cda20e5bd2535f80a42cd47c13f3074f93f8e77d Mon Sep 17 00:00:00 2001 From: amitpatwa <56401945+amitpatwa@users.noreply.github.com> Date: Thu, 10 Oct 2019 20:48:49 +0530 Subject: [PATCH] arduino.c --- arduino | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 arduino diff --git a/arduino b/arduino new file mode 100644 index 0000000000..f5324bd9ca --- /dev/null +++ b/arduino @@ -0,0 +1,27 @@ +// defines pins numbers +const int trigPin =9; +const int echoPin =10; +// define variables +long duration; +int distance; +void setup() +{ pinMode(trigPin, OUTPUT); +pinMode(echoPin, INPUT); +Serial.begin(9600); +} +void loop() +{ + //clears the trigPin + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + //Sets the trigPin on HIGH state for 10 micro seconds + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + digitalWrite(trigPin, LOW); + //Reads the echoPin, returns the sound wave travel time in microeseconds + duration= pulseIn(echoPin, HIGH); + //calculating the distance + distance= duration*0.034/2; + //Prints the distance on the Serila monitor + Serial.println(distance); +}