Regarding giving sine wave to analogRead and viewing it on the serial plotter.

I was trying to get familiar with the serial plotter so that i can use it in future for debugging purpose. But when I give a sine wave of 1Volt amplitude and a DC offset of 500mV(to avoid negative voltage) and 50Hz. As a beginning i wrote the the following few lines as code.

void setup()
{
Serial.begin(115200);
}

void loop()
{

Serial.println(analogRead(A5));
delay(100);

}
Result obtained on the serial plotter is a constant voltage of 19. same was obtained on monitor too. What should be done to vie the sine wave on the plotter?

Sampling a 50Hz signal at somewhat less than 10 Hz?

sruthisindu:
on the serial plotter is a constant voltage of 19. same was obtained on monitor too. What should be done to vie the sine wave on the plotter?

What is "serial plotter"?

Sorry but did not get you. How do I change the sampling rate and how's it 10 Hz?

Serial plotter is a feature on Arduino available from versions 1.6.6. Real time sensor data plotting and debugging is possible using the plotter which plots the data displayed on serial monitor.

An example of Serial Plotter with an UNO (select 250000 bauds in Serial monitor):

const uint8_t sinesize = 128;
const uint8_t _sinesize = sinesize - 1;
volatile float sine[sinesize];

void setup() {

  Serial.begin(250000);

  for (uint8_t i = 0; i<sinesize; i++) {
    sine[i] = 200 * (sinf(i * 2 * PI / sinesize));
  }
}

void loop() {
  uint8_t var;
  static uint8_t i;

  delay(5);
  i = (i + 1 ) & _sinesize;       // Discard all bits above sinesize
  Serial.print((int)sine[i]);       // Print waveform


  Serial.print(" ");                // print a blanck
  var = (i + 170) & _sinesize;
  Serial.print((int)sine[var]);     // Print waveform


  Serial.print(" ");                // print a blanck
  var = (var + 170) & _sinesize;
  Serial.println((int)sine[var]);   // Println waveform

}

Hi,

OK. I haven't used it ever.

What the other forer says is that, as you delay by 100 (0.1 s), you are sampling the sin signal at the same place all the times every 5 cycles ( 5 * (1/50) = 0.1) so having the same value every time.

Try with a value not multiple of 20 (ms by cycle); 101 has to do.

Regards.

@ard_newbie: I understand what you are trying to say. To save the samples as array and then use them. But as mentioned in your program, sinesize acts as sampling frequency. But how do i divide the real time sine wave's frequency as you have done for created sine wave?. I need to use the sine wave plotted for further processing.
@vffgaston: Thank you for the tip.

how's it 10 Hz?

Serial.println(analogRead(A5));
delay(100);