Hello everyone. ![]()
Im working on reading a sinusoidal signal having (1V amplitude and 0.75 offset) and observing the serial values on the serial monitor. I have a separate program in Labview to graph this serial data back into its original waveform shape. I want to read sinusoidal signals starting from 10Hz up to 200Hz. I have used the following code:
int potPin = 0; // select the input pin
int val = 0; // variable to store the value coming from the function generator
void setup()
{
Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
}
void loop() {
val = analogRead(potPin); // read the value from the function generator
Serial.println(val);
delay(0.5); //Sampling rate for the signal
}
At 10Hz, the serial values are alright, for example 202, 208, 214,220.. which results in an alright sinusoid being graphed by Labview.
However, as I increase the frequency of the sinusoid to 80Hz, 100Hz, 150Hz.. The serial values no longer accurately represent the sinusoidal signal being inputted to the arduino input pin.. for example 234,330,400,600..
I have tried decreasing delay at the end of the code to increase the sampling rate, however below 0.5 serial data can no longer be seen when COM port is open.
Is there any programming method I can use to to accurately sample the sinusoidal signal and observe more precise values on the serial monitor? I have tried using an array to 'force' 500 data points to be read however the problem still occurs.
int potPin = 0; // select the input pin for the potentiometer
int ctpinvalue[500]; // variable to store the value coming from the sensor
int i = 0;
void setup()
{
Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
}
void loop()
{
for (i=0; i<=499; i = i+1) // reads 200 values for waveform
{
ctpinvalue = analogRead(potPin); // Pin 0 Current transformer
_ Serial.println(ctpinvalue*);_
_ delay(0.5);_
_ } // end of count loop*_
}
Appreciate any help from all of you


