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.