Problem Coding Internal Pull Up resistors

I have a program that controls the lights of a trailer. Right now the button inputs are looking for +5v and because they are floating, they are causing problems with the project. I would like to modify the existing set up to look for ground and use the internal pull up resistors, but every time I rework it, it doesn't work. Would really appreciate some help.

#define reverse 2
#define left 3
#define right 4
#define runing 5
#define Fbutton 6
#define Rbutton 7
#define Hbutton 8
#define Sbutton 12
#define Tbutton 9
#define LED 13


int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;
int button5State = 0;


void setup() {

  pinMode ( reverse , OUTPUT ) ;
  pinMode ( left , OUTPUT ) ;
  pinMode ( right , OUTPUT ) ;
  pinMode ( runing , OUTPUT ) ;
  pinMode ( LED , OUTPUT ) ;
  pinMode ( Tbutton , INPUT ) ;
  pinMode ( Fbutton , INPUT ) ;
  pinMode ( Rbutton , INPUT ) ;
  pinMode ( Hbutton , INPUT ) ;
  pinMode ( Sbutton , INPUT ) ;
  digitalWrite ( reverse, HIGH) ;
  digitalWrite( left, HIGH) ;
  digitalWrite ( right, HIGH) ;
  digitalWrite (runing, HIGH) ;
  digitalWrite (LED, HIGH);
}

void loop() {


  button1State = digitalRead(Fbutton);

  if (button1State == HIGH) {
    digitalWrite(right, HIGH);
    digitalWrite(left, HIGH);
    digitalWrite(reverse, HIGH);
    digitalWrite(runing, HIGH);
    digitalWrite(runing, LOW);
    digitalWrite(left, LOW);
    digitalWrite(right, LOW);
    digitalWrite(reverse, LOW);
    delay(500);
    digitalWrite(right, HIGH);
    digitalWrite(left, HIGH);
    digitalWrite(reverse, HIGH);
    delay(500);
    
  }

  button2State = digitalRead(Rbutton);

  if (button2State == HIGH) {
      digitalWrite(reverse, HIGH);
      digitalWrite(left, HIGH);
      digitalWrite(right, HIGH);
      digitalWrite(runing, HIGH);
      digitalWrite(runing,LOW); 
  }

  button3State = digitalRead(Hbutton);

  if (button3State == HIGH) {
    digitalWrite(reverse, HIGH);
      digitalWrite(left, HIGH);
      digitalWrite(right, HIGH);
      digitalWrite(right,LOW);
      digitalWrite(left,LOW);
      delay(500);
      digitalWrite(right,HIGH);
      digitalWrite(left,HIGH);
      delay(500);
  }

  button4State = digitalRead(Sbutton);

  if (button4State == HIGH) {
    digitalWrite(reverse, HIGH);
      digitalWrite(left, HIGH);
      digitalWrite(right, HIGH);
      digitalWrite(runing, HIGH);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(reverse,HIGH);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(2500);
      digitalWrite(reverse,HIGH);
      delay(250);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(right,HIGH);
      delay(100); 
      digitalWrite(left,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      delay(100);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(3000);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(100);
      digitalWrite(runing,LOW);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(reverse,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(2500);
      digitalWrite(reverse,HIGH);
      delay(250);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(right,HIGH);
      delay(500); 
      digitalWrite(left,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(3000);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(500);
      digitalWrite(left,LOW);
      digitalWrite(right,LOW);
      delay(500);
      digitalWrite(left,HIGH);
      digitalWrite(right,HIGH);
      delay(500);

  }

  button5State = digitalRead(Tbutton);

  if (button5State == HIGH) {
    digitalWrite(left, HIGH);
      digitalWrite(right,HIGH);
      digitalWrite(reverse, LOW);
      digitalWrite(runing, LOW);
      digitalWrite(left, LOW);
      delay(250);
      digitalWrite(left, HIGH);
      delay(250);
      digitalWrite(left, LOW);
      delay(250);
      digitalWrite(left, HIGH);
      delay(250);
      digitalWrite(right, LOW);
      delay(250);
      digitalWrite(right, HIGH);
      delay(250);
      digitalWrite(right, LOW);
      delay(250);
      digitalWrite(right, HIGH);
      delay(250);
      digitalWrite(right, LOW);
      digitalWrite(left, LOW);
      delay(250);
      digitalWrite(right, HIGH);
      digitalWrite(left, HIGH);
      delay(250);
      digitalWrite(right, LOW);
      digitalWrite(left, LOW);
      delay(250);
      digitalWrite(right, HIGH);
      digitalWrite(left, HIGH);
      delay(250);
      digitalWrite(right, LOW);
      digitalWrite(left, LOW);
      delay(1000);
  }
}

The digitalWrites are already backwords due to p channel mosfets.


It would be really simple, and it's hard to imagine how you could have got it wrong. Post the version of your sketch where you have tried to use the internal pullup resistors.

Currently the pins are all trying to override each other and causing the circuit to run whatever program it sees first.

BCS5399:
Currently the pins are all trying to override each other and causing the circuit to run whatever program it sees first.

You need to clarify that a bit. What you describe is normal, so also describe what you want to happen.

PS there is a mistake on your diagram. One of your buttons is not connected to ground.

I want the buttons to be pressed and for a the respective if statement to start. However right now the pins are floating. I want to use the internal pull up resistors to stop the floating, but I can't figure out how to code it correctly.

BCS5399:
I want to use the internal pull up resistors to stop the floating, but I can't figure out how to code it correctly.

See pinMode() - Arduino Reference

You can use if / else if so the buttons don't override each other. Currently you test one without taking ibto account the previous.one.

You need to put all reads in the beginning of loop() before you do the testing.

Hi,
Welcome to the forum.

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

Your fritzy picture is unfortunately not a schematic, which should label gate, drain and source, what type of MOSFETs they are, what their part number is, why you have a bluetooth or RF module connected.

Frizty sometimes are good for helping make a circuit, but it does not show signal flow or power supply value.

Can you tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :slight_smile: