Created
October 11, 2021 14:37
-
-
Save Hotfirenet/25d7f9e9afdb91cdd1a5dba44d95a6b4 to your computer and use it in GitHub Desktop.
This file contains 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
const byte TRIGGER_PIN = 7; // entrée numérique 7 affectée au trig | |
const byte ECHO_PIN = 11; // entrée numérique 11 affectées à l'écho | |
const unsigned long MEASURE_TIMEOUT = 25000UL; // délais avant annulation de mesure : 25ms correspond à 8m à 340m/s | |
const float SOUND_SPEED = 340.0 / 1000; // Vitesse du son dans l'air en mm/us | |
void setup() { | |
Serial.begin(115200); | |
pinMode(TRIGGER_PIN, OUTPUT); | |
digitalWrite(TRIGGER_PIN, LOW); | |
pinMode(ECHO_PIN, INPUT); | |
} | |
void loop() { | |
digitalWrite(TRIGGER_PIN, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(TRIGGER_PIN, LOW); | |
long measure = pulseIn(ECHO_PIN, HIGH, MEASURE_TIMEOUT); | |
float distance_mm = measure / 2.0 * SOUND_SPEED; | |
Serial.print("\t"); | |
Serial.println(distance_mm,0); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment