Introduction: Getting Started With the Maxbotix Sonar Sensor - Quick Start Guide
The MaxSonar EZ1 provides very short to long-range detection and ranging, in an incredibly small package. It can detect objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. (Objects from 0 inches to 6-inches range as 6-inches.) The interface output formats included are pulse width output (PWM), analog voltage output (Vcc/512 volts per inch), and serial digital output (9600 baud). A good sensor for when a Sharp IR distance sensor won't cut it.
Step 1: Are You a Pro? Go Straight to the Datasheet...
If youre a pro cut straight to the data sheet- if not, here's a quick start guide on using the Maxbotix sonar sensor&
Step 2: Things You'll Need...
Things youll need:
An Arduino
A half size breadboard
A piezo buzzer
Wires
MaxSonar sensor
All of these are available in the Adafruit store.
Step 3: Solder It Up!
Solder 3 wires to the Maxbotix sonar sensor. Ground, power and analog. Thats all well need for this simple test, and for the most part if youre just using this sensor with an Arduino its all youll likely use.
Step 4: Wire It Up!
Using the diagram, wire it up!
Step 5: Run Some Code..
Run some code!
The MaxSonar EZ1 outputs analog voltage with a scaling factor of (Vcc/512) per inch. A supply of 5V yields ~9.8mV per inch. On the other hand, the Arduino’s analog-to-digital converter (ADC) has a range of 1024, which means each bit is ~4. 9mV. For that reason, to convert the number returned by the ADC to inches, we have to divide by 2.
// using the maxsonar quick start http://www.adafruit.com
// http://www.adafruit.com/index.php?main_page=product_info&cPath=35&products_id=172
int sonarPin = 0; //pin connected to analog out on maxsonar sensor
int piezoPin = 9; // specifies the pin connected to piezo from Arduino
int inchesAway; // inches away from the maxsonar sensor
void setup() {
pinMode(piezoPin, OUTPUT);
//Serial.begin(9600); // starts serial communication, used for debugging or seeing the values
}
void loop() {
inchesAway = analogRead(sonarPin) /2; // reads the maxsonar sensor and divides the value by 2
// approximate distance in inches
//Serial.print(inchesAway); // prints the sensor information from the maxsonar to the serial monitor
//Serial.println(" inches from sensor");
if (inchesAway < 24) { // if something is 24 inches away then make a 1khz sound
digitalWrite(piezoPin, HIGH);
delayMicroseconds(500);
digitalWrite(piezoPin, LOW);
delayMicroseconds(500);
}
}
13 Comments
9 years ago on Introduction
Nice write up. The diagram is a bit wrong however. The ground from the sensor is connected to the power on your breadboard diagram. Black wire from sensor should connect to black horizontal row on breadboard, not the power horizontal row.
11 years ago on Introduction
I need help!!!
I am working on a project for school and I need it to work to graduate. My project is to integrate a proximity/ sonar sensor onto an RC car to make it stop if it gets within a certain distance from an obstacle. before I can even begin to worry about integrating the sensor on the car I need to get it to work with the arduino uno. I am having difficult getting the program to work for the sonar sensor. I know that the original schematic and code was designed to work with an arduino diecimila, but all I could find was an uno. what can I do to make this work? I am using the maxbotix sonar sensor and the piezo buzzer used in the quick start guide. Please help me out
11 years ago on Introduction
Nice tutorial.
I'm doing a similar project and I'd like to document it but I'm unable to locate the fritzing part for the MaxBotix sensor. Did you create this one on your own?
12 years ago on Introduction
is their any way you can make a trigger with a tela photo lens. but remeber the light that triggers it is emeral and its about 25 feet away if you could help out post back.
14 years ago on Step 3
What advantages/disadvantages do the other pin outs offer?
Reply 14 years ago on Step 3
The preview feature assumes the view actually works correctly...
http://www.maxbotix.com/MaxSonar-EZ1__FAQ.html#Tell_me_how_the_serial_pulse_width_and_analog_voltage_outputs_compare
Reply 14 years ago on Step 3
www.maxbotix.com/MaxSonar-EZ1__FAQ.html#Tell_me_how_the_serial_pulse_width_and_analog_voltage_outputs_compare
Reply 14 years ago on Step 3
www.maxbotix.com/MaxSonar-EZ1__FAQ.html#Tell_me_how_the_serial_pulse_width_and_analog_voltage_outputs_compare
14 years ago on Step 4
Nice diagram. What program did you use to generate it?
Reply 14 years ago on Step 4
fritzing.org/
14 years ago on Introduction
like that green circle thing on a submarine that shows where things are?
14 years ago on Introduction
so what does this actually do?
Reply 14 years ago on Introduction
its SONAR (sound navigation and ranging) it is like what bats have to see because they are sort of blind.... a,k.a Uber- Hearing