Go Down

Topic: Wrong analogRead values (Read 1 time) previous topic - next topic

gmbroh

Feb 13, 2013, 11:04 pm Last Edit: Feb 14, 2013, 08:41 am by gmbroh Reason: 1
I am trying to measure the voltage of an 5volt AC rectified voltage at 65Hz. Using the UNO R3 Below is the current code.




Code: [Select]
const int numReadings = 25;
int ac_input[numReadings];
const int analogInPin = A0;//Pin for input for AC voltage     
float ac_output = 0;   
int index = 0;

void setup()

{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  for (int thisReading = 0; thisReading < numReadings; thisReading ++)
    ac_input[thisReading] = 0;
}

void loop()

{
  ac_input[index]= analogRead(analogInPin);
  ac_output = ((ac_input[index]/1023.0)*5.0);                             
  Serial.println(ac_output); 
  delay(2);
  index = index + 1;

  if (index >=numReadings)
    index =0;

}




The problem is that the output on the serial monitor only shows the peak values of the voltage. That is from 4-5v instead of zero.

5
4.98
5
5
4.95
4.62
4.27
4.26
5
4.93
4.7
4.58
5
4.79
5
5
4.35
4.53
5
5
5
4.91
4.84
4.52
5
5
4.67
4.54
5
4.69
5
5
4.43
4.32
5
4.92
5
5


I have tried changing the board I'm using aswell as the input pin.

Has anyone experienced anything similar ?

AWOL

Have a look at this thread
http://arduino.cc/forum/index.php/topic,144195.msg1084872.html#msg1084872

Please use code tags when posting code.

Code: [Select]
for (int thisReading = 0; thisReading < numReadings; thisReading ++)
    ac_input[thisReading] = 0;
they're already zero; this is pointless.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

What are you expecting exactly?  A 65 Hz signal would have a period of 15 mS, and you have a 2 mS delay between readings. What is your circuit?

PeterH


I am trying to measure the voltage of an 5volt AC rectified voltage at 65Hz


How have you connected the Arduino to the source?

Where does the rectified signal come from - is it possible that it includes some smoothing?
I only provide help via the forum - please do not contact me for private consultancy.

michinyon

The phrase "5 volt rectified AC voltage"  is gibberish.   

If you have rectified it,  it isn't an AC voltage.  The electron flow is no longer alternating in direction.

You will expect to see a DC voltage with a voltage ripple.  Which is exactly what you are getting.
Depending on the type of rectifier,  you will see 65 Hz or 130 Hz ripple.    I can't tell from your
sampling rate, exactly which you are getting.

Your DC voltage has a peak of 5 volts and a minimum of about 4.5 volts.  That is exactly what you
are getting.

Go Up