|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with Ultrasonic Sensor on Arduino Uno
I need help programming an Ultrasonic Sensor on an Arudino Uno. The Ultrasoinc is an LV-MAXSONAR-EZ. I've tried different methods and even downloaded this https://github.com/Diaoul/arduino-Maxbotix library , but I still can't get it to work. Does anyone have a method to make a this or a similar Ultrasonic Sensor work with the Arduino Uno and display the distance in inches and/or centimeters?
|
|
#2
|
|||
|
|||
|
Re: Help with Ultrasonic Sensor on Arduino Uno
i have done this a couple times, those sensor are great.
First ensure it is wired correctly: when looking down at the sensor, with the pins at the bottom, supply ground on the right most pin and +5v to the next pin to the left. connect the 3rd pin from the left to analog input 0. Below is a basic version of a sketch that will work with this sensor. long inches = 0; long raw=0; long rawavgsum=0; long rawavg=0; const int avgcounter = 90; void setup() { // initialize serial: Serial.begin(9600); // make the pins outputs: } void loop(){ for (int i = 0; i<avgcounter;i++) { raw = analogRead(0); rawavgsum=raw+rawavgsum; delay(10); } rawavg = rawavgsum/avgcounter; inches = rawavg/2; //At 5 V on Vcc, the sensor is rated 9.8mV/ inch. pin range isis 0-1024 counts per 0-5V, 1 count = 4.8mV, 2 counts = 1 inch Serial.print("avg Inches: "); Serial.print(inches); Serial.print("\n"); rawavgsum=0; delay(250); } |
|
#3
|
|||
|
|||
|
Re: Help with Ultrasonic Sensor on Arduino Uno
Thanks! Turns out my wiring was a bit off, but your's works too. I appreciate the help!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|