Hi there.
I am using MB7092 XL-MaxSonar. it works only with rs232. Provides also analog but the precision with arduino would be very bad.
I was surprised nobody appear to have been able to use this sensor with rs232, I mean to get the usable integer out of it !
The code given by Piano_man didn't work for me. Or any other code, excepted the code for wiewing only on computer IDE screen serial that works, but as soon as I try to modify it to get something out of it, I am jammed with RRRR and other bad stuff.
I contacted MaxSonar customer aftersales, they gave me the link to this post.
After days of fighting hard...
I found the way to do it and code that really works !!! yeah !!! (above)
Things to know :
1/ sofwareserial is not a real serial, it's a virtual serial. And it doesn't obey well or at all normally (as hardware serial).
Something like
if (sonarSerial.available()
doesn't work, or not properly. and it doesn't behave like the hardware serial too.
so forget all these !
source :
http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.LibrairieSerialSoftware2/ arduino nano I was working on has only 1 serial hardware . So I started on arduino mega 2560.
3/ rs232 from sensor have inverted logic, and no way to invert mega's serial logic. Then I purchased a IC : 74HC14 it contains 6 inverting with Schmitt function (Schmitt probably not necessary, but I found only this in the neighboorhood) it works perfectly. + on arduino's 5V and - to the ground. pin 5 from sensor to an input, and related output to pin 17, that is the hardware dedicated RX2 on this mega.
Reasult :
finally it works perfectly, you even don't need to convert into an int, because you get it already as an int !!!
So you need :
-one arduino that have several hardware serial ports
-signal inverting device (IC)
-my code

)
even don't need a library...
Have fun !
// Copyright (C) 2019 by Francois Regnault and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//READ MaxSonar 7092 sensor on rs232, arduino mega 2560
// readings from MaxSonar 7092 are first inverted using an IC 74HC14 (inverted logic from rs232 MaxSonar)
// Mega have several hardware pins . here, use of RX2 : input pin 17
int g;
void setup() {
// initialize serial:
Serial2.begin(9600);
Serial.begin(9600);
}
void loop() {
Serial.println("loop");
if (Serial2.available() > 0) {
g=Serial2.parseInt();
Serial.print(" mesure= "); Serial.println(g);
}
}