problem with using if statements and buttons

my code is in the attachment
i am trying to have the code start using a button and only move on when the button is pressed. then in the next callout i want it to check the variables if both the variables are met then it can move on to the next callout
my issue is my buttons work in a seperate code with their own if statements controlling a test LED but when i use them together in my project code the chip doesnt detect when the buttons within “void safety () {}” are being pressed. i used serial data to monitor this and it seems even if i specify to monitor “neuOn” button it continues to only monitor “button.” weird thing is if i monitor “button” within “void loop (){}” then the inputs for “button” are correct. but when i monitor “neuOn” it still monitors “button” but it no longer correctly detects change of state.
my question is am i using the correct code for what i am trying to accomplish or is there a better way to write my code so that Arduino can correctly distinguish between multiple button inputs.

car_start33.ino (2.19 KB)

The OP's code:

 inputs : nuetral safety switch, clutch safety switch, car start button
 outputs: key on position, key run position, neutral motor
 int testLED = 13;
 int button = 12;  // allows car to start remotely
 int keyon = 11;  //sends output to key on
 int keyrun = 10; // sends output to run
 int clutch = 9;  // activates clutch safety switch so car starter will engage
 int neutral = 8; // checks to see if car is in nuetral
 int pbrake = 7;  // checks to see if parking brake is enagaged
 int nmotor = 6;  // if car is not in neutral then motor pushes shifter into neutral
void setup() {
  pinMode(keyon, OUTPUT);  // makes keyon an output
  pinMode(keyrun, OUTPUT); // makes keyrun an output
  pinMode(neutral, INPUT_PULLUP); // makes neutral an input
  pinMode(clutch, OUTPUT); // makes clutch an output
  pinMode(pbrake, INPUT_PULLUP);  // makes pbrake an input
  pinMode(nmotor, OUTPUT); // makes nmotor an output
  pinMode(button, INPUT_PULLUP); // makes button an input
  pinMode(testLED, OUTPUT);
void loop() {
  int keyless = digitalRead(button);     // states keyless reads input from button
  if (keyless == LOW) {safety();}        // states if keyless is HIGH then run safety()}
void safety() {                          // checks if it is safe to start car
  //digitalWrite(clutch, HIGH);            // commands clutch safety switch on
  int but = digitalRead(neutral);      // states neuOn reads input from neutral
  //int brakeOn = digitalRead(pbrake);     // states brakeOn reads input from pbrake
  //while (neuOn == LOW) {};
  //if (neuOn == LOW) 
  digitalWrite(testLED, HIGH);
                                         // states if neuOn, brakeOn is HIGH then run startCar();
//if (neuOn == LOW) {neutralmotor();}
void ignitionOn() { // turns ignition on and runs timer
  //digitalWrite(testLED, HIGH);
  digitalWrite(keyon, HIGH);  //commands keyon
  //digitalWrite(testLED, LOW);
void startUp(){
  digitalWrite(keyrun, HIGH);
  digitalWrite(keyrun, LOW);
void neutralmotor(){
  digitalWrite(nmotor, HIGH);
  digitalWrite(nmotor, LOW);
if (keyless == LOW) {safety();}        // states if keyless is HIGH then run safety()}

Your comment doesn't match your code. Sometimes just going through and fixing this sort of stuff you will find your errors.

int but = digitalRead(neutral);      // states neuOn reads input from neutral

Your description of the problem is a bit convoluted and doesn't make sense with the names of things in the code you posted. Why don't you take a stab at putting that together a little better. What do you mean when you say you try to measure one button but it reads another?

How do you have all this wired up? Can you draw us a quick wiring diagram?

yeah i have the names in the comments all messed up because i was trying everything as far as changing the names to see if that would work then i switched from pulldown resisters to the internal pull up resisters and i forgot to change the comments to match. (i have been on this problem for a week)
in serial data if i say measure input from line 30,


it will send me input from line 25 like it is seeing this within void loop


button wiring diagram is in the attachments allong with the updated code with matching comments

buttons work seperately in a test code as intended.

car_start33.ino (2.07 KB)

How do you know? Anonymous printing sucks. Print some label before those things so you know what gets printed where.

I see your schematic but it only has one button. I wasn’t trying to get a synopsis of your wiring but the actual wiring of your project.

here is a picture of my entire breadboard.
yellow is my outputs and orange in my inputs.

i figured it out what i did was replaced the first if statement for the first button to a while statement and now everything works as intended. i dont know why the while statement works over the if statement but it works now.

That's not good. Random changes that seem to make things work but you don't understand it is a recipe for even more messed up code later. You should be able to understand the logical difference between an if statement and a while statement. You should be able to trace through based on that what the code does and see if it is actually what you want or if is just seems to work for now.

oh trust me i am eager to learn the difference of why the if statement doesnt work but for the meantime i am at least getting somewhere. i just started learning code 3 weeks ago i am not supposed to know everything. thanks for the help.


Can you please post a copy of your circuit, in CAD or a [u]picture of a hand drawn circuit in jpg, png?[/u]

Thanks...Tom.. :)