Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 15, 2013, 03:10:16 pm
Try this: (Compiled but untested.)
Code:
const int numReadings = 100;
const int analogInPin = A0; 
int inputReading [numReadings];

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

void loop()
{
  for (int i = 0; i < numReadings; i++) {
    inputReading [i]= analogRead(analogInPin); // roughly 9kHz sampling
  }
 
  for (int i = 0; i < numReadings; i++) {   
    float voltage = ((inputReading[i]/1023.0)*5.0);                             
    Serial.println(voltage); 
  }
}

I tried connecting a 10k resistor as someone suggested. And it WORKED !. I uploaded your code for fun and it also works. Its a bit better than mine.... smiley-sad
2  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 14, 2013, 04:40:12 am
At first the code was working really well. All I was doing was changing the delay to get different sample rates. Please see below

Quote
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.

The chart you posted (reproduced output) shows the graph reaching zero. What are you talking about?

The chart of the reproduced output is from when the code was working but not I am not getting those values.
3  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 14, 2013, 03:49:02 am
Quote
The input to the arduino is 0 to 5volts ac  I dont understand why you think its dc.
Because your scope trace clearly shows everything above 0V.
Alternating current implies a current reversal.

At first the code was working really well. All I was doing was changing the delay to get different sample rates. Please see below
4  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 14, 2013, 02:40:36 am
I am trying to measure the voltage of an 5volt AC rectified voltage at 65Hz. Using the UNO R3 Below is the current code.

Is that full-wave or half-wave rectification?

And with or without a filter capacitor?

Lefty

It is full wave rectification without a filter capacitor.
5  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 14, 2013, 02:38:48 am
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.

The input to the arduino is 0 to 5volts ac  I dont understand why you think its dc. I have attached a print screen of the input to the arduino
6  Using Arduino / Programming Questions / Re: Wrong analogRead values on: February 14, 2013, 02:32:17 am
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?
7  Using Arduino / Programming Questions / Wrong analogRead values on: February 13, 2013, 05:04:27 pm
 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:
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 ?
8  Using Arduino / Programming Questions / Re: Help with Serial Monitor Read-Outs on: January 23, 2013, 07:54:36 am
 I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?
9  Using Arduino / Programming Questions / Re: Help with Serial Monitor Read-Outs on: January 23, 2013, 07:49:30 am
Quote
3.69<cr><lf>
Six characters, 32Hz maximum at 9600.

Sorry but I dont understand what you mean. Is even possible to read/collect/record more that 5 data points when using the ADC ?
10  Using Arduino / Programming Questions / Re: Help with Serial Monitor Read-Outs on: January 22, 2013, 08:58:57 am
Quote
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.
In what period? A week? I'm sure the Arduino is capable of more than 5 readings a week.

If the period is 5 microseconds, you may well be SOL.

Code:
   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
Isn't integer math wonderful? It is, but it probably is not what you want. Using 5.0 and 1024.0 will produce results that are closer to what you expect, I'd guess.

Quote
I have tried increasing the communication speed but that prints out gibberish
Did you change the speed in the receiver, too?

Yes I have tried changing the communication speed at the reciever end, but this is in the serial monitor. I changed the communication speed in the code and in the serial monitor to match.
11  Using Arduino / Programming Questions / Re: Help with Serial Monitor Read-Outs on: January 22, 2013, 08:56:50 am
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

That's no help at all. Let me ask it another way: How long is the 'cycle' or 'period' in milliseconds?

I am working a frequency range of 0 to 60 Hz. at 10Hz for example the period is 0.1 second. Does that help ?

This is the type of data from the serial monitor. I would like to see more values in-between each period.
5
4.03
2.43
5
4.79
2.82
5
5
2.95
3.9
5
3.36
2.51
5
3.69
2.25
5
3.99
2.41
5
4.78
2.81
5
5
2.92
3.93
5
3.36
2.54
5
3.67
2.24
5
3.98
2.4
5
4.77

I have attached the input and output data.
12  Using Arduino / Programming Questions / Re: Help with Serial Monitor Read-Outs on: January 22, 2013, 06:18:40 am
Thank you on the note on about the delay. When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.
13  Using Arduino / Programming Questions / Help with Serial Monitor Read-Outs on: January 22, 2013, 03:04:19 am
I am working on a project to read ac voltages using the Arduino Uno R3.

I would like to increase the number of read-outs on the serial monitor as at the moment I get about five values in each cycle.

I have tried increasing the communication speed but that prints out gibberish
I have also tried changing the delay which doesnt affect the number of reading serial monitor prints out.

Below is my current code.

    const float analogInPin = A0; 
    //const float analogOutPin = A5;
    float sensorValue = 0;       
    float voltage = 0;       
    float sensor = 0;

    void setup()

 {
   Serial.begin(9600); // initialize serial communications at 9600 bps
 }

   void loop()

{
   sensor = analogRead(0);
   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
   //outputValue = map(voltage, 0, 1023);
  //analogWrite(analogOutPin, voltage);
   Serial.print("AC Voltage = " );                       
   Serial.println(voltage);   

   delay(3.125*0.000001);                   
}
Pages: [1]