Go Down

Topic: DIY Ping))) sensor (Read 1 time)previous topic - next topic

youssefaly

Jun 02, 2012, 11:15 pm
I don't have the money to buy Ping))) sensors (It ain't cheap here) but think I found a simple solution by using two piezo buzzers as sender and receiver with the "tone(pin,40000,5);" at 40khz like the original Ping))) for 5 milliseconds. the part I want is counting the time until receive so I can calculate the distance at 330m/s for sound speed here is my code please someone edit the bottom commented part for me.
Code: [Select]
`/*that sketch needs help with the commented part and it usestwo piezo buzzers each having its cathode to groung and one anode to digital pin 2 and the anode of the other to digitalpin 3 and it is used as a DIY Ping))) sensor*/int speed = 330;int time;int distance;int distanceCm;int outPin = 2;int inPin = 3;void setup(){  pinMode(outPin,OUTPUT);  pinMode(inPin,INPUT);  digitalWrite(inPin,LOW);}void loop(){  tone(outPin,40000,5);  //count time in ms until inPin is high and store it as "time"  //multiply "time" by "speed" and store it as distance in meters  //multiply "distance" by 1000 and store it to distanceCm in centimeters  //display that on a serial port or utelise it}`
Thank you

AWOL

#1
Jun 02, 2012, 11:57 pm
Your 5ms pulse is going to limit your minimum range to around one metre.
You may want to work on reducing it.

How sensitive are the devices at 40kHz, and what amplification do you have on the receiver?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johnwasser

#2
Jun 02, 2012, 11:58 pm
Perhaps this will help:
http://www.micro-examples.com/public/microex-navig/doc/090-ultrasonic-ranger.html

The code translates roughly to:

Turn on 40 kHz output for 300 microseconds (a little over 10 pulses).
Wait 600 microseconds.
Start a timer.
Stop the timer.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

jtw11

#3
Jun 02, 2012, 11:59 pmLast Edit: Jun 03, 2012, 12:01 am by jtw11 Reason: 1
Firstly, I doubt there's anybody here on the forum willing to write code for you - but will offer their advice and expertise to help you help yourself to write code, by providing help with specific problems.

So, take a look at the following Arduino page on Ping))) setups. You can pick out simple bits you need - in your code, you wish to output to serial, so you must initialize serial comms using the Serial.begin function.

http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor

For things like counting time, check the Arduino example for the 'Blink without delay' example, in there is a snippet of code which counts time.... Please ask specific questions on here, not the classic "I haven't done my homework, please do it for me"

youssefaly

#4
Jun 17, 2012, 12:29 pm
To: johnwasser
Thanks for the advice the link you posted I've visited it previously many times and I only don't know what are the speakers here, Are these buzzers? maybe, can I use buzzers or do I have to use some special transducers?, thanks again.
To: AWOL
Thanks man, do I change it down in the millisecond or the microsecond range and can you please suggest a suitable duration? I didn't know I had to use an amplifier, Can I make one using lm386, lm324 or lm339 ? I'm only worried about the distortion of the amplifier to affect the analog input and the code not having a good threshold, any way thanks.
To: jtw11
Thank you for the reply, I've read the blink without delay before but I didn't understand it, thanks

AWOL

#5
Jun 17, 2012, 12:57 pm
Murata transducers are cheap and designed for the job.
I really wouldn't advise building U/S sensors from scratch unless you have an oscilloscope.
A very poor third is build your own.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up

Please enter a valid email to subscribe