Robotics ArduinoJLCPCB
Published © GPL3+

Elevator with Arduino

You'll learn how to create your own elevator with Arduino.

IntermediateFull instructions provided5 hours18,327
Elevator with Arduino

Things used in this project

Hardware components

JLCPCB Customized PCB
JLCPCB Customized PCB
×1
Reed Switch, SPST-NO
Reed Switch, SPST-NO
×4
Arduino UNO
Arduino UNO
×1
LCD I2C 20x4
×1
Switch Sealing Boot, Button Operators
Switch Sealing Boot, Button Operators
×4
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
DC Motor, 12 V
DC Motor, 12 V
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1

Software apps and online services

Arduino IDE
Arduino IDE
EasyEDA Software

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Code

Elevador code

Arduino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//Inicializa o display no endereco 0x27
LiquidCrystal_I2C lcd(0x27,20,4);

//Variavel para controlar a entrada no loop
bool controle = 0;
bool not_pos = 0;

//Variaveis de controle para iteracao nos lacos for
int i = 0, j = 0;

//Variaveis utilizadas para armazenar a atual posicao do elevador e a posicao desejada pelo usuario
int actual_pos = 0, des_pos = 0;

//Vetores para armazenar as posicoes do elevador (sensor) e a posicao desejada pelo usuario (pedido)
int sensor[4];
int pedido[4];

//Inicio da funcao void setup
void setup()
{

// Initialization of 20x4 LCD
lcd.begin (20,4); //Inicializa o Display de LCD

// Initializing the 20x4 LCD
lcd.init();                

//LCD Backlight Activation
lcd.backlight();

// Activating the cursor to the 0.0 position of the 20x4 LCD
lcd.setCursor(0,0);

//Configurando os pinos dos botoes como entrada e pull up
for(int i = 2; i <= 5; i++)
{
  pinMode(i, INPUT_PULLUP);
}

//Configurando os pinos dos botoes como entrada e pull up
for(int i = 6; i <= 10; i++)
{
  pinMode(i, INPUT);
}

for(int i = 0; i<4; i++)
{
  pedido[i] = 1;
}

//Configuracao dos pinos de controle dos motores como saidas digitais
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

//Comandos para que o motor fique parado
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}

void loop()
{

//Leitura dos botoes selecionados pelo usuario do elevador
for(int botao = 2; botao < 6; botao++)
{
  //Armazena o estado de cada botao no vetor pedido
  pedido[botao-2] = digitalRead(botao);
  
  //Verifica qual o andar desejado para o elevador subir
  if(pedido[botao-2] == 0)
  {
    des_pos = botao - 1;
    controle = 0;
  }
  
}

//Verifica se um dos botoes foi pressionado e se a variavel de controle possui valor igual a 0  
if((pedido[0] == 0 || pedido[1] == 0 || pedido[2] == 0 || pedido[3] == 0) && controle == 0)
{   

    //Set a value of 1 to the control variable to allow the code stream to enter the condition only once
    controle = 1;
    
    //Execute the loop commands while the control variable is equal to 1
    
      
          //Reading of all sensors to determine the current position of the elevator
          for(int sens = 6; sens < 10; sens++)
          {
            sensor[sens-6] = digitalRead(sens);
          }
            
          //Comparing the current elevator position with the desired position
          for(i = 0; i<4; i++)
          {
              
              if(sensor[i] == 1)
              {
                break;
              }
                  
          }

          for(j = 0; j<4; j++)
          {
              
            if(pedido[j] == 0)
            {
              break;
            }
        
          }

              if(j == i)
              {
                  digitalWrite(10, HIGH);
                  digitalWrite(11, HIGH);
              }
      
                if(j < i)
                {
                  digitalWrite(10, LOW);
                  digitalWrite(11, HIGH);                
                }
      
              if(j > i) //2 > 0
              {
                  digitalWrite(10, HIGH);
                  digitalWrite(11, LOW);
              }
                      
    controle = 0;
    not_pos = 0;


while(not_pos != 1)
{
  
  //Determinando a posicao atual do elevador
  for(int sens = 6; sens < 10; sens++)
  {
   bool s = digitalRead(sens);

     if(s == 1)
     {
      actual_pos = sens - 5; 
     }
  }

   if(actual_pos == des_pos)
   { 
     
     digitalWrite(10, HIGH);
     digitalWrite(11, HIGH);
     not_pos = 1;

     for(int i = 0; i<4; i++)
      {
        pedido[i] = 1;
        sensor[i] = 0;
      }

     break;
   }
}
  
}

}

Credits

Robotics Arduino

Robotics Arduino

42 projects • 60 followers
JLCPCB

JLCPCB

73 projects • 42 followers
JLCPCB, is the largest PCB and PCB Assembly prototype enterprise in Asia. Coupon code "JLCPCBcom" for all and permanantly available.

Comments