sine wave generator

@aphy
Can you explain why you want to penetrate wood ?

can 555 create nice 40 kHz sine wave? do you have any schematic? thanks

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.

(Edit: oops missed out T450 transputer)

ok thank you very much!!! :smiley:

i will try the square wave and the 555 as well.
sorry i'm just afraid to try the square wave because i'm afraid to break my sensor.

but then i guess I'll do it. thanks..

i'm just afraid to try the square wave because i'm afraid to break my sensor.

But the data sheet specifies square waves.

but one of us first picked up a pair of Murata 40kHz transducers about thirty years ago

Make that two of us :slight_smile:

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! :smiley:

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.

Here is a link to a good one http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/

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.

Did you get an answer to your original question?

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.

@grumpy mike, I've tried the square wave but How can I get 40kHz? I tried the PWM but the frequency is quite low.

int outPin = 8; // digital pin 8

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?

Yes, but at the wrong frequency.
(40kHz == 25us cycle)

oh yes. that would make it 12.5
thank you very much!!! :smiley:

You'll probably find that you need shorter delays than that (you can't have a x.5us delay anyway) to account for the overheads of "digitalWrite".

then what could be the best way to do? and amplifier for the square wave? thanks

then what could be the best way to do?

Get hold of an oscilloscope or a frequency counter, and tweak your loop times until you get closest to 40kHz.

and amplifier for the square wave?

MAX232 or similar.

to account for the overheads of "digitalWrite".

For those frequencies you might also need a look into direct port manipulation: - Arduino Reference - Arduino Reference

You must know the pin in advance, but thats not the problem I guess

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.

Just to clarify a point touched on earlier:

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

@markT: yes, that's why I i'm going to use direct contact (no air gap), i am going to use a coupling material.

@grumpyMike : I tried the PWM but I cannot change the frequency. I am new to arduino and the PWM (default peroid is short)

I tried the PWM but I cannot change the frequency.

Why not?
http://www.arduino.cc/playground/Code/PwmFrequency

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1152547089