Popular modules:
- The cheap: HC-SR04.
- The waterproof: JSN-SR04T.
- The capable: GY-US42V2.
- The good:
Maxbotix per purpose.
The common for all sensors: They use time of flight of sound to calculate the distance.
The difference:
- HC-SR04 uses separate transmitter and receiver tfor trigger tick and echo. Works as Triggered PWM: the microcontroller holds Echo pin up from trigger end time till echo returns.
- JSN-SR04T uses transducer to trasmit trigger and receive the echo. Waterproof transducer. The PCBA requires environmental protection.
- GY-US42V2 uses non-waterproof transducer. The "capable" title comes from its versatility. In difference with 2 modules above it can work over I2C, Serial UART, Triggered or non-triggered PWM.
- Maxbotix has every possible flavor of sensor per protocol, EMI protection and environmental sealing. Pricey and there's good reason why. :-)
The GY-US42V2 is the hardest to find information about. So the post is about it.
It took very long search
to dig out some info about the sensor.
By default, it arrives set to work over I2C. Pinout: VCC, GND, SCL, SDA.
It can work over UART serial or as regular PWM output (similar of HC-SR04). To set it to work with Serial solder central pin to H. Then pinout is: VCC, GND, RX, TX.
To set it as PWM, solder central pin to L. Then pinout is: VCC, GND, Trig, Echo.
When it's set in PWM and Trig is NOT connected, it transmits distance automatically at 50Hz, as pure PWM.
The code
examples are in the archive.
I tried to make GY-US42V2 waterproof by replacing standard transducer with waterproof transducers. None of tried transducers worked.
Observation: Modules HC-SR04, JSN-SR04T, and GY-US42V2 are sensitive to EMR. They don't work in proximity of switching power supplies. This can be seen in compact electronic design or simple under EFL lamp. So far, many attempts to use different EMI filters failed. The distant location of the module from source of EMR helps. In this case twisted and well-shielded cable is recommended for signaling.