3

What I aim to do: To measure the frequency of an AC analog signal generated by an electrodynamic shaker, which has a peak voltage of 10V-- using an Arduino Uno.

What I have tried: Tried using a circuit similar to an optocoupler (using a 2N2222) transistor to take pulse input, using the pulsein() function. However the duration is always returning as 0.

My questions:

  • Is this method an acceptable way of measuring frequency?
  • What could I be doing wrong such that the time duration is always returning 0?
  • Is there an easier way of carrying out this work?

Will put up the code if asked for. However it is basically just defining a few variables (for pins, duration etc), and then using the pulsein function.

Here is the image of the circuit diagram

chicks
2274 silver badges10 bronze badges
asked May 7, 2019 at 6:26
5
  • Please provide a schematics or wiring, how you have the signal connected to the Arduino. What form does the signal have? Are you doing some preprocessing, or do you simply rely on the Schmitt Trigger inside the digital input of the Arduino? Commented May 7, 2019 at 6:50
  • I have added the circuit diagram. I'm not using a Schmitt trigger since my professor has explained to me that the circuit I am using will convert the AC signal to pulses, which can be read by the digital input pins of the Arduino. However, I do admit I am not an electronics engineer, so my knowledge about this is quite limited. Commented May 7, 2019 at 6:57
  • Try adding a resistor between base and emitter of the transistor to pull the base to ground, when the phototransistor of the optocoupler is not conducting. That should keep the transistor base from floating. Though it is only a guess, that this is a problem. Can you observe the signal and the output of the circuit with an oscilloscope? Commented May 7, 2019 at 7:04
  • The output, as shown, goes to the Arduino digital pin. I looked at the input signal to ensure it is indeed sinusoidal. However I have not looked at the output. I will do so. Thank you for your input! Commented May 7, 2019 at 9:22
  • 1. Why the transistor? The optocoupler already includes a (photo-)transistor, so why add another one? 2. pulseIn() measures the length of a pulse, i.e. the time between a rising edge and the following falling edge (or vice-versa). For measuring a frequency, you need the time between two consecutive rising (or falling) edges. 3. What is the range of frequencies you want to measure? What kind of accuracy do you need? There are many methods to measure a frequency, and the "right" one for you depends on your requirements. Commented May 9, 2019 at 9:01

2 Answers 2

2

This project includes a frequency counter.

https://www.instructables.com/id/Oscilloscope-in-a-Matchbox-Arduino/

From the project page: This oscilloscope costs the price of an Arduino Nano (2ドル and a display (3ドル) plus a few pence for resistors, etc. It's specification is:

  • max 1M samples/second, min 1000sps
  • 8-bits per sample
  • DC 0-5V; AC +/- 550mV, AC +/- 117mV, AC +/- 25mV
  • USB "PC scope" or built-in display
  • could be battery-powered
  • optional logic display
  • optional frequency meter
  • optional voltmeter
  • optional signal generator

My comment: I build it, it's a nice little project and the author is an expert programmer.

answered May 7, 2019 at 12:10
1
  • 1
    Answers should be more selfcontaining. A link-only answer would get completely useless, when the link dies eventually. Please include the key points directly in the answer text. Commented May 12, 2019 at 12:29
0

Is this method an acceptable way of measuring frequency?

Nope, not at all.

What could I be doing wrong such that the time duration is always returning 0?

You are misusing pulsein(), it doesn't work like that; look up the documentation for it!

Is there an easier way of carrying out this work?

Yes; there are many ways, you can research many of them. One thing you can do is make a peak detector, either in hardware or software, and then design a way to get a counts/time, which should correlate to the frequency!

answered May 16, 2019 at 23:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.