Today I want to present you to the result of a team job, a lift. There have been loads of trials and errors especially in the mechanics. I have to thank my father for the electromechanics of the lift because otherwise I couldn’t have been able to finish it this fast. Thank you dad! you rock! I do still remember as being a kid and him encouraging me to build something. Unfortunately not all was about building, I still remember that as being kid I used to take a screw to break all the diodes on his pcbs, holy patience you had dad!
Because of the length of the post, I’ve decided to divide it into different parts:
- Overall description
- Detailed pictures
- Hardware description
- Test cases with videos
- Software description
In this project my father and I have tried to replicate a common lift with 5 floors (0 to 4) . We have two ways to move the lift, from the outside with its corresponding leds signalling the motion of the lift to go upwards or downwards and from within we have another set of push buttons to go to the floor we want to. There is a led in each button in the buttons which are inside to indicate the floor where the lift is headed to. Once the lift has reached the position where it is required to be the door will be opened, the lift will let some time to people to get in and then it will close the door and then it will move there where it is requested.
Because of having used interrupts it is not necessary to wait for the lift to be in a floor to call from somewhere else. During all the process, opening, closing door, moving upwards or downwards the lift will be able to store the request and service then when being able to. Here is a general video to see the inside and the outside of it:
Front view of the lift
Of course, the leds and the push buttons are recycled. The ones from the inside the lift are from an old phone. The others from PCBs, likewise the LEDS. Where the push buttons from the outside and the leds are is just a cable rack.
Rear view of the lift
The funniest thing is that most of the parts used on the lift have been recycled. With the exception of the arduino and some of the wires to connect the different boards, all the materials were already around my home, which is more challenging as it isn’t like assemblying a kit. There are lots of adjustements besides, bearing in mind that neither me nor my father are carpenters so our tools are as well quite limited.
I’ve decided to simplify a bit all the schematics, in truth there is some wired logic to get NC end limit switches from NO end limit switches through relays.
The sensors are a single IR emitter and 5 different IR receivers for each floor. These will set the green position leds which are up on the lift. The schematic for one of the emitter (which is in movement with the lift) and the sensors is the following (The receiver should be duplicated for the rest of the floors) :
The way to control the motor of the door is made with two relays which invert the voltage to invert the motion of the motor. The open command or close command should be always sent by the arduino board. Once the door reaches the end, it hits either the open end limit switch or the close end limit switch, which stops the motor. Besides, it has been added
The electrical schematic for opening and close the door is the following:
There are certain security measures within the circuit such as stopping the lift if it’s moving upwards and it’s already on the last floor. This was made because before having the arduino somehow we could have messed it up inmensily. Likewise, on the floor 0 there is another contact that will stop the supply of energy to the motor if the lift is already on the floor 0. Besides, the lift will not move unless the door is fully closed. The schematic is the following:
There are more of course, for example, if the door is being opened or closed the lift should not move, this has been done by programming and in the same way has been made redundant by wired locking. The schematic is the following:
In the first place, the priority is for the people who have called within the lift, why? Because we have to give priority to the people who waited and is already within the lift. Now let’s describe the test cases ilustrating each with a video:
Test case 1
If the lift is moving from the floor 4 towards the 0 and there are other “requesters” who call the lift to go down the lift should stop in each floor to pick them and then they would select a floor to go.
Test case 2
In the other way round, if the lift is in the floor 0 and it’s going towards the 4th one, the lift will stop in each floor where a up request has been made.
Test case 3
For this case we’ll call the lift in the same floor where the lift is. In this case the door should open and let the people in to move somewhere else.
Test case 4
If after having called the lift the people decide not to get in or get in and not push any buttons in the inside then the lift will stay there up to the point where another request is made.
Test case 5
Let’s imagine a case where the lift is stopped on the floor 0 and we call it to go upwards from the 3rd,2nd and 1st floor, in that order. The lift shouldn’t stop according to the last call but to the ones which are closer, so it should stop in the other way round, 1st ,2nd 3rd to pick the people who want to go upwards. The same would happen in the other way round as being on the 4th floor if we call it to go downwards from 1st,2nd and 3rd it should stop in this way: 3rd,2nd and 1st.
Test case 6
For this test case I’m going to get in the 3rd floor, go to the floors 2nd and 0. In the meantime I will call the lift to go downwards from the 4th floor. The lift will go to the 2nd and 0 floor and then it will go to the 4th one as it’s not in its path.
Test case 7
For this case, I’m going to get in the 1st floor and I’m going to the 3rd floor and being on the 2nd floor I will call it from the 0. The lift will go to the third floor and then to the floor 0.
Test case 8
In this case let’s imagine we are in the 0 floor, we go to the 3rd one. In the meantime someone calls from the floor 2nd to go downwards, in the 3rd one someone gets in and go to the floor 0 but in its path the lift will stop on the 2nd floor to pick the one who has called before reaching the floor 0.
Test case 9
For this case I’m going to duplicate the eighth. However, we’re going to call it from the 2nd to go upwards and after from the 1st to go downwards. Once in the 2nd I’m going to request the lift to go to the third one and only after having done so it will go to the first floor to go downwards.
I’m pretty happy with these test cases but if you have any other idea, just tell me and I will update the post.
The explanation given here is quite too simple, but it may be helpful before giving a look to the code source.
To begin with, let’s start with the variables for the physical world:
ix Stands for boolean input and ox Boolean output, the numbers are the pins used on the Arduino ATMEGA 2560.
int ix_OUT_CALL_UP_0 = 2;
int ix_OUT_CALL_UP_1 = 4;
int ix_OUT_CALL_DOWN_1 = 3;
int ix_OUT_CALL_UP_2 = 6;
int ix_OUT_CALL_DOWN_2 = 5;
int ix_OUT_CALL_UP_3 = 8;
int ix_OUT_CALL_DOWN_3 = 7;
int ix_OUT_CALL_DOWN_4 = 9;
int ixBOX_CALL_0 = 26;
int ixBOX_CALL_1 = 24;
int ixBOX_CALL_2 = 25;
int ixBOX_CALL_3 = 23;
int ixBOX_CALL_4 = 22;
int ox_BOX_LED_0 = 27;
int ox_BOX_LED_1 = 28;
int ox_BOX_LED_2 = 29;
int ox_BOX_LED_3 = 30;
int ox_BOX_LED_4 = 31;
int ox_UP_CMD = 32;
int ox_DOWN_CMD = 33;
int ox_OPEN_CMD = 34;
int ox_CLOSE_CMD = 35;
int ox_OUT_LED_UP = 36;
int ox_OUT_LED_DOWN = 37;
The classes used in the program are the following:
TON Class: I can’t help it but refer you to the post where I first did this class, here.
LIFT Class: This class is in charge of moving up or down depending on the target position and the current position with which is fed through the sensors. Besides, this class will open the door and close it once it has passed the determined time. With some of the methods of this class we will control the outputs of the arduino board. Besides, if the lift is on a floor and it’s called again, the sequence of opening/close door will be rebooted. This is a public atribute which is only access from within and the function CallManagerBlock().
The TON classes used in this class are within but we need the counter from the outside, this is why the tmrCounter is a variable for the Parameters method. We will be passing the current position, the target position and a flag saying if a sequence has finished.
As functions we have:
CallManagerBlock: Which returns nothing but is in charge of giving priority to the calls from the inside the lift. Likewise it calculates the distance to go to the calls closer.
Besides, it is in charge of handling with the calls of the outside of the lift, determining whether it is going up and from the outside someone wants to go up or someone wants to go down this function will determine which calls pay attention to first. If it is going upwards the lift will have this sequence to start going downwards (unless someone calls from within to go downwards).
PHYSICAL_CALL_MANAGER: Which doesn’t return anything and it will be the interface between the calls from the inside and the outside and will feed the algorithm (QUEUE_UP_MANAGER and QUEUE_DOWN_MANAGER) with the calls.
QUEUE_UP_MANAGER/ QUEUE_DOWN_MANAGER: These two functions do not return anything either. The aim of these functions is to write over an array (either to go up or to go down) just the calls that are not repeated.