Author Topic: Problems with LV-MaxSonar-EZ1 code  (Read 7183 times)

0 Members and 1 Guest are viewing this topic.

Offline Brandon121233Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 320
  • Helpful? 0
  • "Genius is %1 inspiration and %99 perspiration"
Problems with LV-MaxSonar-EZ1 code
« on: April 12, 2007, 04:12:29 PM »
Hey everyone
I'm having some difficulties with making the LV-MaxSonar-EZ1 ultrasonic rangefinder, work with my arduino board. I'm trying to use the analog output from it to measure the distance in inches. The manual says that
Quote
Outputs analog voltage with a scaling factor of
(Vcc/512) per inch. A supply of 5V yields ~9.8mV/in.
and 3.3V yields ~6.4mV/in. The output is buffered
and corresponds to the most recent range data.
This is the code I have so far:

Code: [Select]
int ultraAn = 0;    // select the input pin for the ultrasonic sensor
int val = 0;       // variable to store the value coming from the sensor
int dist = 0;      // variable to store the converted distance in inches

void setup()
{
  Serial.begin(9600);        // setup the serial port to send the values back to the computer
}

void loop() {
  val = analogRead(ultraAn);    // read the value from the sensor
  Serial.println(val);           // print the value to the serial port   
  dist = (val/9.77);          // converts the analog value to distance in inches
  Serial.println(dist);         // prints the distance in inches   
  delay (2000);                // delays 2 secconds in between readings
}

and it send me data through the serial link like this:
Quote
103

10

33

3

102

10

1001

102

997

102

998

102

999

102

1001

102

but those values were definitely no accurate, so any help would be great. Thanks
Hell, there are no rules here—we're
   trying to accomplish something.

                                                                              —Thomas Edison

Offline Brandon121233Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 320
  • Helpful? 0
  • "Genius is %1 inspiration and %99 perspiration"
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #1 on: April 12, 2007, 10:18:36 PM »
sorry i looked into it for a couple of hours and I think I answered my own question, I needed to convert the analogRead into the actual voltage value instead of the 0-1024 value it was, now its working pretty well. Now that thats working, does anyone know like a link that would point me in the right direction for determining the distance with the TX pin which the data sheet says:
Quote
TX – Delivers asynchronous serial with an RS232 format,
except voltages are 0-Vcc. The output is an ASCII
capital “R”, followed by three ASCII character digits
representing the range in inches up to a maximum of
255, followed by a carriage return (ASCII 13). The
baud rate is 9600, 8 bits, no parity, with one stop bit.
Although the voltage of 0-Vcc is outside the RS232
standard, most RS232 devices have sufficient margin
to read 0-Vcc serial data. If standard voltage level
RS232 is desired, invert, and connect an RS232
converter such as a MAX232.

can anyone help me with the pseudo code of how to retrieve the ACSII characters from the arduino?
Hell, there are no rules here—we're
   trying to accomplish something.

                                                                              —Thomas Edison

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #2 on: April 13, 2007, 02:07:07 AM »
so i have never used the arduino but micro controllers tend to have a UART (or sometimes USART) port.
this is just like a RS232 port (which is what the serial port on PCs and older laptops is) except RS232 ports run at higher voltage so they can be used over longer distances. to convert from the logic level on the UART to RS232 voltages you would use a chip such as the MAX232 level shifter.

so, search for pages describing the arduinos UART. if you are actually looking for circuit diagrams, try using the keyword "MAX232".

hope this gives you a starting point.

dunk.

Offline Hal9000

  • Supreme Robot
  • *****
  • Posts: 338
  • Helpful? 0
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #3 on: April 13, 2007, 03:44:57 PM »
"The truth is, you can't hide from the truth, cos the truth is all there is" - Handsome Boy Modeling School

Offline Brandon121233Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 320
  • Helpful? 0
  • "Genius is %1 inspiration and %99 perspiration"
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #4 on: April 13, 2007, 04:09:01 PM »
Yeah thanks
I was aware of the tutorials, specifically the sonar one, but that has code for the sensor that outputs ping time delays and the microcontroller counts the delay and everything, I am not aware of any tutorial on reading serial ASCII commands sent from an ultrasonic sensor. I know how to go about it basically so its not a big deal, I just didn't want to have to spend a couple of hours trying to figure it out, if someone had already done that. Thanks for your help so far-and I might have some more questions later on about this.
Hell, there are no rules here—we're
   trying to accomplish something.

                                                                              —Thomas Edison

Offline Hal9000

  • Supreme Robot
  • *****
  • Posts: 338
  • Helpful? 0
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #5 on: April 13, 2007, 04:16:13 PM »
Oh right, sorry........I guess it would have been a bit help, though!

Keep on truckin'!

And, I also have a bit of trouble grasping the rs232, so maybe not the best person to ask! soz.
"The truth is, you can't hide from the truth, cos the truth is all there is" - Handsome Boy Modeling School

Offline ekisbaiedom

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #6 on: May 28, 2007, 01:25:58 PM »
HI.

Im very new to robitics, and just trying to figure out how it works...Im trying to build an ultrasonic rangefinder for starters. I already bought some tranceducers etc. Can someone please give me a circuit and PIC code that works? The LV-MaxSonar-EZ1 circuit from their datasheet looks very easy, but I dont have code for the PIC, and I'm not quite sure where to hook up the transmitter and receiver.

Can anyone Help PLEASE?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #7 on: May 30, 2007, 08:14:23 PM »
Quote
I'm trying to use the analog output from it to measure the distance in inches.
but you arent using analog in your code, you are using serial . . .

Offline Brandon121233Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 320
  • Helpful? 0
  • "Genius is %1 inspiration and %99 perspiration"
Re: Problems with LV-MaxSonar-EZ1 code
« Reply #8 on: May 30, 2007, 09:38:29 PM »
are you replying to my question? If so I got this problem worked out about a month ago, and yes I am using analog


Code: [Select]
void loop() {
  val =analogRead(ultraAn);  // read the value from the sensor
  dist = (val/9.77);          // converts the analog value to distance in inches
}


« Last Edit: May 30, 2007, 09:39:03 PM by Brandon121233 »
Hell, there are no rules here—we're
   trying to accomplish something.

                                                                              —Thomas Edison

 


Get Your Ad Here

data_list