I'm trying to create a code using an Arduino Uno board to increment and decrement the output voltage of the Arduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below.
The things that are missing on the schematic are two buttons. I want to be able to increment 0.5 volts with each press of Button-A until the Arduino is at 5 volts. With Button-B I want to be able to lower the voltage by 0.5 volts with each press of the button till value is 0.
I can do the calculations and the circuit design but I'm not much of a programmer. I just want to know if anyone can point me in a good direction of where I can get the right code. I have already looked at all the tutorials on the Arduino Website. I do know I have to work with the PWM functions as well as attachinterrupt()
and Debounce()
functions. Also, how do I set the increments so that I don't go over, say it takes 10 presses to get to 5 volts on the 11th press have it not do anything so I don't break anything. So can anyone please help me with any suggestions?
I have a low pass filter on the circuit for noise handling and like I said I need to add in the buttons to my schematic.
simulate this circuit – Schematic created using CircuitLab
Here is my code I have made. I'm using an LED to test the Vout aspect. So far I can only get my LED to flicker from 2 to 4 volts and my buttons A and B don't work. Can someone look over my code and see how bad I made this?
int PWMPin = 6; // output pin supporting PWM
int buttonApin = 9; // buttonA to pin 9 PWM
int buttonBpin = 10; // buttonB to pin 10 PWM
float value = 0; // read the value at 0
int fadeValue = value;
void setup()
{
Serial.begin(9600); //initialize serial communication at 9600 baud
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(PWMPin, OUTPUT);
}
void loop()
{
{
int port = analogRead(0);
port = map(port, 0, 10, 0, 255);
analogWrite(6, port);
}
{
if (digitalRead(buttonApin) == LOW, fadeValue)
{
// fade from min to max in increments of 25.5 points: basically (0.5 volts)
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255):
Serial.println(PWMPin);
analogWrite(PWMPin, fadeValue);
}
}
{
if (digitalRead(buttonBpin) == LOW, fadeValue)
{
// fade from max to min in increments of 25.5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=25.5)
digitalWrite(PWMPin, fadeValue);
// sets the value (range from 0 to 255): basically (0.5 volts)
analogWrite(PWMPin, fadeValue);
}
}
}