Elevator with 4 floors

I am having problems with making the code for an elevator i built, it has 4 floors and the circuit has an H bridge and 4 buttons.

const int button1 = 9;
const int button2 = 10;
const int button3 = 11;
const int button4 = 12;
const int B2A = 3;
const int B2B = 5;
const int halleffect1 = 4;
const int halleffect2 = 6;
const int halleffect3 = 7;
const int halleffect4 = 8;

void setup()
{

pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(halleffect1, INPUT);
pinMode(halleffect2, INPUT);
pinMode(halleffect3, INPUT);
pinMode(halleffect4, INPUT);

pinMode(B2A, OUTPUT);
pinMode(B2B, OUTPUT);

Serial.begin(9600);

}

void loop()
{

digitalRead(halleffect1);
digitalRead(halleffect2);
digitalRead(halleffect3);
digitalRead(halleffect4);

if (digitalRead(button1) == HIGH)
{
floor1function();
}

else if (digitalRead(button2) == HIGH)
{
floor2function();
}

else if (digitalRead(button3) == HIGH)
{
floor3function();
}

else if (digitalRead(button4) == HIGH)
{
floor4function();
}

digitalWrite(B2A, LOW);
digitalWrite(B2B, LOW);

}

void floor1function()
{

if (digitalRead(halleffect1) != LOW)
while (digitalRead(halleffect1) == HIGH)
{
motordown();
}
}

void floor2function()
{

if (digitalRead(halleffect3) == LOW || digitalRead(halleffect4) == LOW)
{
while (digitalRead(halleffect2) == HIGH)
{
motordown();
}
}

else if (digitalRead(halleffect1) == LOW)
{
while (digitalRead(halleffect2) == HIGH)
{
motorup();
}
}
}

void floor3function()
{

if (digitalRead(halleffect1) == LOW || digitalRead(halleffect2) == LOW)
{
while (digitalRead(halleffect3) == HIGH)
{
motorup();
}
}

else if (digitalRead(halleffect4) == LOW)
{
while (digitalRead(halleffect3) == HIGH)
{
motordown();
}
}
}

void floor4function()
{

if (digitalRead(halleffect4) != LOW)
{
while (digitalRead(halleffect4) == HIGH)
{
motorup();
}
}
}

void motorup()
{
digitalWrite(B2A, HIGH);
digitalWrite(B2B, LOW);
Serial.println("Going Up");
}

void motordown()
{
digitalWrite(B2A, HIGH);
digitalWrite(B2B, HIGH);
Serial.println("Going Down");
}

Hi @nandesslb
Recommendations.
Read: How to get the best out of this forum
Use </> tags to post sketcks or printouts;
Post your scheme. Not fritzing .Can be done freehand;

About your problem. Which is ? ???
RV mineirin

well the problem is the dc motor does not respond when i press the butons and i know its something i put wrong in the code or just didn't put at all

How s the motor driver connected - more info than the frizzy diagram.

The motor is connected by 2 cables to the H bridge, the H bridge is conected to an external source and to the arduino.

some quick thoughts

shouldn't button pins be configured with pullup, INPUT _PULLUP, and won't a button pull the input LOW when pressed?

are B2A and B2B the pins the control direction and should be opposite when the motor runs and the same (HIGH or LOW) when stopped? is the ENable pin being driven (PWM)?

As for the first question i don't realy know but im going to change that.
The second question, Yes the pins on the H bridge are suposed to run the motor up and down.
The last question i realy don't know.

a typical h-bridge requires 3 pins. 2 pins, A & B, determine the direction and the EN pin is usually used to control speed and needs to be set for the motor to be ON

this is an L9110 bridge idk if it makes a difference

yes it makes a difference. while it may use an h-bridge it is actually a motor controller with just 2 control pins. looks like just one pin should be HIGH to move in a direction

motorDown() sets them both HIGH

Oh thanks im going to change that right now

Please design and test all the various components of your system independently of each other. That will eliminate a lot of guesswork about why the system as a whole doesn't do what you expect.

consider

demonstrates the concept of a position and target and generically changing a position to reach a target

and consider its use of arrays and how your code would look if there were 10+ floors

// elevator

enum { Off = HIGH, On = LOW };

byte pinsLed [] = { 10, 11, 12 };
byte pinsBut [] = { A1, A2, A3 };
#define N_BUT   sizeof(pinsBut)

byte butState [N_BUT];

// -----------------------------------------------------------------------------
int
chkButtons ()
{
    for (unsigned n = 0; n < sizeof(pinsBut); n++)  {
        byte but = digitalRead (pinsBut [n]);

        if (butState [n] != but)  {
            butState [n] = but;

            delay (10);     // debounce

            if (On == but)
                return n;
        }
    }
    return -1;
}

// -----------------------------------------------------------------------------
void
setLeds (
    byte  led0,
    byte  led1,
    byte  led2 )
{
    digitalWrite (pinsLed [0], led0);
    digitalWrite (pinsLed [1], led1);
    digitalWrite (pinsLed [2], led2);
}

// -----------------------------------------------------------------------------
int  floorOn  = 0;
int  floorReq = floorOn;

void
loop ()
{
    int but = chkButtons ();

    if (0 <= but)
        floorReq = 100 * but;

    if (floorOn != floorReq)  {
        if (floorOn > floorReq)
            floorOn -= 10;
        else
            floorOn += 10;
        delay (200);

        char s [80];
        sprintf (s, " on %6d, req %6d", floorOn, floorReq);
        Serial.println (s);
    }

    if ( 50 > floorOn)
        setLeds (On, Off, Off);
    else if (150 > floorOn)
        setLeds (Off, On, Off);
    else
        setLeds (Off, Off, On);
}

// -----------------------------------------------------------------------------
void
setup ()
{
    Serial.begin (9600);

    for (unsigned n = 0; n < sizeof(pinsBut); n++)  {
        pinMode (pinsBut [n], INPUT_PULLUP);
        butState [n] = digitalRead (pinsBut [n]);
    }

    for (unsigned n = 0; n < sizeof(pinsLed); n++)  {
        digitalWrite (pinsLed [n], Off);
        pinMode      (pinsLed [n], OUTPUT);
    }
}

Your button inputs definitely need pull-ups. Internal pullups are enabled by

pinMode(button1, INPUT_PULLUP);

etc.

Separate out the button code and make sure just the buttons work. Then add the rest of the code.

This:

  if (digitalRead(halleffect1) != LOW)
    while (digitalRead(halleffect1) == HIGH)
    {
      motordown();
    }

is the same as this:

  while (digitalRead(halleffect1) == HIGH)
  {
    motordown();
  }

and

while (digitalRead(halleffect1) == HIGH)
  {
    motordown();
  }

is the same as

while (digitalRead(halleffect1))
    motordown();