Write a value as output and read it as input is not working

I am trying to write a value as output using 1 pin and read it using another pin:
1 - I write 3.0V, using pin 9 (PWM). When I read it using an external voltmeter, I get 3,0V, so it is OK.
2 - I connect pin 9 to Pin A0 (Grounds are connected too). If I read it using an external voltmeter, I get 3,0V, oK!
3 - When I try to read the value of pin A0 with arduino, the value is zero or 4.88V.

What is Wrong?

Leo.

LeoR7:
I am trying to write a value as output using 1 pin and read it using another pin:
1 - I write 3.0V, using pin 9 (PWM). When I read it using an external voltmeter, I get 3,0V, so it is OK.
2 - I connect pin 9 to Pin A0 (Grounds are connected too). If I read it using an external voltmeter, I get 3,0V, oK!
3 - When I try to read the value of pin A0 with arduino, the value is zero or 4.88V.

What is Wrong?

Leo.

Nothing is wrong. The external voltmeter is seeing the average voltage of the PWM.
The analogue pin is seeing either the high or low of the PWM waveform, without any smoothing/averaging.

I see... So, what is the frequency of this output? How can I read the raw data?

LeoR7:
I see... So, what is the frequency of this output? How can I read the raw data?

The frequency for PWM on pin 9 is 490Hz.

By raw data, do you mean the duty-cycle?
You could use an RC filter, then measure it as an analogue voltage. That would still have some ripple on it though, unless you used a fair-sized capacitor.
Otherwise, you'd need to do it by measuring pulse-lengths.

LeoR7:
I am trying to write a value as output using 1 pin and read it using another pin

I write 3.0V, using pin 9 (PWM).

Why do you want to measure PWM when you already know what it is.

You can't write 3volt, because most Arduinos don't have a D/A converter.
AnalogWrite creates a PWM signal.

Tell us what you want to do.
Leo..

10K and 4.7uF work well. Here's a series of outputs writing PWM in increments of 25.

What I want to do is very simple:
I want to write an output of variable voltage like Vout = 2+2 Sin(.5 t), where t is the time, so I have a sinusoidal signal.
At the same time, I want to read this sign using a different pin, so I can compare what is in and what is out. This is just for testing, as I am a beginner.

I have the output in pin 9 and the input in pin A0.

By the way, I am using Mathematica to read and write.

LeoR7:
What I want to do is very simple:
I want to write an output of variable voltage like Vout = 2+2 Sin(.5 t), where t is the time, so I have a sinusoidal signal.
At the same time, I want to read this sign using a different pin, so I can compare what is in and what is out. This is just for testing, as I am a beginner.

I have the output in pin 9 and the input in pin A0.

By the way, I am using Mathematica to read and write.

What frequency sine wave do you want to generate?

Edit: Have a look here:-
Arduino DDS Sinewave Generator

I want to generate any sine wave, let´s say, 1 Hz. I would like to output the sine wave and read it, but what I get is a noisy reading...

CrossRoads:
10K and 4.7uF work well. Here's a series of outputs writing PWM in increments of 25.

Nice!!! How did you do it, with Arduino?

That's an Arduino, using an RC filter with a 10K resistor and 4.7uF cap.
If you only want a crude sine-wave, you can do it directly with an Arduino. I thought you might have wanted a reasonable quality audio frequency sine-wave.
You'd get reasonably good results by controlling a 10-bit DAC with an Arduino.

Is that 130.5 milli-Hertz on the scope? You don't want to rush things with that setup.

Yes, simple for loop, something like this

void setup(){
pinMode (9, OUTPUT);
}
void loop(){
  for (byte x=0; x<251; x=x+25){
  analogWrite (9, x);
  delay(25); // or some amount
  }
}

I don't know what the frequency was, was just checking out the filtering.

How would look like the circuit for this kind of measurement? I am just connecting ground to ground and pin 9 to pin A0.

10k resistor between the PWM pin and the anaolgue pin, and a 4.7uF (or 10uF) cap from A0 to ground.
The RC filter smooths digital PWM to an analogue voltage that the A/D converter can read.
Leo..

Great!! I could read it satisfactorily!! Take a look at picture.
Issues:

  1. There is a shift in voltage value. My output is set to 1.50V, but the reading is 1.465V using Arduino or a Voltmeter. Is it expected?
  2. In the picture, we see the filter with one 22uF capacitor and other filter with 47uF capacitor. What is the limit for the capacitor? Should I use a bigger one and have "zero noise"?

You can never get to zero noise. A bigger capacitor will reduce the ripple but the tradeoff is that it will be slower to change to the next voltage. See the picture posted earlier. That's an extremely slow waveform but you can still see the transitions aren't instant - it takes a little while to get to the next value.

LeoR7:

  1. There is a shift in voltage value. My output is set to 1.50V, but the reading is 1.465V using Arduino or a Voltmeter. Is it expected?
  2. In the picture, we see the filter with one 22uF capacitor and other filter with 47uF capacitor. What is the limit for the capacitor? Should I use a bigger one and have "zero noise"?
  1. 8-bit PWM = 256 steps. Every step is 1/256 of the supply voltage. ~19.5mV per step on a 5volt Arduino.
    Supply could be 5volt, but it could also be 4.75volt or 5.25volt (is within specs of the onboard regulator).
    USB supply could be worse. Supply could also have some hash on it.

  2. No limit. Settle time will increase with larger value caps.
    A two-stage filter can be used. R-C-R-C
    Leo..