Hi. I'm trying to output a set voltage for a specific time interval. For example, I want to output a voltage of 3V for 30 seconds and then switch it off. Should I use PWM with a low pass filter for this?
I'm fairly new with arduino and this is the code I already have.
int muscle = 10; // the PWM pin the muscle is attached to
int writeInputVoltage = 127;
// 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() {
//turn muscle pin on:
analogWrite (muscle,writeInputVoltage);
}
So in this case I get a square output wave with a 50% duty cycle and the voltage will vary between 0-5V. Is that right?
But let's say I want an output voltage of 2.5V. Then what will analogWrite function look like. Will this code work:
int muscle = 10; // the PWM pin the muscle is attached to
int muscleHeatTime = 10000;
int muscleCoolTime = 5000;
int writeInputVoltage = 127 ;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin (9600);
// declare pin 10 to be an output:
pinMode(muscle, OUTPUT);
Serial.println("What is the input voltage (0-255)? "); //Prompt User for Input
while (Serial.available()==0){ } //Wait for User Input
writeInputVoltage = Serial.parseInt(); //Read User Input
}
void loop() {
//turn muscle pin on:
analogWrite (muscle,writeInputVoltage);
delay (muscleHeatTime);
//turn the muscle pin off:
analogWrite (muscle,0);
delay (muscleCoolTime);
}