Page 2 of 2

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Posted: Fri Mar 13, 2026 1:09 am
by chipfryer27
Hi

One way might be to use the Mapping Function component.

Briefly you enter expected input Min / Max values (e.g. 0-9999) and then the respective output Min / Max values that you want (e.g. 0 - 100). I have probably overcomplicated by trying to explain, but it is a very handy component and very easy to use. This may save you a lot of bother.

Regards

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Posted: Fri Mar 13, 2026 2:57 am
by mnfisher
I'm just waiting on some resistors to have a play....

In the UART modes it outputs the length as two bytes - in a 4 byte block (header, datahi, datalo, checksum) - the length is datahi * 256 + datalo

So if we catch the data to an array d[4] it would be d[1] x 256 + d[2]

The result is in mm

The exception is mode 5 (output as a string "12345mm\r\n")...

I've written an outline program - will post the code once tested...

Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component

Posted: Fri Mar 13, 2026 5:47 pm
by Matrixv8
Thank you for your help, I intend to use this in the future projects.

Regards,
Pierre