1

I bought this waterproof ultrasonic sensor about 5 of them with the part number SR04M-2 Written on the PCB silkscreen Which is different from the usual SR04t-0.2, they are just not working, I don't know if its using a different communication protocol or its faulty because no output is coming out of the sensor at all. if anyone out there has ever came across this type and was able to walk his/her way around it should help

3
  • compare the datasheets for the two devices ... which part of your question is about the Arduino? – jsotola Oct 26 '20 at 9:56
  • Am using arduino to communicate with the sensor and its not working – Jephtah Jephtah Oct 26 '20 at 10:46
  • there is no information about the arduino in your post ... actually, there is no question being asked ... please add relevant information, such as the sensor datasheet, the connection diagram, the arduino sketch, the description of the expected behavior and the observed behavior, and the question that you want answered – jsotola Oct 26 '20 at 10:51
3

I found this code for the SRF05 and it works for the SRO4M-2 as well. Good Luck!

const unsigned int TRIG_PIN=13; //RX
const unsigned int ECHO_PIN=12;  TX
const unsigned int BAUD_RATE=9600;

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  Serial.begin(BAUD_RATE);
}

void loop() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);  

  const unsigned long duration= pulseIn(ECHO_PIN, HIGH);
  int distance= duration/29/2;
  if(duration==0){
    Serial.println("Warning: no pulse from sensor");
  } else {
    Serial.print("distance to nearest object:");
    Serial.println(distance);
    Serial.println(" cm");
  }
  delay(100);
}
2

RX = trig and TX = Echo this is counter intuitive but it works. The manufacturer did not bother to indicate trig and echo on the PCB. I discovered this on link : https://bitbucket.org/teckel12/arduino-new-ping/issues/40/aj-sr04m-board. When I switch RX & TX as indicated in the pics it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.