Jakub Belniak
Published © CC BY

Lego Mindstorms Elevator

A 3-story elevator with a mechanical door made from Lego Mindstorms and programmed on RoboCore. It moves up and down and reacts to buttons.

IntermediateShowcase (no instructions)10 hours3,428
Lego Mindstorms  Elevator

Things used in this project

Hardware components

Mindstorms EV3 Programming Brick / Kit
LEGO Mindstorms EV3 Programming Brick / Kit
2 motors
×1
RoboCORE
Husarion RoboCORE
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
9 buttons
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

Elevator code

C#
Elevator operates on limit switches made from buttons which indicate on what floor is the elevator. 3 other buttons outside the elavator are for calling it on desired floor. 3 buttons inside the elavator are used to choose destinantion of the elevator. Code is based on functions and loops.
#include <hFramework.h>

using namespace hFramework;


void door_open(){
hMot2.setPower(400);
	hMot2.rotRel(-90);

	//hMot2.rotAbs(90);

}

void door_close(){
hMot2.setPower(400);
	hMot2.rotRel(90);

	//hMot2.rotAbs(90);

}

void on_czek_off_door()
{
    door_open();
    sys.delay(10000);
    door_close();
}




void home_elevator(){
    hExt2.pin1.setIn_pd();//krancowka dolna

	hMot1.setPower(300);
	while(hExt2.pin1.read()==0){
		sys.delay(50);
	}
	hMot1.setPower(0);
}

void semi_elevator(){
    hExt2.pin1.setIn_pd();//krancowka dolna
    hExt2.pin2.setIn_pd();//krancowka srodkowa
    hExt2.pin3.setIn_pd();//krancowka gorna

    if(hExt2.pin1.read()==1)
    {
        hMot1.setPower(-300);
        while(hExt2.pin2.read()==0){
            sys.delay(50);
        }
        hMot1.setPower(0);

    }
    if(hExt2.pin3.read()==1)
    {
        hMot1.setPower(300);
        while(hExt2.pin2.read()==0){
            sys.delay(50);
        }
        hMot1.setPower(0);
    }


}



void end_elevator(){
    hExt2.pin3.setIn_pd();//krancowka gorna

	hMot1.setPower(-300);
	while(hExt2.pin3.read()==0){
		sys.delay(50);
	}
	hMot1.setPower(0);
}





void buttons_thread_loop()
{
    //przyciski zewnatrz
    hExt1.pin1.setIn_pd();
    hExt1.pin3.setIn_pd();
    hExt1.pin2.setIn_pd();

    //przyciski wewnatrz
    hExt1.pin5.setIn_pd();
    hExt1.pin6.setIn_pd();
    hExt1.pin7.setIn_pd();



	while(true){


        //przyciski zewnetrze

        //jazda na 1 pietro
		if((hExt1.pin1.read()==1)||(hExt1.pin5.read()==1))
		{
            sys.delay(20);
            if((hExt1.pin1.read()==1)||(hExt1.pin5.read()==1))
            {
                home_elevator();
                on_czek_off_door();

            }
		}


        //jazda na 2 pietro
		if((hExt1.pin3.read()==1)||(hExt1.pin6.read()==1))
		{
            sys.delay(20);
            if((hExt1.pin3.read()==1)||(hExt1.pin6.read()==1))
            {
                semi_elevator();
                on_czek_off_door();

            }
		}



        //jazda na 3 pietro
		if((hExt1.pin2.read()==1)||(hExt1.pin7.read()==1))
		{
            sys.delay(20);
            if((hExt1.pin2.read()==1)||(hExt1.pin7.read()==1))
            {
                end_elevator();
                on_czek_off_door();
            }
		}

    }

}




void hMain()
{

    //end_elevator();
    //buttons_thread_loop();
    // create thread handling buttons, so you can do other work in hMain
    sys.taskCreate(buttons_thread_loop);

    //while (true) {
      //  LED1.toggle();
        //sys.delay(500);
    //}
}

Credits

Jakub Belniak

Jakub Belniak

1 project • 0 followers

Comments