Recently I ordered two sr04m-2 ultrasonic sensors. The problem is that they are showing incorrect values. Both of them are showing 200-250 cm(or 0) no matter how close I put them to wall, hand or whatever. I wired rx to trigger pin and tx to echo pin(also tried vice versa). 5V and GND to respective pins on the arduino board. I tried using NewPing library and code from internet without this library. Also tried to connect to different digital pins and set different baud rates. Red light on the sensor is flashing and I hear click sounds.
What can be the problem? Maybe they just don't work?
Thank you in advance.
Image:
You could post a few images of the project. You could post a schemo. You could let us know which MCU you are using.
You could come to understand why a mix of floats and ints not properly cast could give wonky results. Like what is .034 cast as an int?
You could add some serial prints for troubleshooting and remove them later.
Hi,
added to the post one image(new users can't add more) and information that I get from serial monitor. If problem is in data types why first code example is not working? I hope that gives you some information. Thank you.
Have you considered how the device is wired up may be an issue?
For instance, the green wire for 5V on the module goes to pin 7 on the UNO. Perhaps finding a connect guide for your ultrasonic sensor might be in order?
Is there a resistor in location R19 on your board? That will switch the board to Serial (9600 baud, 3-byte messages every 120 milliseconds) ot Low Power Serial (9600 baud, send 0x01 to receive 3-byte distance).
Hello, I added image of another side of the sensor. I have read documentation from https://www.katranji.com/tocimages/files/406377-274587.pdf https://www.jahankitshop.com/getattach.aspx?id=4635&Type=Product
And both documents say that it can work in same mode as HC-SR04 sensor.
Yes, it can. If it is configured to. Neither of those documents matches your board. I suspect the "SWIM"(?) pin on your model does something. I think you need to find a document specific to your board.
Same issue, with same hardware (with sensor from AMZ) : did anyone got an idea ?
(no resistor on R19. schema is working well with a non waterproof SR04)