Pages: [1]   Go Down
Author Topic: DIY Ping))) sensor  (Read 693 times)
0 Members and 1 Guest are viewing this topic.
Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*that sketch needs help with the commented part and it uses
two piezo buzzers each having its cathode to groung and one
anode to digital pin 2 and the anode of the other to digital
pin 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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25732
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Loop until an analog input (from the receiver) goes above 0 or until the timer overflows.
Stop the timer.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
« Last Edit: June 02, 2012, 05:01:02 pm by jtw11 » Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25732
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
First choice, buy ready-made units, second choice build published design.
A very poor third is build your own.

Please don't copy thread replies as PMs.
Logged

"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.

Pages: [1]   Go Up
Jump to: