AJ-SR04M board

Issue #40 resolved
Stirling Paatz created an issue

I have recently been receiving AJ-SR04M boards instead of the usual JSN devices, and these do not seem to work at all with the Newping Library (or any other library). As these seem to be increasingly widespread, it would be good to understand what needs to be changed in order to use them. It's hard to find data though, although this page has plenty in Chinese

AJ-SR04M 1.jpghttps://fr.aliexpress.com/item/AJ-SR04M-Integrated-Ultrasonic-Ranging-Module-Reversing-Radar-Waterproof-Ultrasonic-Square-Wave/32832042271.html

AJ-SR04M 2.jpg

Comments (9)

  1. Tim Eckel repo owner

    Looks like this sensor can communicate via serial or the trigger/echo method. NewPing only works via the trigger/echo method.

    Your options are either to switch the sensor to use the trigger/echo communication method or to communicate with it without NewPing via serial.

    It's out of the scope of NewPing to communicate via serial, as each sensor uses totally different communication messages. You'll need to get with the manufacture on how to switch it to use trigger/echo or how to communicate with it via serial. I don't have the sensors, nor the spec sheet, there's no possible way I could even hint on how any of this would be done.

  2. Stirling Paatz reporter

    I’ve been continuing to work on this, because I think these boards are clones of the JSN SR04-2.0, which is becoming more prevalent. (although I’ve not had one of these yet)

    According to the Chinese data that I’ve been able to translate, the board as a default operates in trigger/echo mode, and the serial method is selected by soldering in a resistor to an marked position. By default then, we ought to be able to make them work.

    It looks like the problem is not just limited to the clone boards and the JSN version 2 boards have a similar issue. One experimenter I have found, seems to have been able to achieve operation by extending the Trig pulse to 20mS.

    I will continue to experiment and let you know how I get on. If you are interested I would be happy to send you some boards

  3. Tim Eckel repo owner

    You could test this theory by changing line 134 of NewPing.cpp from:

    delayMicroseconds(10);

    to:

    delayMicroseconds(20);

  4. Tomas Kovacik

    hi

    thx for lib

    I also buy this module and changing delay to 20ms did not work for me, from datasheet, it shoud by fine way it's programed:

    MODE1 (open R19): When a Trig to a high level greater than 10us trigger signal, the module will work out a corresponding Echo pin outputs a high level, the high level time is the distance of the object Echo distance calculated by the formula: uS / 58 = Cm or uS / 148 = Inch; or: High Time * distance = velocity of sound ( 340M/ S ) / 2;

    so 10 is(should be) fine.

    but it did not work for me. So I take my scope and after connecting probes, everything start to work, so I try external pull up, internal pullup on pins ,non of this works only connected probes, then I realize probe have internal defined resistence = pulldown, so I try 4k7 pulldown (1st resistor I have on hand) and it works, maybe stronger internal pullup on module side

    module has 5 modes, 10us pulse on trigger line, 10ms puse, constance serial output, serial output after anything is send on serial to module and constant asci output.

    translated datasheet to english(by google translate):

    https://github.com/tomaskovacik/kicad-library/tree/master/library/datasheet/K02-AJ-SR04

    simple serial example:

    https://github.com/tomaskovacik/arduino/tree/master/K02_serial_example

  5. Tim Eckel repo owner

    @tomaskovacik There's little the library can do about this. Sounds like you're saying that you added a pulldown resistor to the sensor and then it worked? If so, it sounds like a physical problem, and something software can't fix.

    Also, if you're using two pins to communicate with the sensor, you probably should be setting #define ONE_PIN_ENABLED false. Setting this value and changing the 10us pulse length to 20us may get it working. If not, it sounds like hardware.

  6. Tomas Kovacik

    hello again,

    I am avare that this is HW "problem" and SW(lib) cannot fix this, I wrote here so anyone can find solution how to use your lib.

    for the record, setting

    #define ONE_PIN_ENABLED false
    

    did not fix it, pull down on trigger is still needed.

  7. Michal Ambrož

    Hi, i get RS04M-02. It did not worked so i “debugged” the library and it seams that changing

    #define MAX_SENSOR_DELAY 500000

    in library header file works

    I am tired now to do full testing after many changes. So far its just a late night hint.

  8. Tim Eckel repo owner

    That's a setting designed to be set by the user to get unique sensors to work. It's not a bug that can be fixed and incorporated into the code, as that value would cause problems for everyone not using that sensor.

    Basically, you changing that value is exactly what you should do. But it's not a bug or something that will be included in the library.

  9. Log in to comment