I need help with my elevator uni project, I don't have much time

#include <LiquidCrystal.h>
#define pwm1     9
#define pwm2     10

int i=1;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 
#define btn4 13
#define btn3 6
#define btn2 7
#define btn1 8 
boolean buttonState1;
boolean buttonState2;
boolean buttonState3;
boolean buttonState4;

void setup() {
  
  pinMode(pwm1, OUTPUT); 
  pinMode(pwm2, OUTPUT); 
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(btn4,INPUT_PULLUP);
  pinMode(btn2,INPUT_PULLUP);
  pinMode(btn3,INPUT_PULLUP);
  pinMode(btn1,INPUT_PULLUP);
}
void loop() {
  lcd.print("FLOOR ");
  lcd.print(i);
  delay(1000);
  lcd.clear();
  buttonState1 = digitalRead(btn1);
  buttonState2 = digitalRead(btn2);
  buttonState3 = digitalRead(btn3);
  buttonState4 = digitalRead(btn4);
  digitalWrite(pwm1,LOW);
  digitalWrite(pwm2,LOW);
  
  //------------------------------------------
  //On clicking on 4th floor's button
  
  if(buttonState4 != HIGH){
    while(i<4){   
      i++; 
      digitalWrite(pwm1, LOW);
      digitalWrite(pwm2, HIGH);
      lcd.print("On the way to ");
      lcd.setCursor(0,1);
      lcd.print("floor ");  
      lcd.print(i);
      delay(1000);
      lcd.clear();
    }
    i=4;
    lcd.clear();
  }
  //----------------------------------
  //3rd floor
  if(buttonState3!= HIGH){
    if(i>3){
      while(i>3) {
        i--;
        digitalWrite(pwm1, HIGH); 
        digitalWrite(pwm2, LOW); 
        lcd.print("On the way to");
        lcd.setCursor(0,1);
        lcd.print("floor ");
        lcd.print(i);
        delay(1000);
      }
    }
    
    if(i<3){ 
      while(i<3){
        i++;
        digitalWrite(pwm1, LOW);
        digitalWrite(pwm2, HIGH);
        lcd.print("On the way to");
        lcd.setCursor(0,1);
        lcd.print("floor ");
        lcd.print(i);
        delay(1000);
      }      
    }    
    
    i=3;
    lcd.clear();
  }
  //-------------------------------------------------
  //On clicking on 2nd floor's button
  
  if(buttonState2!= HIGH){
    
    if(i>2){
      while(i>2) {
        i--;
 	    digitalWrite(pwm1, HIGH); 
        digitalWrite(pwm2, LOW); 
        lcd.print("On the way to");
        lcd.setCursor(0,1);
        lcd.print("floor ");
        lcd.print(i);
        delay(1000);
      }
    }
    
    if(i<2){ 
      while(i<2){
        i++;
    	digitalWrite(pwm1, LOW);
  		digitalWrite(pwm2, HIGH);
   		lcd.print("On the way to");
       	lcd.setCursor(0,1);
    	lcd.print("floor ");
        lcd.print(i);
        delay(1000);
      }      
    }    
    
  	i=2;
    lcd.clear();
  }

  //-----------------------------------------
  //On clicking on 1st floor's button
  
  if(buttonState1 != HIGH){
    
  	if(i>1){
    	while(i>1) {
    		i--;
			digitalWrite(pwm1, HIGH); 
 			digitalWrite(pwm2, LOW); 
    		lcd.print("On the way to");
     		lcd.setCursor(0,1);
    		lcd.print("floor ");
      		lcd.print(i);
      		delay(1000);
       		lcd.clear();
        }
    	i=1;    
      	lcd.clear();
    } 
  }
}

When i press the buttons nothing happens. The original code was
if(buttonStatex == HIGH), but like that it would have been an endless loop.
Please somebody help me I only have a couple of days before it's time to present my project to my professor

All I can suggest is you get some sense into the button wiring and handling.

You are pulling them low with external resistors, and pulling them high with the internal pull-up feature of the AVR input pin.

Best practice:

Wire the switches between ground and their respective input pins.

Lose the external resistors.

Test the digitalRead() of a pushbutton for LOW which will mean being pressed.

Continue to use INPUT_PULLUP as the pin mode.

HTH

a7

1 Like

And use serial.Print() to show the values being read from each switch pin. Simple debugging to begin with.

Maybe reduce this delay...
Otherwise it will take one second to read your button inputs.

This looks like a for loop...
And since you have 5 of these blocks, it would be better to make this a function. But that may be too much for you looking at the due date...

Hi, @ariqamili
Welcome to the forum

If this is a uni project, where is the schematic diagram?
Your Fritzy is not very informative and hard to read and is not an industrial standard.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you tell us what your uni course is called?

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

1 Like

One thing that you should learn about science is: be precise

what exact type of microcontroller are you using?
Does your project include a real mechanic where with what motor an elevator is physically moving up / down?

How many days are "a couple of days"?

2 days?
3 day?
4 days?

How much time in hours in summary can you spend on this project?

2 hours?
10 hours?
20 hours?
50 hours?

If somebody would start explaining. What knowledge-level about programming do you have?

Have you done some own research about arduino elevator projects?

If would write the code - will you tell to your professor that it is me who has to get the graduation?

1 Like

So there is probably something wrong with the buttons. I suspect they never go low. I would have expected a setup like this:


Not sure why you have an extra resistor in there.

i tested your code and it seems (?) to work

  • routed LCD output to the serial monitor and dropped repeatedly print the FLOOR #
  • pressed button-2
  • pressed button-3
  • pressed button-1

my buttons are wired between the pin and ground

begin
On the way to
floor 2
On the way to
floor 3
On the way to
floor 2
On the way to
floor 1

And how did you spend your time that should have gone into this project till now?

  • Exactly where on the LCD are you printing this.
void loop() {
  lcd.print("FLOOR ");
  lcd.print(i);

Hi, @ariqamili

Do you have a DMM? (Digital MultiMeter)

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

tl;dr: the main issue is the button handling.

I built @ariqamili's elevator project. The logic does work.

I fixed buttons all to be pulled high, LOW when pressed.

I had to change the variable 'i' to anything but. I used IK.

The LCD printing is not very pretty, yet. And as you all have no doubt seen, the use of delay() means leaning on the elevator button for some time before the call is heeded.

The handling of the elevator current floor and journey to the destination floor is literal and naive, obvious low fruit for improvement. One function should be able to make an elevator go up or down enough to go from floor X to floor Y. And that should be possible without timing out the progress with delay calls.

But it's due Monday at 8 PM, or so I have heard. As it is, it works fine and might be called a good first effort, if the buttons are handled consistently: wired from the pin to ground, no resistor and these lines ripped from my working version:

// the pin mode
  pinMode(btn3, INPUT_PULLUP);

// what means a button is being pressed
# define PRESSED LOW

// boolean! true means the button is being pressed
  buttonState3 = digitalRead(btn3) == PRESSED;

// so this will run the body of the if statement when it is executed and the button is down
  if (buttonState3) {

I'm pretty good at this kind of hacking and am quite confident I made no other significant changes. I can honestly say I did not even look too closely at how it works.

@ariqamili should avail herself of the IDE Autoformat tool. Until you can write formatted code by habit, it is a way to put code into one of several well-known standard formats, and makes code much easier to read and a ceratin class of errors much easier to spot.

a7

How long have you known about this project, and why did it take so long for you to start? Poor planning on your part does not make it an emergency for me. Once you post a correct schematic, I will do my best to assist you.

1 Like

Can you please explain it to me in details, because this is not really related to my degree, I've never heard of arduino before this project

Thank you in advance

Dear @ariqamili,

your title says
I need help with my elevator uni project, I don't have much time.

Now 8 days have passed by until you made this rather poor response
Then the only thing that you are writing is:

As soon as you change from a such poor writing style that has only two sentences that do specify nothing
to
a style that shows real engagement
you will get a lot of help.

Can you please explain it to me in details , because this is not really related to my degree, I've never heard of arduino before this project

Are you expecting that somebody will write down a 10 pages tutorial taylored to the code you need?

What details do you need to be explained?

You might have good reasons why you did not post for the last 8 days.
But then you have to explain it.
Without such an explanation it looks like you are super-lazy.
Still showing no own effort.

You did not answer my question

With your behaviour you made yourself untrustworthy. That is the reason why you only get such small answers.

So depending on the answers how many days and how many hours you can spend on this project different approaches can be taken.

Now it is up to you to show
real engagement to make this project a success.

I get your point
I was trying to fix this i asked for help from my friends still couldn't come up with a solution. I was busy these days.
Now I have until today for this project.

So this means today is the day you have to present the project?

well, I would assume OP had only a few hours left before handing out his work and as the forum did not do his homework for him, he bailed and found an alternate route to cheat his way through this...

I'd love to be proven wrong, but we see it here often, newbies having done nothing to learn, coming here with some code found from previous projects, friends, AI generated or whatever in a last minute hope that we would help them cheat... and then disappearing as fast as they appeared when time runs out.

There are tons of elevator projects out there, some even available in GitHub, that you can use to cheat and chatGPT can even help you refactor the code so that it does not look exactly the same...

@ariqamili, please prove me wrong and show us that there are still students out there working hard to get things done....

1 Like

yes unfortunately