One-Buck Ultrasonic Sensor

1235»

Comments

  • ercoerco Posts: 18,410
    edited March 2014 Vote Up0Vote Down
    Martin_H wrote: »
    Let's not forget that the cheapo sensors are missing the Ping)))'s most important feature. The LED that blinks when it is actively sensing! Besides being fun the LED has spared me time debugging when I simply had the Ping))) connected to the wrong pin.

    LED, shmell -ED. Tracy Allen recently pointed out that the PING's hardware timeout is 20 ms, whereas this cheap sensor's is much longer. That's critical for refreshing servos every 20 ms when there is nothing for the sensor to detect: http://forums.parallax.com/showthread.php/153735-Pulsin-Timeout-and-HC-SR04-problems?p=1244702&viewfull=1#post1244702

    Further, Tracy shares a clever RC workaround to force a shorter timeout when using these cheap sensors.
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • ercoerco Posts: 18,410
    edited August 2014 Vote Up0Vote Down
    Down to $1.15 now: http://www.ebay.com/itm/New-Arduino-Ultrasonic-Module-HC-SR04-Distance-Sensor-Measuring-Transducer-HE-/400756229697

    I should have waited! Now renaming the thread to "One Buck" .
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Ken GraceyKen Gracey Posts: 6,044
    edited August 2014 Vote Up0Vote Down
    http://en.wikipedia.org/wiki/Caveat_emptor

    Buy the Ping))) and it'll work with all of our tutorials and examples without any consideration to wiring or code. And you'll have a warranty on replacement even if you blow it up.

    Remember, your hobby time is limited and it's valuable too. After you carve out your job, time for family, cleaning the house and paying bills you have your hobby so make that time effective by using the best hardware you can buy.

    Ken Gracey
  • ercoerco Posts: 18,410
    edited August 2014 Vote Up0Vote Down
    No argument there, Ken!

    Another PING plus (which Parallax should promote more IMO) is that Tracy Allen tested and noted that the PING's timeout (i.e., nothing detected) is a tad under 20 seconds, which makes it perfect for supporting the 20 ms refresh rate for CR servos. The dollar sensors' timeout is longer than 20 ms and will cause servo stutter.
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Ken GraceyKen Gracey Posts: 6,044
    edited August 2014 Vote Up0Vote Down
    erco wrote: »
    No argument there, Ken!

    Another PING plus (which Parallax should promote more IMO) is that Tracy Allen tested and noted that the PING's timeout (i.e., nothing detected) is a tad under 20 seconds, which makes it perfect for supporting the 20 ms refresh rate for CR servos. The dollar sensors' timeout is longer than 20 ms and will cause servo stutter.

    I didn't know this, but now I shall bring this detail to the surface!

    Can you point me to Tracy's link? Maybe I'll be so lucky to find an oscilloscope screen shot or some proof I can use for an Insider post.

    Ken Gracey
  • ercoerco Posts: 18,410
    edited August 2014 Vote Up0Vote Down
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Hal AlbachHal Albach Posts: 677
    edited November 2014 Vote Up0Vote Down
    I finally succumbed to ordering a 10 pack of these HC-SR04 ultrasonic modules. Ordered them on Oct 30 and they arrived Nov 6th, free shipping and a total cost of $12.58. I did not expect to see them before Thanksgiving. Using a BS2 program I tested each of them and found 2 that would not return a distance even though I could hear both pinging. Looked closely at the SMD parts and found one resistor skewed so that only one end was actually soldered down. Using a toothpick I gently nudged all the parts and one of the transistors, a 1F, popped off completely. I carefully soldered the parts back on and that module is now working fine. The other one had no visible problems and all the SMD's were tight. Chalking that up as a DOA. BTW, has anyone else noticed that two of the three IC's have their ID info sanded off?
    I then set about setting them up to only require one I/O pin. With the BS2 it was easy using the setup on one of Erco's earlier posts. I/O pin direct to the Trigger and a 1.8K resister between Trigger and Echo. Worked like a charm. I found that I could use a resistor as high as 3.3K without any problems. When I went for 4.7K all I got were zeros.
    Then I turned to making these units use 1 pin from the Propeller, since the bot I'm building will have 5 of these for obstacle avoidance. Using the circuit provided by Alex Stanfield in post # 108 I was successful in mating the propeller to the SR04 with one pin. When I looked at the pin with my scope I saw that the Echo part of the signal was barely making it to 2 Volts, so I reduced the 10K resistor to 3.3K and now the Echo shows 3 Volts. I tried various objects at various distances and always received a good, steady reading. The program I'm using is C with simpleide. I just included ping.h and used the function call;
    cmDist = ping_cm(10);
    and display the data on an LCD. I'm including a pic of the scope trace, vertical is 1 Volt/div and horizontal is 0.5 ms/div. The trigger pulse is barely visible at the left and the positive pulse is the Echo from an object 50 cm away.
    I also quickly fabricated a prototype mount for the pingers out of wood. Used a small sheet of 1/4" poplar board, cut two 5/8" slots about half an inch down and rounded out the bottom with a Dremel drum sander. Then glued a base to it so I can screw it down on the bot.
    EDIT: Taking a closer look at the scope measurements it appears that after the 10us trigger pulse there is about a 450us delay before the Echo pin goes high to start the measurement, seems like plenty of time to get the I/O pin into input mode.



    2014-11-09 17.26.36.jpg
    2014-11-09 17.37.27.jpg
    2014-11-09 17.40.19.jpg
    1024 x 1024 - 129K
    1024 x 1024 - 99K
    1024 x 1024 - 114K
    Florida, between St. Petersburg and the Gulf of Mexico

    Do not look directly into laser with remaining good eye...
  • ercoerco Posts: 18,410
    edited November 2014 Vote Up0Vote Down
    Great work, Hal, thanks for the very helpful info and documentation. :)
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Duane DegnDuane Degn Posts: 10,001
    edited November 2014 Vote Up0Vote Down
    Ditto to erco's thanks. Very useful information.
  • ercoerco Posts: 18,410
    edited January 2015 Vote Up0Vote Down
    Hal Albach wrote: »
    I/O pin direct to the Trigger and a 1.8K resister between Trigger and Echo. Worked like a charm. I found that I could use a resistor as high as 3.3K without any problems.

    I was beating my head against the wall earlier today hooking up two of these sensors to a PicAxe (yeah, I know, serves me right). I assumed Hal's resistor range was OK for all processors. I didn't have any 1.8K resistors, so I used 2.2K. My rapid-fire sonar readings were mostly good, but at least once per second, there was a hiccup and the sensor returned a maximum timeout reading, which glitched my servos badly. Wasted an hour trying different code routines, then I swapped resistors to 1.7K (1.5K + 220R) and all was right with my data stream again.

    Note to self: buy some 1.8K resistors for that drawerful of ultrasonic sensors!

    Note to self #2: "Drawerful" blows spell check's mind. Use it daily to confound the computer network and possibly stave off Judgment day for another year or two.
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • RDL2004RDL2004 Posts: 2,554
    edited January 2015 Vote Up0Vote Down
    erco wrote: »
    Note to self #2: "Drawerful" blows spell check's mind. Use it daily to confound the computer network and possibly stave off Judgment day for another year or two.

    Wow, I would have bet money that "drawerful" was incorrectly spelled (my spell checker doesn't like it either), but I checked and that is indeed the right way to spell it.
    - Rick
  • mindrobotsmindrobots Posts: 6,488
    edited January 2015 Vote Up0Vote Down
    Interesting response to the varied resistor values by a different processor.
    erco wrote: »

    Note to self #2: "Drawerful" blows spell check's mind. Use it daily to confound the computer network and possibly stave off Judgment day for another year or two.

    More interesting response to "drawerful" - Firefox doesn't like it, Word doesn't like it but my iPhone has no problem with it and Pages has no problem with it.

    Firefox does accept "dwarfer" while both Apple products support the political correctness of discussing vertically challenged people with proper terms by rejecting that word.

    Just more junk food for thought!
    MOV OUTA, PEACE <div>Rick </div><div>"I've stopped using programming languages with Garbage Collection, they keep deleting my source code!!"</div>
  • mkeydiluffymkeydiluffy Posts: 4
    edited February 2015 Vote Up0Vote Down
    Thanks for your help. I bought the HY-SRF05 sensor, below I put the code I've tried and it work quite well .

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' HY-SR05 ultrasonic sensor mode 1 usage
    ' P11 to trigger
    ' P10 echo


    DO
    Range VAR Word ' define the 16 bit range variable
    LOW 11 ' start with pin low
    PULSOUT 11, 10 ' issue 10uS trigger pulse (5 x 2uS)
    PULSIN 10, 1, Range ' measure echo time
    Range = Range/29 ' convert to cm (divide by 29)

    DEBUG HOME, "distancia = ", DEC5 Range ,"cm"
    PAUSE 100
    LOOP


    I hope someone will be helpful
  • ercoerco Posts: 18,410
    edited February 2015 Vote Up0Vote Down
    Welcome, mkeydiluffy. Glad to hear you got it working in standard 2-pin mode. Now try the one-pin mode, put a 1.8K resistor between trigger and echo, and use one I/O pin to trigger. Save a pin every chance you get!
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • macrobeakmacrobeak Posts: 193
    edited February 2015 Vote Up0Vote Down
    Erco,
    While you are sourcing and investigating ultrasonic sensors, don't forget to look for cheap underwater sensor devices!
    There seem to be many expensive closed source ultrasonic underwater sensors but I have not come across any cheap open source devices like the air based PING/SR02 etc
  • ercoerco Posts: 18,410
    edited February 2015 Vote Up0Vote Down
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • mkeydiluffymkeydiluffy Posts: 4
    edited February 2015 Vote Up0Vote Down
    erco wrote: »
    Welcome, mkeydiluffy. Glad to hear you got it working in standard 2-pin mode. Now try the one-pin mode, put a 1.8K resistor between trigger and echo, and use one I/O pin to trigger. Save a pin every chance you get!

    Thx for you message, i will do it this afternoon, is a good advice for to use only one pin I/O. Sorry for my english writing im spanish and try to write myself without the help translator.

    One question, how i connect a resistor between trigger and echo? if in the connection of the mode 1, i see that the pin echo has to be free.
    Maybe the infomation of conexion about the mode 1 it not be good. I connect Vcc +5v, trigger pin I/O, echo whitout connection, OUT Vss(0v) and GND too.
  • ErnestErnest Posts: 1
    edited April 2015 Vote Up0Vote Down
    Hello,
    there are a lot of different versions of extremely cheap „rebuilds“ of the HC-SR04 from china.
    They all have the same arrangement of piezo-transmitter, piezo-receiver and connectors.
    They differ in R's, C's and their placements on the board. Some even don't have a quartz.
    But the most important difference is the firmware, the program in the microcontroller.
    Most of these versions are working. In our project with schools we got three lots.
    a) 15 pieces with an error in the firmware using a "never-ending polling for a never coming echo"
    b) 20 pieces (no quartz ) with absolutely unsufficent sensivity and
    c) 20 pieces for 0.98 EUR = 1.05 $ per piece (without separate transistors on board) working properly.

    Lot a) After sending the ultrasonic bursts to an object outside the detection range they wait in an endless loop for a response and ignore further triggers. A first way out is a short metallic tap to the receiver. Then short distances could be measured until you have a too far object . . . .
    A curious strategy may cure this erroneous behavior: When there is no answer before timeout, then switch off the power for the HC-SR04 and repower it after a short delay.
    My modifications: Connect the Vcc-pin of the sensor with the collector of an additional pnp-Transistor. Connect the emitter of this transistor with the 5V of the arduino board and the base of this transistor via an 1k resistor to an additional controlPin. LOW at the controlPin switches the power on, HIGH switches off. A short HIGH pulse by a digitalWrite( controlPin, HIGH ) directly followed by a digitalWrite( controlPin, LOW ) is enough to reset the ultrasonic sensor. This reset must be done whenever the output of the functions ping() or pulseIn() is 0.
    So this software initiated hardware reset ends the infinite polling of the firmware in the controller.
    This strategy was successful for 14 sensors. The 15th needed a delay(1).

    Lot b) These sensors were not able to detect a reflected signal from a hand in 35 cm distance.
    The maximum distance of a hard reflecting medium was about 120 cm. I suppose unsufficient correlation between transmitted frequence and bandpass frequence due to tolerances of the used chip capacitors. The result of my analysis will be presented later.
    Of course the low price will limit my amount of time for modifications.
  • mkeydiluffymkeydiluffy Posts: 4
    edited May 2015 Vote Up0Vote Down
    Ernest wrote: »
    Hello,
    there are a lot of different versions of extremely cheap „rebuilds“ of the HC-SR04 from china.
    They all have the same arrangement of piezo-transmitter, piezo-receiver and connectors.
    They differ in R's, C's and their placements on the board. Some even don't have a quartz.
    But the most important difference is the firmware, the program in the microcontroller.
    Most of these versions are working. In our project with schools we got three lots.
    a) 15 pieces with an error in the firmware using a "never-ending polling for a never coming echo"
    b) 20 pieces (no quartz ) with absolutely unsufficent sensivity and
    c) 20 pieces for 0.98 EUR = 1.05 $ per piece (without separate transistors on board) working properly.

    Lot a) After sending the ultrasonic bursts to an object outside the detection range they wait in an endless loop for a response and ignore further triggers. A first way out is a short metallic tap to the receiver. Then short distances could be measured until you have a too far object . . . .
    A curious strategy may cure this erroneous behavior: When there is no answer before timeout, then switch off the power for the HC-SR04 and repower it after a short delay.
    My modifications: Connect the Vcc-pin of the sensor with the collector of an additional pnp-Transistor. Connect the emitter of this transistor with the 5V of the arduino board and the base of this transistor via an 1k resistor to an additional controlPin. LOW at the controlPin switches the power on, HIGH switches off. A short HIGH pulse by a digitalWrite( controlPin, HIGH ) directly followed by a digitalWrite( controlPin, LOW ) is enough to reset the ultrasonic sensor. This reset must be done whenever the output of the functions ping() or pulseIn() is 0.
    So this software initiated hardware reset ends the infinite polling of the firmware in the controller.
    This strategy was successful for 14 sensors. The 15th needed a delay(1).

    Lot b) These sensors were not able to detect a reflected signal from a hand in 35 cm distance.
    The maximum distance of a hard reflecting medium was about 120 cm. I suppose unsufficient correlation between transmitted frequence and bandpass frequence due to tolerances of the used chip capacitors. The result of my analysis will be presented later.
    Of course the low price will limit my amount of time for modifications.

    Hello Ernest, thanks for you comment. Can you answer me some question?, How you connect the sensors? in mode 1 or 2?, and which programming language do you use?.

    I wait your answer. Thanks again
  • "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • My Local inporter has them in stock in Chicago. $2.10 each

    I don't know how they can make this stuff so cheap.

    http://www.valuehobby.com/arduino-and-cnc/ultrasonic-ranging-module-hc-sr04.html

  • ercoerco Posts: 18,410
    edited October 2015 Vote Up0Vote Down
    jdolecki wrote: »
    I don't know how they can make this stuff so cheap.

    I'm pretty sure they are factory seconds, maybe failed QC tests. Quality and range vary widely. I have modified many for 1-pin use. Some are OK, some (maybe 20%) just don't work at all. I just toss them, it's not worth troubleshooting. Hmmm... diet coke or two ultrasonic sensors? Tough call some days!

    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • ercoerco Posts: 18,410
    A 5-pack of sensors for $4.19, less than a 6-pack of PBR. Each providing a different and necessary kind of fun.

    http://www.ebay.com/itm/5pcs-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor-for-Arduino/301877065006



    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • xanaduxanadu Posts: 3,102
    edited August 12 Vote Up0Vote Down
    I have a couple of the waterproof version - http://www.ebay.com/itm/Ultrasonic-Module-Distance-Measuring-Transducer-Sensor-Waterproof-JSN-SR04T/262136734027

    Has anyone tried the 2.0?

    I have some of the non-waterproof and they work great. The operating parameters are similar. The waterproof won't return an echo pulse.

  • According to this page the 2.0 requires a pullup on TX/echo.

    http://artofcircuits.com/product/jsn-sr04t-2-0-water-proof-ultrasonic-module-distance-measuring-sensor

    All is well :)
  • xanaduxanadu Posts: 3,102
    edited August 12 Vote Up0Vote Down
    FYI the trimpot on the board is to calibrate the distance measured. Maybe not, it seemed to work for a couple of mm. I wonder if it adjusts the modulation to eliminate crosstalk between modules.
  • ercoerco Posts: 18,410
    edited September 2 Vote Up0Vote Down
    New self-contained $14 module with LED display (0-400cm) and adjustable min/max trigger output signals.

    http://www.ebay.com/itm/New-Ultrasonic-Motion-Detector-Sensor-Module-Security-Non-contact-Display-Board-/261432834516

    s-l500.jpg
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
Sign In or Register to comment.