+ Reply to Thread
Results 1 to 16 of 16

Thread: Detect Distance with the Ping)))(TM) Ultrasonic Detector

  1. #1

    Default Detect Distance with the Ping)))(TM) Ultrasonic Detector

    What is the Ping))) Sensor?

    The Ping))) sensor is a device you can use with the BASIC Stamp to measure how far away an object is. It's measurement range is from 3 cm to 3.3 m, and it's remarkably accurate, easily detecting an object's distance down to the half centimeter.



    How Does Ping))) Work?

    Figure 2 shows how the Ping))) sensor sends a brief chirp with its ultrasonic speaker and makes it possible for the BASIC Stamp to measure how long the echo takes to return to the Ping))) sensor's ultrasonic microphone. The BASIC Stamp has to send the Ping))) sensor a pulse to begin the measurement. The Ping))) sensor then waits long enough for the BASIC Stamp program to start a PULSIN command. Then, at about the same time the Ping))) sensor chirps its 40 kHz tone, it sends a high signal to the BASIC Stamp. When the Ping))) sensor detects the echo with its ultrasonic microphone, it changes that high signal back to low. The BASIC Stamp's PULSIN command measures the time between the high and low changes, and stores it measurement in a variable. You can use this value and modify your program to use the speed of sound in air to calculate the object's distance in whatever measurement units you choose, centimeters, inches, feet, etc...




    __________________________________________________ ___________________________

    The draft material in this Topicis part of a forthcoming Stamps in Class text by Andy Lindsay.

    (c) 2005by Parallax Inc - all rights reserved.∑∑

    Post Edited By Moderator (Jessica Uelmen (Parallax)) : 8/25/2010 5:46:05 PM GMT
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	PingPicture.jpg‎
Views:	6708
Size:	49.8 KB
ID:	37329   Click image for larger version

Name:	PingConceptDiagram.jpg‎
Views:	6772
Size:	35.2 KB
ID:	37330   Click image for larger version

Name:	p529852-1.gif‎
Views:	1649
Size:	39.5 KB
ID:	73997   Click image for larger version

Name:	p529852-2.gif‎
Views:	1585
Size:	19.6 KB
ID:	73998   Click image for larger version

Name:	p529852-3.gif‎
Views:	1547
Size:	26.0 KB
ID:	73999  

    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  2. #2

    Default

    ACTIVITY #1: Measuring Echo Time

    In this activity, you will test the Ping))) sensor and verify that it gives you time measurements that correspond to the object's distance. You will also modify the example program so that it converts the echo times to cm measurements.

    Parts Required

    All you'll need is a Ping))) sensor and three jumper wires to make it work. The Ping))) sensor has protection against programming mistakes (and wiring mistakes) built-in, so there's no need to use a 220 Ω resistor between P15 and the Ping))) sensor's SIG terminal.

    (1) Ping))) Ultrasonic Distance Sensor
    (3) Jumper Wires

    Ping))) Circuit

    Figure 3 shows the schematic and wiring diagram we will use to test the Ping))) sensor.

    ÷∑∑∑∑∑∑∑ Build the circuit shown in Figure 3.



    Testing Ping)))

    As mentioned earlier, the Ping))) sensor needs a start pulse from the BASIC Stamp to begin the measurement. A pulse to P15 that lasts 10 μs (PULOUT 15, 5) is easily detected by the Ping))) sensor and only takes a small amount of time for the BASIC Stamp to send. A PULSIN command that stores the duration of a positive pulse has to come immediately after the PULSOUT command. The result that the PULSIN command stores in a variable is the round trip time for the Ping))) sensor's chirp to go to the object and back. You can then multiply this value by .03434 to convert from 2 μs PULSIN Duration units to the distance in centimeters. Activity #2 will explain how to derive this value.

    Example Program - PingTest.bs2

    In this activity, you will measure the distances of a few close-up objects, so thePing))) sensor only needs to be roughly Boe-Bot height above your working surface (8 to 10 cm). If you are measuring objects that are more than 30 cm away, keep your Ping))) sensor about half a meter or more above the floor.

    ÷∑∑∑∑∑∑∑ Place your Board of Education with the Ping))) sensor circuit on something to keep it at least 8 cm above the table surface.
    ÷∑∑∑∑∑∑∑ Place an object (like a water bottle, box, or paper target) 15 cm from the front of Ping.
    ÷∑∑∑∑∑∑∑ Enter, save, and run PingTest.bs2.
    ÷∑∑∑∑∑∑∑ The Debug Terminal should start reporting a value in the neighborhood of 450. Values of 438 to 466 means the distance is between 15 and 16 cm.
    ÷∑∑∑∑∑∑∑ Move the target to a distance of 30 cm from the Ping))) sensorand verify that the value of the time variable doubled.
    ÷∑∑∑∑∑∑∑ Point your Ping))) sensorat a variety of near and far objects and see if the time values work. To convert to centimeters, multiply your time measurement by .03434. The next activity will explain how to derive this value using the speed of sound in air.

    Code:
    ' PingTest.bs2
     
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    time VAR Word
     
    DO
     
      PULSOUT 15, 5
      PULSIN 15, 1, time
      DEBUG HOME, "time = ", DEC5 time
      PAUSE 100
     
    LOOP



    Your Turn - Displaying Centimeter Measurements

    The next activity will cover how to derive values that you can use with the ** operator to convert from the PULSOUT command's Duration value to centimeters, inches, feet, etc. Here are a couple of lines you can add between PingTest.bs2's DEBUG and PAUSE commands to display the measurement in centimeters.

    time = time ** 2250
    DEBUG CR, "Distance = ", DEC4 time, " cm"

    ÷∑∑∑∑∑∑∑ Save PingTest.bs2 as PingCentimeters.bs2.
    ÷∑∑∑∑∑∑∑ Add the two lines of code to the program's DO...LOOP between the DEBUG and PAUSE commands. When you're done, it should look like this:

    DO

    PULSOUT 15, 5
    PULSIN 15, 1, time
    DEBUGHOME, "time = ", DEC5 time
    time = time ** 2250
    DEBUG CR, "Distance = ", DEC4 time, " cm"
    PAUSE 100

    LOOP

    ÷∑∑∑∑∑∑∑ Run your modified program and verify that the program correctly displays both the echo time and centimeter measurements.


    Post Edited By Moderator (Jessica Uelmen (Parallax)) : 8/25/2010 5:46:35 PM GMT
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	PingSchematicWiring.jpg‎
Views:	6663
Size:	29.0 KB
ID:	37331   Click image for larger version

Name:	p529853-1.gif‎
Views:	1768
Size:	29.0 KB
ID:	74000  
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  3. #3

    Default

    Hello..Thanks for sharing these valuable ideas ....I got a question..?

    I made toy car which goes to 8 mph.. I need to have sensors which detect obstacles and move a round them...since this speed is fast for Infrared sensors which has short range detectorto detect and send signal to servo to react...I decided to use ultra-sonic sensors but my question is I have trouble coding the ultra-sonic sensors tolet the servo react..??

    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  4. #4

    Default

    This is a project that will take some planning. The first thing you'll want to do is draw a picture of where the beams will be directed in front of your vehicle. Then, write some code and test to see how long it takes a servo to turn to each of the directions you want to check. You will then know how many times per second you can check in front of you. With that bit of information you can then decide whether you can detect the obstacles in time while traveling at 8 MPH. If the answer is yes, then there are various downloads on the Ping))) product page <http://www.parallax.com/detail.asp?product_id=28015> that you can use to get the sweeping sensor to work.

    If it turns out that the sampling rate is not sufficient for a servo sweeping a Ping))) sensor, another thing you could look into is our Ping))) 5-pack <http://www.parallax.com/detail.asp?product_id=28015-5pack>. There is a coding trick you can use to check all 5 Ping))) sensors between each servo pulse. The trick is that you will be checking to find out whether there are any objects within the threshold distance. Here is an example that checks 4 Ping))) sensors connected to P4, P5, P6, and P7 for objects a little over 1.5 M out:

    pingArray VAR Nib
    .
    .
    .
    OUTB = %1111
    DIRB = %1111
    PAUSE 1
    OUTB = %0000
    DIRB = %0000
    PAUSE 10
    pingArray = INB

    The contents of the pingArray variable will contain four bits. When the bit for a corresponding Ping))) is 0, then an object is closer than 1.5 m.

    Post Edited (Andy Lindsay (Parallax)) : 4/11/2006 7:07:56 PM GMT
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  5. #5

    Default

    How would i use the ping sensor and a bs2/prop to measure the speed of sound, in meters/second?
    Preferably a BS2.

    Thank you

    Post Edited (computer guy) : 4/3/2007 7:36:47 AM GMT
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  6. #6

    Default

    You might want to take a look at Smart Sensors and Applications, which has a chapter for the Ping))) sensor - this thread was an early draft of the beginning of that chapter. The book goes further into the way temperature affects the speed of sound, and gives a formula for the speed of sound in air at a given temperature. You can download the book here:

    http://www.parallax.com/detail.asp?product_id=28029

    There is no example program for this specifically,but if you work with a known distance I think you could calculate it.The Ping))) sensoroutputs a time measurement, which we know to be thetime it takes for an echo to emit and return. The typical distance measurement program uses thetime as avariable andthe assumed speed of sound at room temperature as a constantto calculate distance. Now, if you make the distancea constant by setting up the sensor and a target and measuring the distance with a ruler or tape, you could use this constant, and the time measurementas a "stopwatch"and measure the sound's speed.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  7. #7

    Default

    What PING)) code would you use with a faster Basic Stamp 2px?

    humanoido
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  8. #8

    Default

    The faster BS2px requires a longer PULSOUT parameter to trigger the PING. Replace the 5 in PULSOUT with 13:

    PULSOUT 15, 13 'BS2p, BS2px & BS2sx
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  9. #9

    Default

    How can I have the ping sensing some from 2 inches to 10 inches with a acuracy of 1/8 of inches
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  10. #10

    Default

    You probably can't.

    The BS2 can't do the timing to get an accuracy of 1/8". The PING))) is specified for an accuracy of 0.5cm at best which is a bit more than 1/8". You may do better using a faster Stamp like a BS2px, but it's not clear that the PING))) is capable of the stability to get that kind of accuracy.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  11. #11

    Default

    I have used the ultrasonic sensor to measure the distance from the sensor to object. It can detect the object up to 10ft far from the sensor at the hall way of LAB room,the distance result are very accurate,but it not work properly in the LAB room with many computers, lightbulbs, and router. Can you tell me what "noises" affect to the ultrasonic transducer.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  12. #12

    Default

    In the LAB room, there's LOTS of ultrasonic reflective surfaces. It's probably not electrical or optical noise affecting the transducer, but echos bouncing around all those hard surfaces.

    The solution might be to try to 'focus' either the emitter or the 'ear' sensor, perhaps with a length of heat-shrink tubing the right size.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  13. #13

    Default

    please tell me how the motion sensor light affect to the ultrasonic transducer. The ultrasonic transducer dosen't work properly in the room have motion sensors.

    Thank you for your time.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  14. #14

    Default

    The 'ping' is not affected by light -- so, if you have IR based motion sensors, they won't affect the 'ping'.

    If, on the other hand, your "motion sensor lights" are in fact ultrasonic, it might be possible for them to 'confuse' the 'ping'.

    It might help if you explained what you mean by "not working properly". Are the distances too short? Too long? Inconsistent?
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  15. #15

    Default

    Hi everyone,
    i'm looking for a code for speaker when the ultrasonic distancce sensor detects object at close range, it gives a fast and high tone, and otherwise.

    Thank you for your time.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

  16. #16

    Default

    You'll need to modify one of the existing sample programs for the PING))). The sample code shows how to read the sensor and produce a value for the distance to the nearest object detected. You'll have to test this for whatever you consider to be "close range" and generate the tone you want. The "What's a Microcontroller?" tutorial shows how to make sounds using a Stamp and a piezo-speaker. You can also read the chapter on the FREQOUT statement in the "Basic Stamp Syntax and Reference Manual". Both are included in the help files of the Stamp Editor.
    Last edited by ForumTools; 10-01-2010 at 11:43 PM. Reason: Forum Migration

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts