How can i control the voltage?

I am relatively new to arduino, and right now I'm making an application in. "Net" to control arduino UNO and I want to control the brightness of a LED but I want to do for the Arduino programming without using a potentiometer. this can be done? how? .. thanks

Use analogWrite to PWM the pin to give a voltage between 0 and 5.

Use analogWrite to PWM the pin to give a voltage between 0 and 5.

That is NOT what analogWrite does. The voltage on the pin (and only on some pins) will be either 0 or 5 (assuming a 5V Arduino). The pin is turned on and off frequently, so that some devices appear to operate at lower voltages. LEDs appear dimmer to the human eye, because of persistence of vision. The voltage on the pin appears to an oscilloscope to be a square wave. It appears to the LED to be a square wave, too. The effect of applying that square wave to an LED is that the voltage is reduced, when seen by the human eye, but not when seen by the oscilloscope.

Yeah I should have known you would call me on that, should have said something like apparent or pseudo voltage. But wtf, I'm bored with this now.

Using a capacitor and pwm you can average out a voltage , eg controlling a regulator's vout.

JimboZA:
should have said something like apparent or pseudo voltage.

This isn't a case of being pedantic. Telling someone PWM puts out a variable voltage is just flat out wrong.

A PWM pin puts out just that, a pulse-width modulated signal which allows you to control things like the speed of a motor or brightness of a LED.

You CAN use PWM to create voltage using a RC filter, but only as a reference for something else (like an op amp buffer).