NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

teckel:
Are you using an ATmega microcontroller or something else?

The only time that NewPing sets the trigger pin to high is for 10 microseconds to initiate the sensor. If the ONE_PIN_ENABLED value is set to true, it then sets the trigger pin to input mode, which is why I suggested setting this to false if you're using two pins anyway.

The last thing I'd try is adding the following two lines right before the "class NewPing {" line in NewPing.h:

#undef DO_BITWISE

#define DO_BITWISE false




This will force it to use Arduino commands instead of bitwise logic on the pins. This would especially be required if not using an AVR ATmega microcontroller.

If this doesn't work, there's probably no way for me to help without having your exact hardware to duplicate it. 

Tim

Hi Tim.

Yesterday I received new hardware (JSN-SR04T-2.0) and now it works. I just had to set the parameter "ONE_PIN_ENABLED to false" ...
Nevertheless, many thanks for your help.

However, I have another question: I currently calculate the distance in the following way:
duration = sonar.ping ();
distance = ((duration / 2) * 0.03435);
Result e.g. 233,34cm

If I measure the distance in the following way:
float distance = (sonar.ping_cm ());
then I get another result, e.g. 238cm at the same measuring distance.
Yes, in the first variant, the temperature and the humidity affect the result, but the result of the second variant is closer to the true measuring distance (237 cm). Why?

Can you explain me how the distance is calculated with "(sonar.ping_cm ())"?

Best regards
Martin