Created
December 27, 2020 11:01
-
-
Save donly/a83a1e1f5b2c34c15aff2e84e2d86a3c to your computer and use it in GitHub Desktop.
An Arduino project of HC-SR04+ demo
This file contains hidden or 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
//HC-SR04+ | |
const int trigpin = D4; | |
const int echopin = D3; | |
long duration; | |
int distance; | |
void setup(){ | |
pinMode(trigpin,OUTPUT); | |
pinMode(echopin,INPUT); | |
Serial.begin(115200); | |
} | |
void loop(){ | |
digitalWrite(trigpin,HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigpin,LOW); | |
duration=pulseIn(echopin,HIGH); | |
distance = duration*0.034/2; | |
Serial.println(distance); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment