hi, im trying to read sine wave signal… i found this code by NickGammon. The code can display the sine wave signal but the sine is not smooth… how to make the adc interrupt read the signal precisely so we can calculate the phase angle of the graph. any idea to make adc read exactly the value of wave.

here the code and the result before

``````const byte adcPin = 0;
int xt=0;
void setup ()
{
Serial.begin (115200);
// set the analog reference (high two bits of ADMUX) and select the
// to 0 (the default).

}  // end of setup

{
byte low, high;

// cause the results of each conversion to be discarded,

void loop ()
{
// if last reading finished, process it
{

// do something with the reading, for example, print it
delay (100);

}

// if we aren't taking a reading, start a new one
{
// start the conversion
}

// do other stuff here

}  // end of loop
``````

Your sine wave looks "clipped", don't apply more voltage than arduino can handle. Try this: http://coolarduino.wordpress.com/2013/01/09/audio-vu-meter/

It is your hardware that is the problem not the software. What input circuit do you have?

Grumpy_Mike, the output voltage to arduino pin0 is 2VAC, i also put voltage bias +2.5V.

2 V rms or 2 V peak to peak?

2 V rms or 2 V peak to peak?

2Vrms… it come from transformer after i step down to 2vac.

What you get is exactly right. It is what you should get. A voltage of 2V RMS is 5.6V peak to peak so you will see clipping top and bottom. You divide the reading by four so 255 will be the maximum you see, so what is the problem? If you want it not to clip then don't put so much voltage in. If you want the full range of the A/D then fon't divide it by four.

ooo...so the result i get is correct.. so i need to step down more the voltage input to get the smooth sine wave right? beside that any idea how can i calculate the frequency of the wave.

Yes a lower input. For frequency count the number of samples between successive peaks and multiply that by the sample interval. Then take the reciprocal of that number to give the frequency.