Servo+buttons+ voltage to pins

hi all, i posted up a while ago and everyone help amazingly! thank you all.

so i am working on servo that’s activated by a button to move then return with one press when pressed, this program works great.
what i want to add is 2 more buttons that when they are pressed it sends 5v to separate Model Rocket igniters.

here is my shot at trying to add 2 more buttons, other this i have no idea where to even start?

appreciate it! thanks

So this is most likely wrong, i have what it think is adding 2 more buttons, other than that i have no idea how to tell it when they are pressed, like apply voltage to…?

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 3; 
int press2 = 0;
int button3 = 2; //button pin, connect to ground to move servo
int press3 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);

  if (press1 == LOW)
  {
    servo1.write(90);
delay(300); 
    servo1.write(0);


  }    
  
  
}

original code without 2 additional buttons

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);

  if (press1 == LOW)
  {
    servo1.write(90);
delay(300); 
    servo1.write(0);


  }    
  
  
}

Start with the blink without delay example.

Mark

did that already..

i need to know what commands i need to know, to make it work right... :~

did that already..

Not in the code you posted.

StrikeForceInd:
here is my shot at trying to add 2 more buttons, other this i have no idea where to even start?

Start by reading the state of the buttons.

and i did look at the blink program, just dont know where to put that type of info in the program..

by state you mean??

(still a noob here)

StrikeForceInd:
and i did look at the blink program, just dont know where to put that type of info in the program..

It's going to take more than just looking at it; you actually have to understand it in order to apply it.

by state you mean??

Every digital input has a state: either HIGH or LOW. You'll want to start by knowing what the states are of these two additional buttons.

Is there a particular reason why you made a new post in the Gigs and Collaboration section like your previous one? Are you looking to have somebody write the code for you?

ok here is my attempt at it, please point out my wrong doings because i got a whole errors.
more of a walk through than writing the code for me…

Here are the errors

servo_button_final:8: error: expected ',' or ';' before 'int'
servo_button_final:10: error: expected ',' or ';' before 'int'
servo_button_final:12: error: expected ',' or ';' before 'int'
servo_button_final.ino: In function 'void setup()':
servo_button_final:22: error: 'RocketLaunch2' was not declared in this scope
servo_button_final:23: error: 'servo1' was not declared in this scope
servo_button_final.ino: In function 'void loop()':
servo_button_final:32: error: 'press2' was not declared in this scope
servo_button_final:34: error: 'press2' was not declared in this scope
servo_button_final:38: error: 'press3' was not declared in this scope
servo_button_final:40: error: 'servo1' was not declared in this scope

Here is my attempt

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int RocketButton = 13 //rocket pin 1
int press2 = 0;
int RocketButton2 = 12 //rocket pin 2
int press3 = 0;
int RocketLaunch = 8
int RocketLaunch2 = 9
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(RocketButton, INPUT);
  pinMode(RocketButton2, INPUT);
  digitalWrite(5, HIGH); //enable pullups to make pin high
  digitalWrite(RocketLaunch, HIGH); //gives voltage to rocket 1
  digitalWrite(RocketLaunch2, HIGH); //give voltage to rocket 2
  servo1.attach(7);
}

void loop()
{
  press1 = digitalRead(button1);

  if (press1 == LOW)
  
  press2 = digitalRead(RocketButton);
  
  if (press2 == LOW)
  
  press2 = digitalRead(RocketButton2);
  
  if (press3 == LOW)
  {
    servo1.write(90);
delay(300); 
    servo1.write(0);


  }    
  
  
}
int RocketLaunch = 8
int RocketLaunch2 = 9

No semicolons.

servo_button_final:8: error: expected ',' or ';' before 'int'
servo_button_final:10: error: expected ',' or ';' before 'int'

Ok, fixed that issue uploaded it to the arduino and nothing worked...

Could be a good time to add some serial debug prints.

void loop()
{
  press1 = digitalRead(button1);

  if (press1 == LOW)
    press2 = digitalRead(RocketButton);
  
  if (press2 == LOW)
    press2 = digitalRead(RocketButton2);
  
  if (press3 == LOW)
  {
    servo1.write(90);
    delay(300); 
    servo1.write(0);


  }

What exactly are you trying to accomplish here? press3 is never set, so it will never change, making that if statement pointless. press2 is only set when press1 is LOW. Why are you making digitalReads conditional upon the state of another digitalRead? You should be reading the three digital pins regardless of whether what the state of the others are.

  pinMode(button1, INPUT);
  pinMode(RocketButton, INPUT);
  pinMode(RocketButton2, INPUT);
  digitalWrite(5, HIGH); //enable pullups to make pin high

Why does only 1 of your pins get the internal pull-up enabled?

int RocketLaunch = 8
int RocketLaunch2 = 9

Since digitalWrite is never used with these pins as the argument, aside from once in the setup to set them HIGH, I can't see how you would expect these ones to change. If you always want them to be HIGH, why not just connect them to the VCC and not worry about it in the code.

ok so i got 2 buttons to work now just have to add 1 more to it.

some suggestions on making the code more simple and other criticisms welcomed…

i just dont understand why the push button needed to be powered, unlike my Servo button??? is there a way i dont need this?

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int RocketFire1 =  12;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status


Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  
   // initialize the rocket1 pin as an output:
  pinMode(RocketFire1, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);     
}

void loop()
{
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(RocketFire1, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(RocketFire1, LOW); 
  }  
    
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

in my image below… see how the Small Push button is connected right to the next pin not a power line or resistor, why wont it be like that for the other push button for the rocket? is it because the servo can decode the info???

just dont understand why the push button needed to be powered, unlike my Servo button?

Which one is a "Servo button"?

StrikeForceInd:
i just dont understand why the push button needed to be powered, unlike my Servo button??? is there a way i dont need this?

It doesn’t. Neither of your buttons are hooked up correctly anyway; you may just be getting lucky with floating pin syndrome. Connect one end of the button to the input pin and the other to GND. Then, put this in your setup function to enable the internal pullup:

pinMode(someSwitchPin, INPUT_PULLUP);

That way the pin will not float, and will stay at HIGH until the switch is pressed. When the switch is depressed, it will read LOW.

my question is why does the “Fire” button have to be this way why cant it just me like the Servo button

attached image…

pinMode(someSwitchPin, INPUT_PULLUP);

ok so where would i put that in the program?

or should i replace my pinMode(RocketFire1, OUTPUT);
to the pinMode(someSwitchPin, INPUT_PULLUP); ???

StrikeForceInd:
my question is why does the "Fire" button have to be this way why cant it just me like the Servo button

And again, neither of your switches are wired correctly for the code that is written.

StrikeForceInd:
or should i replace my pinMode(RocketFire1, OUTPUT);
to the pinMode(someSwitchPin, INPUT_PULLUP); ???

Why would you tell a pin intending to be an output pin, to act as an input?

so change the

pinMode(buttonPin1, INPUT);

to

pinMode(someSwitchPin, INPUT_PULLUP); ???

i got my info from this Example code if th helps you see why i did what i did.

 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}