Skip to main content
Added code formatting
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

Ardunio UNO. Coding on Incrementing How to increment and Decrementingdecrement an output voltage by using two buttons?

I'm trying to create a code using an ArdunioArduino Uno board to increment and decrement the output voltage of the ArdunioArduino 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 ArdunioArduino 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.

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);                                     
  }  
  }   
}  
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);                                     
  }  
  }   
}  

Ardunio UNO. Coding on Incrementing and Decrementing an output voltage by using two buttons

I'm trying to create a code using an Ardunio Uno board to increment and decrement the output voltage of the Ardunio 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 Ardunio 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.

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);                                     
  }  
  }   
}  

How to increment and decrement an output voltage by using two buttons?

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.

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);                                     
  }  
  }   
}  

Hello I was wondering if anyone can please help Me. I'm trying to create a code using an Ardunio UNOUno board to increment and decrement the output voltage of the Ardunio 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 Twotwo buttons. I want to be able to increment 0.5 volts with each press of Button-A until the ardunioArdunio 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()attachinterrupt() and Debounce()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. Thank you.?

HEREHere is my code I have made. I'm using an LED to test the VoutVout aspect. soSo far I can only get my LED to flicker from 2 to 4 volts and my buttons A and B don't work can. Can someone look over my code and see how bad I made this. Thank you so much for your help....

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)?

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)

   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);                                     
  }  
  }   
}  

// sets the value (range from 0 to 255): basically (0.5 volts)
analogWrite(PWMPin, fadeValue);
}
}
}

Hello I was wondering if anyone can please help Me. I'm trying to create a code using an Ardunio UNO board to increment and decrement the output voltage of the Ardunio 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 ardunio 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. Thank you.

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. Thank you so much for your help....

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);
}
}
}

I'm trying to create a code using an Ardunio Uno board to increment and decrement the output voltage of the Ardunio 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 Ardunio 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?

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);                                     
  }  
  }   
}  
Tweeted twitter.com/#!/StackArduino/status/645716952623788032
added tags and Added my code
Source Link

Hello I was wondering if anyone can please help Me. I'm trying to create a code using an Ardunio UNO board to increment and decrement the output voltage of the Ardunio 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 ardunio 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. Thank you.

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.

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. Thank you so much for your help....

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);
}
}
}

Hello I was wondering if anyone can please help Me. I'm trying to create a code using an Ardunio UNO board to increment and decrement the output voltage of the Ardunio 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 ardunio 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. Thank you.

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.

schematic

simulate this circuit – Schematic created using CircuitLab

Hello I was wondering if anyone can please help Me. I'm trying to create a code using an Ardunio UNO board to increment and decrement the output voltage of the Ardunio 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 ardunio 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. Thank you.

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.

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. Thank you so much for your help....

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);
}
}
}

Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link
Loading