How to obtained the frequency of a signal coming through serial port

How detailed of a wave shape?
I'm guess you need at least 10 samples per wave to have a reasonable idea of the wave shape. That comes to a 1.6 MHz ADC sampling frequency.
If you want to push all that data to a PC real time, at 8 bit resolution, you need 1.6 MB/s transfer rate - one byte per data point. Well within reach of a USB connection, the limiting factors are likely to be the sending and receiving ends.
Way, way out of the realm of an Arduino. Teensy, I don't know. RPi can handle the data rate but will need an external ADC to sample the signal.

In short that idea will not work on the Uno because of the Nyquist criterion.

Thank you, @johnerrington
Could you please suggest an Arduino board that I can use to observe the frequency variations of the signal? Also, the signal has a frequency of 500 kHz instead of 166 kHz, as shown in the figure below. Thank you


.

You COULD use an F-V converter; however then you wont see the wave shape.

Alternatively you could measure the frequency, but you would need to condition the signal to match a digital input. (post #16)

Would you care to share that circuit? (post #18)

How can you display a 500kHz signal with a baud rate of 100kHz?

As I said before an Uno or Nano can happily measure those frequencies, as long as the amplitude is within range. I've done over ten times that.

Use the signal as clock source; count the ticks for a period of time; calculate frequency.

Hello @wvmarle .
Could you please elaborate it a little more. for example what do you mean by using the signal as a clock source?

I am new in Arduino, so need a little more explanation.

Thank you

Full explanation and details of Timer1 settings you can find in the ATmega328p datasheet, chapter 15, page 89.
The clock source is explained in chapter 16, page 113.

The OP has never yet been clear about their requirements, nor about the source of the "signal" thats maybe 150k or 500k.

Of course as you say you can measure the frequency of a constant signal with a uno or nano, as it only requires 2 samples per period.
Getting the wave shape isnt so straightforward, especially if the shape or frequency vary, dpepending on the bandwidth and required accuracy.
Displaying it in real time adds another dimension.

Hello everyone.
I designed a pressure sensor. The pressure sensor is connected to interfacing circuit, which is basically Opamp circuit. The interfacing circuit (opamp) output is connected to the oscilloscope, as shown below. As I bring close my finger to the sensor its waveform width as well as frequency is get changed, which I wanted, as shown in Figure 1. The sensor operating frequency is 166kHz. (An improved version is also designed which is operating at 500kHz).
image
Figure 1

The parameter which I needed is operating frequency and waveform, which is visible with oscilloscope. However, now my target is to replace the oscilloscope with Arduino. My initial setup is:
image
Figure 2.

In the above Figure, the interfacing circuit output is going in Arduino pin A0. I wrote few lines simple code to read analog pin A0 as:

unsigned long runcount = 0;

void setup()

{

  Serial.begin(115200);
}

void loop() {
  
    float val = analogRead(A0);
    float Voltage = val * (5.0 / 1023.0);
    Serial.println(Voltage);
    micros();
}

The data coming through serial monitor, which is in the form of 0,0.1,0.2,.. 0.4. Then I used processing to record the data for 1 minute. A mobile stop watch was used for 1 minute time, the processing was manually stopped as one minute is completed on mobile stopwatch. The recorded data is drawn in the MATLAB which is giving half peaks as:

Figure3: All data drawn in the MATLAB.


Figure 4: zoomed view of section from 0 to 0.7 of the above figure 3.

In the zoomed view, I noticed that the waveform is not matching with the oscilloscope (look like half wave). I used findpeak function in the mutable and find all peaks in the figure 3. Then divide the number of peaks by 60 (as the collected data was for 1 minuet) which is giving to me 80.14Hz. This is look to me incorrect, I am trying to correct my code by reading blogs, but I could not figure it out. Any suggestion or guideline will be highly apricated. I am at beginner level in the Arduino, so will need a little more detail. Thank you.

For this to work you need to sample at more than twice the highest frequency of the wave.
Any lower and you will see an "aliased" signal.
However to see the wave shape you need to sample at a MUCH higher rate.
its explained here

Your "sampling rate" is limited by the serial interface. You seem to be gatteing data of the form 0.xx which _with a delimiter etc) is 5+ characters so the data rate is less than 115000/5 = 23kHz.

To be clear the limitation is the serial interface. Basically I dont see how you can do it that way, you need to use a faster interface.
However to see anything in real time resembling the true shape for 500kHz you need to sample at or above 10MHz.

You need to think again. Or just get one of these

https://www.amazon.co.uk/Hantek-Digital-Storage-Oscilloscope-Channel/dp/B01M74UKKC?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A1Y0G7ZSK431JL

Which has been discussed in detail in the thread above. This latest post of yours makes me feel like you didn't read these replies. It also details why you can NOT do what you're trying to do with an Arduino.

This is a very advanced project.
Even the basic frequency counting that I pointed out to you I would definitely call advanced level.
Sampling and processing a 500 kHz waveform with any detail (you haven't told us ANYTHING about this waveform, how it changes and how your pressure data is encoded in it) requires something like a 5 MHz sampling rate. I call myself pretty advanced in Arduino and general electronics but I have no idea at the moment how to tackle that problem, short of buying a USB scope and do the data (waveform, frequency) processing on a PC - or maybe an RPi if you need to keep the physical size small.