Skip to content

Instantly share code, notes, and snippets.

@rburnett3
Created October 15, 2019 15:37
Show Gist options
  • Save rburnett3/416012ce3938590c78733010db434483 to your computer and use it in GitHub Desktop.
Save rburnett3/416012ce3938590c78733010db434483 to your computer and use it in GitHub Desktop.
MB7389 pulse width
/* 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