Hello, I'm just starting with the arduino and I'm still trying to figure out the analogWrite and PWM functions.
I need to output voltages ranging from 0V-5V with 0.5V increments. Can I use the analogWrite function to output an analog voltage. How is this different from the PWM output?
For example in the code below I am trying to supply a voltage of 1V for 10000 ms and then turn the voltage off for 5000 ms and then supply a voltage of 1.5V all the way up till 5V.
int muscle = 10; // the PWM pin the muscle is attached to
// the setup routine runs once when you press reset:
void setup() {
Serial.begin (9600);
// declare pin 10 to be an output:
pinMode(muscle, OUTPUT);
}
void loop() {
for (int inputVoltage = 51; inputVoltage <= 255; inputVoltage = inputVoltage + 51)
{
//turn muscle pin on:
analogWrite (muscle,inputVoltage);
delay (10000);
//turn the muscle pin off:
analogWrite (muscle,0);
delay (5000);
}
}