Generating 40kHz pulses on pin 13

Hello everyone
I'm new to arduino

I'm trying to Generating 40kHz pulses on pin 13 to drive a 40khz transducer

I have done some reading but every time i think i have found the sketch i need
it starts branching off of the basic function & gets complicated

So if you can help make it simple

tone(13, 40000);

A direct connection will overload the pin, and may burn it out rather quickly. Use a transistor driver to prevent that.

Not that simple :grin:

I'm going to use arduino instead of the 555 timer circuit in the following photo

So arduino output on pin13 will only control the transistor

Quick question can i use the IRF9540 transistor instead of the 2N2222 ?

Screenshot_20220717-180521_Opera


An IRF9540 is a P channel MOSFET, and requires 10v Vgs to turn on.

Use as a high side switch, the IRF9540 is not a logic level MOSFET.


If we are talking about the schematic in post #5, the MOSFET will work, however, wire similar to circuit D2 below, load in the GND leg.


A 2N2222 will work and as will attaching the load to the 555 pin 3 output too.


Yes, connect Arduino pin 13 to the base resistor to get 2N2222 to turn ON/OFF.
For an Arduino, tone(13, 40000); works fine.

Thank you LarryD

I'll try it

Question
in reference to D2 circuit in your photo

can i put the load above the transistor so that the load will be connected to GND through the transistor (opposite to D2 in ur photo)?

wouldn't this lower the power going through the transistor ?

For P channel MOSFETs the Source goes to plus (positive).

You place the load on the Drain side.

If we are now talking about using a MOSFET used with an Arduino, the MOSFET needs to be a logic level type; some part numbers are shown on the schematic offered you in post #6.

If you need 12v to power the load, circuit H2 will work with the Arduino and using your MOSFET part number.


Here is another option that you can try.
2.5kHz tone for 500ms.

What is the purpose of the diode connected parallel to the load?

When the load is inductive (coils of wire such as a motor, relay or solenoid) the diode is used to absorb kickback energy when the load is turned OFF.


In your case the piezo speaker does not need this diode.

If you can use pin 9 and 10 on an Uno, and use toneAC instead of tone, then you can drive the piezo with twice the voltage (10volt peak/peak).
Leo..

If the pieco pulls more than 20 mA it should not be connected directly to the IO-pins.
Hence the transistor.

toneAC is using two IO-pins.
With this the polarity can be changed. And this is indeed like an AC-voltage.

Again: if the piezo pulls more than 20 mA it should not be connected directly to the IO-pins like shown in the schematic of ToneAC. The schematic at ToneAC has a current limiting resistor.

If the piezo must be driven with more than 20 mA ToneAC would only work in conjunction with a H-Bridge

Then it will be easier to use an external powersupply with the voltage the piezo needs and a simple transistor

What is so hard about posting a circuit that suits the application

I recommend using a transistor over an MOS-FET in this application.
Depending on the current almost any small transistor will do
50 to 80 mA. BC238, BC547 lot's of 2N-types too

300 to 800 mA BC337 or similar

MOS-FETs are very sensitive about electrostatic discharge.
Slurp over a carpet with plastic-sole-shoes which will charge your body electro-static then touch one pin of the MOS-FET for 1/100 second !BANG! MOS-FET destroyed

best regards Stefan

I'm wondering why @shopa you replied thus to @LarryD :slight_smile:

Why is that suggestion not ok for you?

Well, the circuit you posted (post#13) won't work for a piezo (which is basically a capacitor).

40kHz transmitters have AFAIK a minimum impedance at resonance of about 500ohm, so it should be fine to drive it between two Arduino pins. Can add 100ohm in series with the piezo to be sure.
Leo..

For me this is the first time working with arduino
That's why i didn't know what was @LarryD talking about

It was too short for me
But i guess it was enough for anyone familiar with arduino

But then i did some reading & understood what he wrote

It should work

Fo safty purposes
I won't use arduino to power the transducer

Instead
I'll use arduino as a signal generator to drive a suitable transistor at 40Khz
&
I'll use an external power supply to power the transducer

In this case the transducer is isolated from the arduino
Thus whatever the conditions or parameters of the transducer shouldn't matter

The only thing that does is the driving signal to switch the transistor at the required frequency

Thanks everyone

I want to pick up what user @Wawa wrote:

If the transducer is a piezo transducer electrically seen it is a capacitor.

500 Ohms means a current of

5V / 500 Ohm = 10 mA which is safe for an Arduino IO-pin
Though it might be interesting what the real current is. As driving the piezo from two IO-pins that change polarity
IO-pin 09 plus --------Transducer------- minus IO-pin 10
IO-pin 09 minus -----Transducer------- plus IO-pin 10

the suddenly reversing of the polarity causes a short peak-current.
A resistor in series with the transducer limits this peak-current

I have not read the whole datasheet of the Atmega328 so I don't know what peak-currents for how long the IO-pins can stand.

best regards Stefan