Go Down

Topic: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7 (Read 588317 times) previous topic - next topic

teckel

Hello Tim:

We are using a HC-SR04 to measure the water level in a nutrients tank.

Tank is 12.75in diameter with open top.
Depth of the tank is 15in

The HC-SR04 is installed at the top in the center of the tank
There is no obstruction of the sensor beam on 11 in diameter from the center.
Then, we have a few 3/8" poly tubes on the periphery of the tank.

Currently, we get maximum distance variation measurement of about 2" for the reading (Usually correct distance to 2" less)

I have attached the code we are using.

From your experience, can we get more stable readings from the sensor?

Thank you in advance.

Best regards,
Serge
Are the 3/8" poly tubes on the periphery of the tank above the surface? 

I would replace the ping_in() method with ping_median().  You'll get results in ping time instead of distance, but you can just use the convert_in() method to convert ping time to distance.  That way, it will throw out any echos that you may be getting from the sides of the tank (or the tubes if they're exposed to the sonar).

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

torchddv

Are you trying to read the surface of the liquid directly? I have been successfully and accurately monitoring a lake level every 15 minutes for over a year now. I have a 3" diameter piece of PVC, capped at both ends with small drilled holes at either end (to dampen any wave action) and containing a float. The sensor is at the top and reads the float. A small off-set in software corrects for the height of the float top above the actual liquid. Variation is consistently +/- 1cm.

Tauronts

Hello, I am trying to use this library to read 2 sensors
with your example of 15 sensors in Energia IDE.

Is it compatible? Any tips?

MM71

#1053
Nov 07, 2017, 12:47 am Last Edit: Nov 07, 2017, 10:37 pm by MM71 Reason: Solved
** SOLVED **

Hi there,
I keep bumping on this error..

----------------------------

/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::ping(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::ping_trigger()'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::set_max_distance(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::NewPing(unsigned char, unsigned char, unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::NewPing(unsigned char, unsigned char, unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::ping_cm(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::ping_in(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::ping_median(unsigned char, unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::convert_cm(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/libraries/NewPing/NewPing.cpp.o (symbol from plugin): In function `intFunc2':
(.text+0x0): multiple definition of `NewPing::convert_in(unsigned int)'
/var/folders/bl/mdq_ql350s345mhhnnkdp4nh0000gn/T/arduino_build_738208/sketch/NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status

----------------------------


Tried a lot of things, but nothing helped. I downloaded the NewTone lib. But how do I implement it? Do I just have to include it? Do I need to change some settings?

Please help me setting up the 3-sensor script.

** SOLVED **

SOLUTION:
In your sketch you need to include the lib as like this: #include "NewPing.h"

instead of this: #include <NewPing.h>




MM71

Now I have another problem in my 3-sensor setup. The sensors I use are HC-SR05. but they return a lot of "0"..
And strange values.. Sometimes it also returns the good value:


0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=0cm 2=190cm
0=0cm 1=0cm 2=0cm
0=0cm 1=146cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=21cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=144cm 2=0cm
0=22cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=189cm

Is it the power usage? The box says: 4.5 -> 5.5 Volts and 10 to 40 mA.

Does anyone have a proper solution?

DivinerGregg

Two wires works great on my esp32 to my hc-sr04. But when I try with one pin it doesn't work.


I define the same pin number in TRIGGER_PIN, ECHO_PIN.

I created a "y" connector to take the pinout of the esp32 into trigger and echo of the sr04.

I have NOT done any voltage conversions from 3.3 of the esp TRIGGER_PIN, ECHO_PIN .

I power the sr04 with 5v from the vcc off the esp32.

Could that be the issue? Or is it due to timers being removed off non avr chip.


teckel

Two wires works great on my esp32 to my hc-sr04. But when I try with one pin it doesn't work.


I define the same pin number in TRIGGER_PIN, ECHO_PIN.

I created a "y" connector to take the pinout of the esp32 into trigger and echo of the sr04.

I have NOT done any voltage conversions from 3.3 of the esp TRIGGER_PIN, ECHO_PIN .

I power the sr04 with 5v from the vcc off the esp32.

Could that be the issue? Or is it due to timers being removed off non avr chip.


The problem is that you're using the ESP32 and not an ATmega processor.  The one pin connection only works with certain processors and sensors.  You could try to connect capacitor between the trigger and echo pins on the sensor and then connect the microcontroller pin to the trigger side.  But, that also doesn't work with all microcontrollers.  You may need to use two pins with your setup.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

teckel

Now I have another problem in my 3-sensor setup. The sensors I use are HC-SR05. but they return a lot of "0"..
And strange values.. Sometimes it also returns the good value:


0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=145cm 2=0cm
0=0cm 1=0cm 2=190cm
0=0cm 1=0cm 2=0cm
0=0cm 1=146cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=21cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=144cm 2=0cm
0=22cm 1=0cm 2=0cm
0=0cm 1=0cm 2=0cm
0=0cm 1=0cm 2=189cm

Is it the power usage? The box says: 4.5 -> 5.5 Volts and 10 to 40 mA.

Does anyone have a proper solution?

Could be a ground issue, could be a sensor issue, could be anything.  Keep it simple if you're having a problem, use a single sensor with the example sketch.  Also, if you're having a problem, you'd need to supply what your sketch and the hardware you're using, I'd be guessing otherwise.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

AndrewsBrewing

Hello Tim,

When using a JSN-SR04T water proof sensor, its required PING_MEDIAN_DELAY is longer than the 29000 which specified in the #define statement.  This causes the sensor to ill-behaved resulting in improper operation.

If this #define constant was converted to a pre-settable value through a user command, then it would accommodate proper operation with a broader range of sensors making the library even more flexible.

Of course if no value was set by the command the default of 29000 would be used.

Might you consider this change in your next update?

Sincerely,
The Beer Drinkers at Andrews Brewing Company
Andrews, North Carolina

bombicri

I tried to use this library with Makeblock MegaPi board.
When I try to include NewPing library in Arduino IDE I received errors from the attached image.
How to solve this problem?
Thank you.
Experienced Dilettante

teckel

I tried to use this library with Makeblock MegaPi board.
When I try to include NewPing library in Arduino IDE I received errors from the attached image.
How to solve this problem?
Thank you.
Have you tried looking on the NewPing home page? There's info about vector errors. Also, I don't know what a Makeblock MegaPi board is. NewPing was designed for Arduino boards.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

teckel

Hello Tim,

When using a JSN-SR04T water proof sensor, its required PING_MEDIAN_DELAY is longer than the 29000 which specified in the #define statement.  This causes the sensor to ill-behaved resulting in improper operation.

If this #define constant was converted to a pre-settable value through a user command, then it would accommodate proper operation with a broader range of sensors making the library even more flexible.

Of course if no value was set by the command the default of 29000 would be used.

Might you consider this change in your next update?

Sincerely,
The Beer Drinkers at Andrews Brewing Company
Andrews, North Carolina
PING_MEDIAN_DELAY is a config value so you can change it if needed.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

aliocha12

I cannot get Newping (v1.9)to provide data with the sample sketches. The "distance = sonar.ping_cm(200);" command returns nothing on the serial monitor. No errors on compile.  I tried both a Leonardo and a 101, same result. The HC-sr404 works fine without the library commands. I have followed the instructions on the web to the letter. Any tips? Thanks
Alex

teckel

I cannot get Newping (v1.9)to provide data with the sample sketches. The "distance = sonar.ping_cm(200);" command returns nothing on the serial monitor. No errors on compile.  I tried both a Leonardo and a 101, same result. The HC-sr404 works fine without the library commands. I have followed the instructions on the web to the letter. Any tips? Thanks
Alex
Are you sure you matched the baud rate of the serial monitor and the baud rate set in the script?  Both must match to display values in the serial monitor.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

DanielG8

Hi there,

I'm having a problem with the 3 pin solution. I'm using the same sketch that you have in your bitbucket, and also the same code but the sensor doesn't work properly, it just prints 0 cm always. I prove the sensor with 4 pin connection and works fine. I don't understand why it doesn't work.

I'm using Arduino UNO rev 3 and a HC-SR04 sensor.

Thanks

Daniel

Go Up