Shop OBEX P1 Docs P2 Docs Learn Events
Advice on using Ultrasonic Distance Sensor? — Parallax Forums

Advice on using Ultrasonic Distance Sensor?

VeritasVeritas Posts: 4
edited 2013-09-30 14:48 in General Discussion
Hey everyone,

New to the forum, new to tinkering with electronics, more specifically the "Ultrasonic Distance Sensor" and generally electrical/mechanical engineering in general. Please excuse me in advance for my ignorance with dealing with these things.

Basically I'm working in a lab and trying to figure out how to use a motion/distance sensor to make an audible "Beeping" that becomes louder and more frequent as an object gets close to the sensor. How do I accomplish this? I purchased the Ultrasonic Distance sensor today but am unsure what kind of controllers I will need to connect and how to code the device to make it perform the functions I want it to. Also, would I be able to code it to have adjustable sensitivity/range? Any help would be greatly appreciated! Thanks.

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-09-30 10:38
    Hi Veritas,

    which sort of sensor did you buy? Did you buy a PING? There is information for that here:
    http://www.parallax.com/product/28015 Click on the Downloads tab for info on that page.

    Also, what sort of microprocessor are you planning on using (Basic Stamp, Propeller, etc.)? And over what range will you be using this sensor?
  • VeritasVeritas Posts: 4
    edited 2013-09-30 10:47
    Thank you so much for your feedback, Electric.

    I purchased a PING sensor. I'm going over the downloads now. . .

    Does it matter which microprocessor I'm using? We're working with objects that will be moving within 0'-10' of the sensor. The PING Ultrasonic Sensor is capable of 0'-9' (which is fine). I'd like to use a processor that can transmit a signal to a speaker that makes the beeping noise.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-30 10:51
    Please refer to the documentation on this device. There are examples of code for the Basic Stamps and the Propeller and there are examples and libraries for use with an Arduino available on the Arduino website. The Basic Stamps can make beeps, but there's no direct way to change the volume of the sound. That can be done using a digitally controlled pot as a volume control or by generating an analog voltage used to control the gain of an amplifier. You'd use existing code to trigger the PING, time the output of the sensor to give a distance value, and use that to set both the volume value and the time to pause until the next PING reading. As the distance gets smaller, the volume value goes up and the pause time gets shorter. Details depend on your specifics. For example, you could use table lookup to produce volume values given PING readings. Similarly, you'd use a table to come up with a pause time in milliseconds given a particular PING value. The time it takes for the PING to come up with a value also depends on the distance with maximum readings (3m) taking about 20ms and minimum distance readings (2cm) about 1ms.

    Please look at the Basic Stamp Syntax and Reference Manual for information on the TONE statement for producing audible tones and the PWM statement for producing voltages.

    The Propeller can also be used and has the ability to make much more varied sounds at different volumes and tones. Here are two examples of tone generators (this and this).
  • VeritasVeritas Posts: 4
    edited 2013-09-30 10:58
    Thanks Mike. What kind of processor would I use if I wanted to transmit the output of the processor wirelessly?
  • T ChapT Chap Posts: 4,223
    edited 2013-09-30 11:06
    If you are expecting 9' reliable results from the PING I think you will be disappointed. If your object that is reflecting the sound has a nice reflective surface you may get some results at 9', but do not expect consistent results out that far.

    Once you get the PING up and running to your requirement, then you can explore the methods to change the volume. There is some simple code for the Propeller that can work to change the volume of a square wave beep, which can be sent direct from the Propeller pin to a piezo, or an amp that amplifies the signal to a speaker or piezo. You can also set the frequency of the beep to change based on the distance.

    It is fairly easy to test the results of the PING with a Prop stick or other Prop development board. You can even show the results of the distance on the Parallax LCD, I use the 2 x 16 backlit version that works well with the Prop.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-09-30 13:01
    Veritas wrote: »
    Thanks Mike. What kind of processor would I use if I wanted to transmit the output of the processor wirelessly?

    You need to specify what you mean by "wirelessly." I know that the Propeller chip is easily interfaced with an Xbee module, for example. I think the Basic Stamp works, too. Much depends on what sort of data you want to transmit, how far, etc.

    Look at the download tab on this page for the pdf of the text:
    http://www.parallax.com/product/122-32450

    There is also a Bluetooth device:
    http://www.parallax.com/product/30086

    There are also cheaper transmitter/receiver combinations that use other frequencies. These are akin to the type of radios used in garage door openers, etc. I'm guessing that for what you want to do, you have a lot of options.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-09-30 13:22
    Veritas wrote: »
    What kind of processor would I use if I wanted to transmit the output of the processor wirelessly?

    Processor doesn't matter. Easiest and cheapest is Prop + HC06 bluetooth in my opinion. HC06 allows us to use an android device running blueterm to as serial terrminal.
  • VeritasVeritas Posts: 4
    edited 2013-09-30 14:15
    You need to specify what you mean by "wirelessly." I know that the Propeller chip is easily interfaced with an Xbee module, for example. I think the Basic Stamp works, too. Much depends on what sort of data you want to transmit, how far, etc.

    Look at the download tab on this page for the pdf of the text:
    http://www.parallax.com/product/122-32450

    There is also a Bluetooth device:
    http://www.parallax.com/product/30086

    There are also cheaper transmitter/receiver combinations that use other frequencies. These are akin to the type of radios used in garage door openers, etc. I'm guessing that for what you want to do, you have a lot of options.

    This is fantastic. I think the Bluetooth device would work perfectly for my needs. So from what I understand, I need to wire the Ultrasonic Sensor to the Basic Stamp microprocessor, then wire the bluetooth device to the Basic Stamp processor board as well, then write up the code to make the sensor send a signal wirelessly to a speaker (via bluetooth) with a beeping sound that varies in volume and frequency as an object nears. . .right?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-09-30 14:48
    Veritas wrote: »
    This is fantastic. I think the Bluetooth device would work perfectly for my needs. So from what I understand, I need to wire the Ultrasonic Sensor to the Basic Stamp microprocessor, then wire the bluetooth device to the Basic Stamp processor board as well, then write up the code to make the sensor send a signal wirelessly to a speaker (via bluetooth) with a beeping sound that varies in volume and frequency as an object nears. . .right?

    It seems like a reasonable idea to me. As Braino said, the processor doesn't matter very much for something like this. You just need to keep in mind the distances you wish to wirelessly transmit. Also heed what T Chap said about the PING not providing reliable data at larger distances. What sort of surface your PING is bouncing its sound off of will also affect the sensitivity and repeatability of your measurements. Things that absorb sound or that are tilted at an angle might show up very differently than, say, a hard surface that is approaching flat toward your sensor. The best way to know, of course, is to try it out.
Sign In or Register to comment.