user41183: I have created a small circuit with a 220 Ohm resistor and a LED connected to PIN9 for power.
I want to measure the Voltage of the current flowing through the circuit. In order to do that I connected a bridge from between the resistor and the LED to the A3 PIN and used this code:
int ledPin=9;
int inPin=A3;
long int in=0;
float V_in=0;
int val;

void setup() {
  analogReference(DEFAULT);
  pinMode(ledPin, OUTPUT);
  pinMode(inPin, INPUT);
  Serial.begin(9600);
  }

  void loop() {
    if (Serial.available() > 0) {
      val = Serial.parseInt();

      if (val>=0 && val<=155) {
        analogWrite(ledPin, val);
        //Serial.println(val);

        for (int i=0; i<10; i++) {
          val+=5;
          analogWrite(ledPin, val);
          //Serial.println(val);

          delay(1000);
          in = analogRead(inPin);
          V_in=float(5.0)*(float(in)/float(1023));
          Serial.println(V_in);
          delay(1000);
          }

        }
        else {
          Serial.println("Dio è morto.");
          }
      } 
    }

The problem is that when I run it, with an Input of 55, I get what seams to be a random arrangement of 0s and 2.56s. While I expect a increasing sequence of numbers between 0 and 2.5.
What am I doing wrong?
I measured the Voltage on the A3 Pin using a voltimeter, and it increases every step by 0.2, exactly as expected. 
This is an output example:


user10794: The analogWrite function, despite its name, outputs PWM (pulse width modulation) which is either fully on or fully off, with varying duty cycles. If you run that through a RC network (eg. 4.7k in series and 10 µF to ground), it will smooth out the pulses and you will actually get a varying voltage.
So in your case you are measuring on or off depending on the timing. However since you are measuring between the resistor and the LED, you won't get 5V because of the voltage drop over the resistor. An LED, depending on the colour, might have a voltage drop of around 2.2V, and thus you might expect 2.8V at that junction. This is approximately what you got.


I want to measure the Voltage of the current ...

This doesn't make any sense electrically. You are either measuring the voltage (in volts) or the current (in amps). You don't measure the "voltage of the current". I suppose you mean "the voltage at that point".

Reference
Arduino functions reference:
Reference > Language > Functions > Analog io > Analogwrite 

41183: <p>I have created a small circuit with a 220 Ohm resistor and a LED connected to PIN9 for power.</p>

<p>I want to measure the Voltage of the current flowing through the circuit. In order to do that I connected a bridge from between the resistor and the LED to the A3 PIN and used this code:</p>

<pre><code>int ledPin=9;
int inPin=A3;
long int in=0;
float V_in=0;
int val;

void setup() {
  analogReference(DEFAULT);
  pinMode(ledPin, OUTPUT);
  pinMode(inPin, INPUT);
  Serial.begin(9600);
  }

  void loop() {
    if (Serial.available() &gt; 0) {
      val = Serial.parseInt();

      if (val&gt;=0 &amp;&amp; val&lt;=155) {
        analogWrite(ledPin, val);
        //Serial.println(val);

        for (int i=0; i&lt;10; i++) {
          val+=5;
          analogWrite(ledPin, val);
          //Serial.println(val);

          delay(1000);
          in = analogRead(inPin);
          V_in=float(5.0)*(float(in)/float(1023));
          Serial.println(V_in);
          delay(1000);
          }

        }
        else {
          Serial.println("Dio è morto.");
          }
      } 
    }
</code></pre>

<p><strong>The problem is that when I run it, with an Input of 55, I get what seams to be a random arrangement of 0s and 2.56s. While I expect a increasing sequence of numbers between 0 and 2.5.</strong></p>

<p><strong>What am I doing wrong?</strong></p>

<p>I measured the Voltage on the A3 Pin using a voltimeter, and it increases every step by 0.2, exactly as expected. </p>

<p>This is an output example:</p>

<p><a href="https://i.stack.imgur.com/R4aga.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R4aga.png" alt="example"></a></p>
 10794: <p>The <code>analogWrite</code> function, despite its name, outputs PWM (pulse width modulation) which is either fully on or fully off, with varying duty cycles. If you run that through a RC network (eg. 4.7k in series and 10 µF to ground), it will smooth out the pulses and you will actually get a varying voltage.</p>

<p>So in your case you are measuring on or off depending on the timing. However since you are measuring between the resistor and the LED, you won't get 5V because of the voltage drop over the resistor. An LED, depending on the colour, might have a voltage drop of around 2.2V, and thus you might expect 2.8V at that junction. This is approximately what you got.</p>

<hr>

<blockquote>
  <p>I want to measure the Voltage of the current ...</p>
</blockquote>

<p>This doesn't make any sense electrically. You are either measuring the voltage (in volts) or the current (in amps). You don't measure the "voltage of the current". I suppose you mean "the voltage at that point".</p>

<hr>

<h3>Reference</h3>

<p>Arduino functions reference:</p>

<p><a href="https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/" rel="nofollow noreferrer">Reference > Language > Functions > Analog io > Analogwrite </a></p>
