Page 1 of 1
AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 2:28 am
by Matrixv8
Hi anyone, can someone help me figuring out why I am getting the same value, 9999, when I use the AJ-SR04M in Flowcode V10. The HC-SR04 component works just fine. I have change the timers and prescaler but still the same value. I have tried other new units, but still the same. Can someone help please?
Regards,
Pierre
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 8:21 am
by chipfryer27
Hi
That board appears to be able to communicate using different protocols, however without your chart we have no idea how you have setup. If you post your chart it would help, and also detail connections.
Regards
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 10:21 am
by mnfisher
The protocol does depend on the value of the link R19 - so check that?
I just got one of these in a AliExpress assortment - so will have a play....
Martin
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 8:29 pm
by mnfisher
Wired up the sensor to an Arduino - and got 9999 (error). R19 open (mode 1 HCSR04 compatible)
I added a connection to a logic analyser - and the output from the sensor looks good - there is a 'trigger' pulse - followed by an output pulse of variable length (depending on distance)
However - the output pulse occurs ~12ms after the trigger pulse and this is longer than then 10000us (10ms) allowed by the component before deciding it is an error. Looks like the sensor is a bit slower!
Therefore - the component always treats the result as an error (and never attempts to read the output pulse time)
Msrtin
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 8:36 pm
by chipfryer27
Hi
I believe medelec35 did some posts on the HC-SR04 regarding timing, so it may be worth doing a quick search for them.
Regards
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 8:44 pm
by mnfisher
The component 'attempts' to add an extra delay - delay 'type' but this is just 20us - the delay before the output pulse (on the board I have anyway) is 12.4ms
So it always 'time outs' the response.
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sat Mar 07, 2026 9:15 pm
by mnfisher
I wrote a very simple program - that sends a trigger and then waits for a return pulse. It measures this using a loop with a 58us delay - and the results look reasonable.
Note that the sensor has a minimum range of ~20cm and results go awry below this. The code here also has no time out - so if a reply never comes it will never display a distance...
Martin
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sun Mar 08, 2026 12:05 am
by Matrixv8
As usual a great thanks to your Martin and the others for your replies and work. I knew this was the problem but I was not going to change to component internal code. So the best is to look for another sensor or use a variation with a resistor on R19. I was aware of the R19 function but hopping I could avoid it. My program was already completed for the environment station I have built but the moisture was a problem with the HC-SR04
Again a great thank you for your replies and work.
Regards,
Pierre
Re: AJ-SR04M Returning 9999 while using the AJ-SR04M Component
Posted: Sun Mar 08, 2026 6:58 am
by mnfisher
The component only seems to work with the compatibility mode.
The other modes are interesting too though - I'll try and add something to the board so I can easily switch the connection at r19 and play some more....
Martin