You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
643 B

// https://www.youtube.com/watch?v=M-UKXCUI0rE&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=53
#include <Arduino.h>
int trigPin = 12;
int echoPin = 11;
int pingTravleTime;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravleTime = pulseIn(echoPin, HIGH);
delay(25);
Serial.print("Ping Time: ");
Serial.println(pingTravleTime);
}