Honestly, I just thought I would use 25 kHz because I need ultrasound to penetrate wood
So why pick a 40kHz transducer?
These things are not like loudspeakers with a roughly flat response across part of the audio spectrum - they peak massively at their resonant frequency; that's what they're designed for.
Generating 40kHz is relatively simple (a simple for loop with some padding will need a little tuning and experimentation), it just depends what else you need to be doing at the same time, but you seem to be avoiding the question.
why are you saying that i'm avoiding your question? i mean what question anyway?
what i am doing may be too simple for you so I just need to know how to generate sine wave using arduino? that's all. thank you
Are you saying that the Arduino (which doesn't need to generate a sine wave; you can prove this by switching your sig-gen to square) just needs to generate 40kHz?
You could do that with a 555 and save yourself money.
Do you need continuous 40kHz (in which case you won't be able to use full power), or do you want bursts of maximum power at a PRR of 10Hz?
No, a 555 can't generate a nice sine wave at 40kHz, but it has been repeatedly pointed out to you that you don't need a 40kHz sine wave when a 40kHz square wave will do the job just as well.
A 555 will produce a 40kHz square wave.
I just guessing here, but one of us first picked up a pair of Murata 40kHz transducers about thirty years ago and happily drove it with a 555, then an 8080, a Z80, a 6809, a 68000, a PIC and then an Arduino, and one of us didn't.
aphy:
Hi. I just want to know if it is possible to output 25 kHz sine wave using arudino Duemilanove? I will use it to drive my ultrasonic sensor. Thanks!
Did you get an answer to your original question?
Google DDS (for direct digital synthesis), NCO (numeric controlled oscillator) and read up. These are techniques that let a micro generate programmable sine waves.
The link shows a fancy filter on the output, but you can get away with a simple RC if your not too picky on bandwidth and distortion. Try it and let us know how it works.
We established that he did not want to do this at all. Well that is he did not need to do it as a square wave would do equally as well, and that it would have done him no good even if he had generated one.
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(outPin, HIGH); // sets the pin on
delayMicroseconds(25); // pauses for 25 microseconds
digitalWrite(outPin, LOW); // sets the pin off
delayMicroseconds(25); // pauses for 25 microseconds
}
will this program be ok to drive my ultrasonic transmitter?
Look at changing the PWM frequency to 40KHz. This is much better than using a loop. Otherwise you can get a NE555 to generate it for you.
Also 25uS is 25 micro seconds 10 -6 where as the delay function gets a number in milli seconds 10 -3.
Ultrasound travels through air.
Ultrasound travels through wood.
Ultrasound does NOT like to travel between air and wood (or any solid/liquid)... There's a massive accoustic mismatch leading to extremely inefficient transfer of energy between the different media. To a good approximation all the ultrasound is reflected by any surface - which is why its very useful for proximity detection.
You need a transducer as used for ultrasound scanning (used with gel to acoustically contact the surface), not one for use in air. These usually run at much higher frequencies (> 1MHz) for higher spatial resolution.
Also we've only discussed the transmitter side of things, no mention of the receiver which is the more tricky circuit.
[ for the record speed of sound in wood is about 3600 m/s (ten times faster than in air), so for a resolution of 1cm you need around 360kHz, for 1mm 3.6MHz... ]