hi there
I m trying to read analog singnal voltage by arduino board.
Let's sat i want to read sinusoidal signal of 50Hz from function generator.
I have used this sketch
void setup() {
Serial.begin(9600);
}
void loop() {
// read the analog input into a variable:
int analogValue = analogRead(0);
// print the result:
Serial.println(analogValue);
// wait 10 milliseconds for the analog-to-digital converter
// to settle after the last reading:
delay(10);
}
This code is working but it displays mostly values 0 and 1024
so whenever i tried to reconstruct this signal it displays triangular wave
instead of sine wave
What should i do??????
any help will be appreciated
Don't put a delay in the built in A/D will go at a much faster rate.
Also don't print inside the loop, that takes a different amount of time for each sample as the number consists of a different number of digits.
Try reading the samples into an array for so many samples and then print them out to see your sin wave.
for (int count=0; count <= 199; count++){ // reads 200 values for waveform
ctpinvalue[count] = analogRead(ctPin); // Pin 0 Current transformer
delayMicroseconds(50);
} // end of count loop
Since I'm in a good mood here's code lifted out of one of my sketches that measuures 50hz AC. No print statements, thats done in an entirely seperate lump of code.
It ultimately produces this graph, which varies between a beautiful sine wave and a spikey mess depending on load and power factor etc :
Its approximately 2 cycles which equates to about a 25th of a second......
hey mike its still not working
i am trying apply 50hz signal from function generator with peak to peak value of 5volt.i have connect one terminal to analog pin specified in the program and ground to analog reference.i have also try this with increase in baudrate to 38400.wht should i do ??
can we print this values serially?