Read Frequency From Circuit with PulseIn() (UNO/ESP8266)?

I have made some progress on my recent project:
High Frequency Piezo Driver

I am wanting to increase the output frequency from 1.5KHz - 2.8KHz (manufacturer specs) to somewhere around 18KHz - 20KHz, I took DVDdoug's advice suggesting that the frequency could be changed by lowering the value of the capacitor (assuming it was an RC circuit) which did work somewhat (0.1uF to 22nF) it ended up sounding like a telephone, then i swapped a 3Mohm -> 1Mohm which sounded more like a 56K modem (the second half) and finally down to a 470Kohm resistor and these all have managed to speed up the frequency a fair bit, so i think i am on the right track but now i want to be able to get a decent reading of the frequency as i change components without the piezo's connected. Obviously a scope would be the way to go but i do not have one.


I have de-soldered the piezo's and when i put 5V's to the input i was surprised to hear it making noise (i think this is now due to the transformers acting like speakers, i wasn't expecting that and spent a few seconds trying to look under the IC's for a a hidden buzzer :man_facepalming:)

So now, i can work with the circuit without having the sound on, now, i do not have a scope, and i am not sure how to connect this circuit to the line in of my sound card to use audacity (although sounds like a good option), so my main question here is:

Is it possible to use an arduino or an ESP8266 (if i need a faster clock) which i have on hand to get a rough idea of the output frequency?

I have soldered two pins onto one of the piezo outputs and have tried a simple PulseIn() sketch that counts the microSeconds between LOW->HIGH and have tried both a 3.3V and 5V supply to the board but i don't think this method is correct and have the following results:

3.3V gave around 85 microSeconds (~11,000Hz)
5V gave around 115 microSeconds (~ 8,700Hz)

  • these two values seem proportional but i am not sure why..

Is PulseIn the wrong method?
Is it a limitation of the UNO (ie clock speed)?
Is there another way?

I am just trying to use what i have on hand so i understand if i am barking up the wrong tree but just looking for some guidance..

Also, the weird thing i have noticed is that the output to the piezo's after a transistor and transformer (which i assumed would be increasing the voltage) is at 0.24V on my meter with an input voltage of 5V to the board but maybe this is a bad measurement due to the signal oscillating, can someone shed some light on this? (i thought this was a boost converter circuit?)

Thanks in advance!

More likely you have an active transducer (speaker + oscillator + driver) instead of a passive transducer (speaker)

That mixup happens constantly because the vendors never make it clear.

thanks aarg, would the driver be the transformer and transistor circuits in the image?

Perhaps I misunderstood. Did the piezos buzz when power is applied, but not attached to the board you posted a photo of? Can you post a photo of the piezo?

The piezos probably resonate at the 1-2kHz you mentioned. They won't do that at the 18-20kHz you mentioned. So they won't be nearly as loud. In fact, extremely quieter.

It might have been my rambling post, i meant that i wanted to work on the board powered up but without blowing my ears off, so i de-soldered the piezo's (just the discs) and putting power to the board (shown above) the sound could still be heard, so i assume it was the transformers (magnet, coil) and the board being used as a speaker, not sure if this is the case but surprised me.

Piezo's:

Yes, i am hoping that they do go higher but we will see!

Starting a new thread wasn't a good idea. I suggest asking a mod for a merge. Too much information is back in the previous thread.

Have you Googled the part number on the IC?

I didn't realise, you might be right, this was more of a question about reading the current frequency without piezo's connected. The hex inverter, yes, it's in the original thread..

What will that gain you?

I am adjusting the frequency by swapping components in the RC circuit and the oscillator to increase the frequency but it's loud, its in this post at the top..

Wrap them in cloth or something.

no, i mean really loud! :loudspeaker:

at random?

no not random, did you read the post (this one)?

It works only if pulses and gaps have the same duration all the time. For a single frequency value you have to measure the time from high to low, then from low to high. Such accurate timing is not guaranteed with tunable analogue frequency generators.

With hardware support there exist several ways of frequency determination:

  • measure the time from pulse to pulse
  • count the number of pulses within a fixed time interval
  • measure the time of a fixed number of pulses

The first method works well only for stable and low frequencies, i.e. not so good in your case.

The latter methods can be implemented without interrupts by counting the signal changes and calculating the frequency after some fixed time or some fixed count.

If you want to get known frequencies then you can use functions like tone() or using hardware timers. The frequency can be made dependent on some input (pot, keyboard...).

1 Like

You mean using pulseIn()? So now you have two mystery problems, the board, and how to use pulseIn()...

Since the frequency is for human ears (I think?) can't you just listen? Once you nail down the component that changes it, you can put anything you like there.

Thanks DrDiettrich, why do i get different results from my pulseIn() attempt at different voltages? I was also worried about the 3V on a pin that an arduino considers to be high, or does that work differently with the pulseIn method?

I am going to try the latter two methods now, and see if i get better results.

Because you are feeding an analog signal with a lot of harmonics, into a digital circuit.

You are making this simple task so complicated for yourself.

Analog circuits can have any dependency on voltages or other parameters.

You mean using pulseIn()? So now you have two mystery problems, the board, and how to use pulseIn()...

Since the frequency is for human ears (I think?) can't you just listen? Once you nail down the component that changes it, you can put anything you like there.

If you had read the thread you are posting on, i have mentioned that i have already had success nailing down the components to change and have changed them, and have also listened to the changes.. please read before posting

I have soldered two pins onto one of the piezo outputs and have tried a simple PulseIn() sketch that counts the microSeconds between LOW->HIGH and have tried both a 3.3V and 5V supply to the board but i don't think this method is correct and have the following results:

3.3V gave around 85 microSeconds (~11,000Hz)
5V gave around 115 microSeconds (~ 8,700Hz)

  • these two values seem proportional but i am not sure why..

so the input voltage to the exact same circuit has an effect on the output frequency then? do i have that right, the results above are the reason i was questioning whether i was using pulseIn incorrectly or was the incorrect method, i assumed only the gain would be affected with teh boost converter circuits before the piezo's..