SR04M-2 Trigger Issues (Stuck in UART)

Hi All,

I have purchased a whole batch of SR04M-2 sensors from AliExpress, I've used aj-SR04M's before and have established code for the sensors (I was expecting to have to adapt very slightly).

However I can't get the sensors to read! What ever I do the red led is flashing continuously and with an oscilloscope I can see constant data transmission on the TX line. The puzzling thing is that everything leads me to believe mode selection is the open pads to the left of the pins and that open should be manual trigger mode.

Has anyone come across these sensors and knows how to escape UART mode (presuming this is what it's stuck in)?
I would switch to UART mode but my PCBs are not set up to use serial/UART data lines!


Could you attach a USB-TTL adapter to the sensor TX (and ground) and capture the serial output to see whether the module is streaming ASCII distance frames?

I've tried the usb-ttl, doesn't seem to be uart either!
Listening on COM3 at 9600 baud...
HEX: E0 00 C0 00 DEC: 224 0 192 0
HEX: C0 00 00 FF DEC: 192 0 0 255
HEX: 00 00 FF 00 DEC: 0 0 255 0
HEX: 00 FF 00 00 DEC: 0 255 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: FF 00 C0 00 DEC: 255 0 192 0
Listening on COM3 at 4800 baud...
HEX: 00 00 80 00 DEC: 0 0 128 0
HEX: FC 00 F0 00 DEC: 252 0 240 0
HEX: F0 00 E0 00 DEC: 240 0 224 0
HEX: E0 00 F0 00 DEC: 224 0 240 0
HEX: F0 00 E0 00 DEC: 240 0 224 0
HEX: FC 00 00 FC DEC: 252 0 0 252
Listening on COM3 at 19200 baud...
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
Listening on COM3 at 38400 baud...
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0
HEX: 00 00 00 00 DEC: 0 0 0 0

Yet running this code with a new esp32 and new sr04m module I just get 0 distances.

const int trigPin = 1;
const int echoPin = 2;
const int powerPin = 3;
void setup() {
  Serial.begin(9600);
  pinMode(powerPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  digitalWrite(powerPin, HIGH);
  delay(200);
}
void loop() {
  // Send 10µs pulse on TRIG
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Measure echo pulse width
  long duration = pulseIn(echoPin, HIGH, 30000); // up to 30 ms
  // Convert to distance (in cm)
  float distance_cm = duration / 58.0;
  Serial.print("Distance: ");
  Serial.print(distance_cm);
  Serial.println(" cm");
  delay(200);
}

Board is getting power and red led flashes constantly and extremely quickly until trigger pulses are sent and then it goes blank.

1 and 3 are uart pins. And 2 is onboard LED pin.

Try pins 21, 22, 23 for example.

Continuous random bytes like in your logs strongly suggest the sensor is in UART mode but misconfigured or mismatched in baud rate. Try 115200

Just tried all the serial speeds 9600 to 115200, no joy.

Then I started wondering if perhaps its just stuck in a contact ranging mode outputting pwm as i can hear the sensor pulses constantly clicking away. Ran this code and it seems it is.

const int sensorPin = 32;

void setup() {
  Serial.begin(115200);
  pinMode(sensorPin, INPUT);
}

void loop() {
  // Measure length of the HIGH pulse in microseconds
  unsigned long pulseLength = pulseIn(sensorPin, HIGH, 30000); // 30ms timeout

  if (pulseLength == 0) {
    Serial.println("No pulse detected");
  } else {
    // Convert pulse length to cm (typical formula)
    float distance_cm = pulseLength / 58.0;

    Serial.print("Pulse: ");
    Serial.print(pulseLength);
    Serial.print(" us    Distance ~ ");
    Serial.print(distance_cm);
    Serial.println(" cm");
  }

  delay(100);
}

but this goes against most of the information on the board. my fault for purchasing a cheap generic. Any idea on whether it can be switched out of this?

Shorting the jumper on the left of the connect had zero effect. I’m starting to think its been configure like this and its not going to be changeable

Solder a 120k resistor to pad. It should set it to polling mode.

That’s weird. This reference says that the open jumper sets the “Standard Trigger Mode” and the 120k resistor sets the “Serial Port Automatic Mode”. OP’s module seems to be operating in the serial mode with the jumper opened…

I think that board has to be configured like JSN SR04T-2.0, but no-one can be sure with these...
120k resistor and uart polling with 0x55

Thanks for your reply @kmin I’m actually trying to get away from uart to the standard pulse mode. I’ve tried the 120k resistor. That does seem to put in uart mode. I’ve also tries a 300k resistor for low power pulse mode, in this mode the led flashes in time with the reading but always returns 0 results. no resistor seems to be constant reading.

I'm not sure if that model can be polled other than through uart.

The doc in post #10 says it can, and states that this sensor works just as the HC-SR04 when in this mode.

That doc also has on its last page an example sketch. Despite the PCBs, maybe it’s time to test it, at least to see if the sensors are working properly.

Must be abad batch of board I think. Switching to an Arduino Uno and the reference sketch a board with open pads does trigger as expected but the readings are all over the place +/- 30cm while the sensor is mounted in a stationary position.

Think I’m going to have to cut my losses and get some different ones

Hi, Wondering if you got the M-2 version to work? I have working SR04T and SR04M versions but get the same problem you have with the M-2. Have tried buying more but all I have received are M-2 even if the listing is different !!