Hi again!. I have another problem with my recently program. The program works perfectly, but after minutes of ejecution all result are zero, why? could it be the WatchDog??? i mean, no more pings, no more results, no more measurement.
If I want to use the one-pin method, do I need a resistor between the 2 pins, I read elsewhere that people were doing that.
Second question: How do I get it to display/record beyond the nearest cm? I see that rounding is supposed to be off by default, but my measured distances always come out to the nearest cm.
If I want to use the one-pin method, do I need a resistor between the 2 pins, I read elsewhere that people were doing that.
Second question: How do I get it to display/record beyond the nearest cm? I see that rounding is supposed to be off by default, but my measured distances always come out to the nearest cm.
Only some sensors would need the capacitor. It's a capacitor, not a resistor. A resistor would be a BAD idea! This is all spelled out at the top of example single pin sketch, see the comments at the top of the sketch:
You're confusing rounding and truncating. If you're using the ping_cm() method, you'll always get a result that's in integers. The difference is if it truncates (default) or rounds. The censors are not accurate to fractions of a CM, and using floating point math greatly slows down the Arduino and uses far more programming space. So, all the math in NewPing is with integers. If you really want to do a fraction of a CM (which won't be anymore accurate anyway) you need to use the ping() method and then apply your own floating point math to convert the speed of sound to fractions of a CM.
This isn't done in the library as it would be pointless and make it slower and use more memory. But, if you really want to waste speed and memory, by all means do the floating point math. Be ready to find out there's a debate on the speed of sound, so that's another margin of error thrown in. Then, be ready to add a temperature sensor and add that value to your computation as that's also part of the equation for the speed of sound. Or, just use the ping_cm() method that's built-in, faster, uses less memory, and is just as accurate in the end. Your choice...
Can someone please help me with the code ? Please ? I want that a buzzer should be activated when distance is less than 50, with NewPing. The if function . Please help .
nityoday:
Can someone please help me with the code ? Please ? I want that a buzzer should be activated when distance is less than 50, with NewPing. The if function . Please help .
If you're asking for a programmer to contract to write you a program, maybe try a local college. There's probably a student who would write this for you and build the circuit for not much money. If you're asking here to get it for free, what's the point? All the fun is designing the circuit and writing the program. We wouldn't want you to miss out on all the fun!
But in general, there's really not much to write. You can easily use my example code to get a distance in CM. Then a simple
would do it. If this is beyond you, I'd suggest learning to program (and this would be a VERY simple first program), or using the above suggestion of finding a student going to college that would be build it for you for probably just a few bucks (college kids always need beer money).
So are you specifically talking about using NewPing with the 15 sensor sketch example? That's something new you didn't mention in your first post, something that TOTALLY changes the answer too!
First of all, you should read the warning at the top of the 15 sensor sketch. This is where I try to talk you out of using it. Basically, if you don't know what it's doing, and you don't know what timer it's using, it's probably outside your pay grade and maybe you should stick with something simple and easy first. If you're read the warning, and fully understand the programming paradigm in the 15 sensor sketch, then you should already know the answer to your question!
If you need some help with the 15 sensor sketch, maybe you should try the link in the index of that page which is labeled "Help with 15 Sensors Sketch". That would seem the obvious place you would go if you wanted help with the 15 sensor sketch, but maybe I'm just too close to it to understand the confusion.
Also, please heed the warning that I put in bold for the 15 sensor sketch:
This sketch is designed for seasoned programming experts, don't use unless you really know what you're doing!
Basically, no assistance will be given, because if you're a seasoned programmer you don't need to ask, and if you're not a seasoned programmer, you shouldn't be using it.
Also, if you read the entire page (from the top) that you posted, you'll have your answer. May I suggest doing a search for "timer" on that page to see if the very page you were on when you had a question was discussed (hint, "timer" is mentioned 83 times on the page that you referenced).
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?
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).
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.
/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"
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:
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.
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.
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:
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.
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
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.