# What is the ASCII code an ultrasonic sensor will output?

In summary, the problem statement is about determining the ASCII code for a certain distance (0.15 meters or 0.5 feet) from an ultrasonic sensor (MB7380) with 8 data bits, no parity, and one stop bit. The datasheet for the sensor provides that the output is an ASCII capital "R" followed by four ASCII character digits representing the range in millimeters. However, there was initial confusion about the conversion process, but with the help of other forums and careful reading of the datasheet, a solution was achieved. The code provided shows how the output can be emulated using an Arduino program.

Problem statement
For an ultrasonic sensor (MB7380) sending 8 data BITS, no parity and one stop bit, what is the ASCII code it will give for a certain distance like 0.15 meters (0.5')?

Attempt at a solution
• I do not know how to convert 0.15 meters into 8 bits. It is using TTL serial output. I believe this model is the 5' version.
• I'm thinking I need to borrow a scope from my uni.
• ASCII Encoder/ Decoder (tool)

I seriously doubt that the output is in ASCII. It is probably an 8 bit representation of some dustance unit of measure.

phinds
FactChecker said:
I seriously doubt that the output is in ASCII. It is probably an 8 bit representation of some dustance unit of measure.
Yep. @adamaero you really need to look at the spec sheet for the device.

Also, you clearly don't understand what "ASCII code" means or you would not have asked the question, so you might want to study up on that as well if you are interested in computer communication.

"The output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters." Talk about reading the datasheet!

I had trouble interpreting how to convert that. For example, I did not know that "\r" would be 13 in ASCII. (I would've taken both characters separately.) But I was actually helped on a different forum. Thanks, but no thanks.

"The output is an ASCII capital “R”, followed by four ASCII character digits representing the range in millimeters." Talk about reading the datasheet!
Would have been nice if you had said so in the first place. The clear implication of your question was that it was a binary 8-bit output as FactChecker suggested.

Last edited:
But I was actually helped on a different forum.
Why did you mark your thread Solved here before you got any replies? Is it because you got a reply on a different forum? You didn't reply to my personal message to you about it before any replies appeared in this thread... Just curious.

Because with the partial help of another forum, I was going to post the complete solution to what I am doing (i.e., writing an Arduino program to emulate this sensor) . . .

Nice!

C:
void setup() {

Serial.begin(9600); // bps ~ baud rate
delay(50);
}

void loop() {
Serial.write("R0030");  // 30 mm = 1.2" = 0.1'
Serial.write('\r');     // "\r" (stop bit) carriage return
delay(60000);         // takes a minute to show on graph

Serial.write("R0061");  // 0.2 feet
Serial.write(0x0d);     // hex
delay(60000);
Serial.write("R0091");  // 0.3 feet
Serial.write(13);       // ASCII
delay(60000);
Serial.write("R0122");  // 0.4 feet
Serial.write(13);
delay(60000);
Serial.write("R0152");  // 0.5 feet
Serial.write(13);
delay(60000);
Serial.write("R0183");  // 0.6 feet
Serial.write(13);
delay(60000);
Serial.write("R0213");  // 0.7 feet
Serial.write(13);
Serial.end();
}

And from there it depends on the datalogger's logic settings for the correct distances to be displayed...

Last edited: