Skip to content

Instantly share code, notes, and snippets.

@rburnett3
Created October 15, 2019 12:47
Show Gist options
  • Save rburnett3/a7af78c9ef1f2ca1c3060e17c504852a to your computer and use it in GitHub Desktop.
Save rburnett3/a7af78c9ef1f2ca1c3060e17c504852a to your computer and use it in GitHub Desktop.
maxsonar-mb1240-analog-voltage
/* Arduino example code for MaxBotix MB1240 XL-MaxSonar-EZ4 ultrasonic distance sensor: analog voltage output. More info: www.makerguides.com */
#define sensorPin A0
int distance = 0;
void setup() {
Serial.begin(9600);
}
void read_sensor() {
distance = analogRead(sensorPin) * 1;
}
void print_data() {
Serial.print("distance = ");
Serial.print(distance);
Serial.println(" cm");
}
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