user45907: I'm working on a bigger project, and needs to give out a voltages between 0 and 5V. I've written this code:
int ledPin = 12;      // LED connected to digital pin 

void setup(){
pinMode(ledPin, OUTPUT);   // sets the pin as output
}

void loop(){
analogWrite(ledPin, 255);
delay(2000);
analogWrite(ledPin, 0);
delay(2000);
analogWrite(ledPin, 127);
delay(2000);
analogWrite(ledPin, 128);
delay(2000);
}

If I've understood it right, this should first give about 5V, then 0V, then 2.5V and againg 2.5V. However my voltmeter only reads 5V and 0V, 2 seconds at each. I've attached my voltmeter to pin 12 and ground. The arduino board is also grounded. 

user42539: The PWM pins output a square wave from 0 to 5V. If you want something more like a DC level, then run the signal thru a Resistor-Capacitor (RC) Lowpass filter.
1K and 10uF should work well to smooth the squarewave.
http://sim.okawa-denshi.jp/en/CRtool.php
On an Uno, pins 3,5,6,9,10,11 are the PWM pins and output at a frequency of ~ 490 Hz or 980 Hz, with a duty cycle from 1 to 254. 0 is full off, 255 full on. 

user337: Most Arduino boards do not have true analog output that can produce voltage range. To check if a particular board has true analog output check the specs and look for pins labeled DAC or Digital-to-analog converter.  Be aware that the supported voltage range will vary depending on the board.
The analogWrite() function uses Pulse Width Modulation to simulate analog output.
If you need true analog output you will need to attach a Digital to Analog Converter(DAC) to the arduino. e.g. https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial
UPDATE: 
If your goal is to drive a motor with a SN754410 you should be able to use the PWM analog output to drive it at varying speeds.  Here is an example: http://web.ics.purdue.edu/~fwinkler/616/sn754410_Arduino.pdf

45907: <p>I'm working on a bigger project, and needs to give out a voltages between 0 and 5V. I've written this code:</p>

<pre><code>int ledPin = 12;      // LED connected to digital pin 

void setup(){
pinMode(ledPin, OUTPUT);   // sets the pin as output
}

void loop(){
analogWrite(ledPin, 255);
delay(2000);
analogWrite(ledPin, 0);
delay(2000);
analogWrite(ledPin, 127);
delay(2000);
analogWrite(ledPin, 128);
delay(2000);
}
</code></pre>

<p>If I've understood it right, this should first give about 5V, then 0V, then 2.5V and againg 2.5V. However my voltmeter only reads 5V and 0V, 2 seconds at each. I've attached my voltmeter to pin 12 and ground. The arduino board is also grounded. </p>
 42539: <p>The PWM pins output a square wave from 0 to 5V. If you want something more like a DC level, then run the signal thru a Resistor-Capacitor (RC) Lowpass filter.
1K and 10uF should work well to smooth the squarewave.
<a href="http://sim.okawa-denshi.jp/en/CRtool.php" rel="nofollow noreferrer">http://sim.okawa-denshi.jp/en/CRtool.php</a></p>

<p>On an Uno, pins 3,5,6,9,10,11 are the PWM pins and output at a frequency of ~ 490 Hz or 980 Hz, with a duty cycle from 1 to 254. 0 is full off, 255 full on. </p>
 337: <p>Most Arduino boards do not have true analog output that can produce voltage range. To check if a particular board has true analog output check the specs and look for pins labeled DAC or Digital-to-analog converter.  Be aware that the supported voltage range will vary depending on the board.</p>

<p>The analogWrite() function uses <a href="https://www.arduino.cc/en/Tutorial/PWM" rel="nofollow noreferrer">Pulse Width Modulation</a> to simulate analog output.</p>

<p>If you need true analog output you will need to attach a Digital to Analog Converter(DAC) to the arduino. e.g. <a href="https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial" rel="nofollow noreferrer">https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial</a></p>

<p>UPDATE: 
If your goal is to drive a motor with a <a href="http://www.ti.com/lit/ds/symlink/sn754410.pdf" rel="nofollow noreferrer">SN754410</a> you should be able to use the PWM analog output to drive it at varying speeds.  Here is an example: <a href="http://web.ics.purdue.edu/~fwinkler/616/sn754410_Arduino.pdf" rel="nofollow noreferrer">http://web.ics.purdue.edu/~fwinkler/616/sn754410_Arduino.pdf</a></p>
