Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Help with Ultrasonic Sensor on Arduino Uno (http://www.chiefdelphi.com/forums/showthread.php?t=133451)

GHernandez2582 24-01-2015 14:09

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?

dave1027 24-01-2015 14:41

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);
}

GHernandez2582 24-01-2015 15:40

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!


All times are GMT -5. The time now is 01:47.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi