Skip to content

Commit

Permalink
Create HC-SR04.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
NikodemBartnik authored May 19, 2018
1 parent eb873b5 commit f04362d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions HC-SR04/HC-SR04.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define TRIG 2
#define ECHO 3

void setup() {
Serial.begin(9600);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
}

void loop() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(5);
digitalWrite(TRIG, LOW);

float t = pulseIn(ECHO, HIGH);
float distance = t*0.017015;
Serial.print("Distance: ");
Serial.println(distance);
delay(500);
}

0 comments on commit f04362d

Please sign in to comment.