Created
October 15, 2019 15:37
-
-
Save rburnett3/416012ce3938590c78733010db434483 to your computer and use it in GitHub Desktop.
MB7389 pulse width
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
/* Arduino example code for MaxBotix MB7389 HRXL-MaxSonar-WR weather resistant ultrasonic distance sensor: pulse width output. More info: www.makerguides.com */ | |
#define sensorPin 2 | |
long distance = 0; | |
long duration = 0; | |
void setup() { | |
pinMode(sensorPin, INPUT); | |
Serial.begin(9600); | |
} | |
void read_sensor() { | |
duration = pulseIn(sensorPin, HIGH); | |
distance = duration; | |
} | |
void print_data() { | |
Serial.print("distance = "); | |
Serial.print(distance); | |
Serial.println(" mm"); | |
} | |
void loop() { | |
read_sensor(); | |
print_data(); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment