A miniature lift – Arduino Mega 2560 on a RTS

Hello everyone!

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:

  1. Overall description
  2. Detailed pictures
  3. Hardware description
  4. Test cases with videos
  5. Software description

Overall 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:

Go to the index.

 

Pictures

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.

dav

Rear view of the lift

REAR VIEW

Main motor

Main motor

Go to the index.

Hardware description

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) :

Sensors 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:

Door control

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:

Motion control

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:

Go to the index.

Test cases

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.

Go to the index.

Software description

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 ix_SENSOR_0=40;
int ix_SENSOR_1=41;
int ix_SENSOR_2=42;
int ix_SENSOR_3=43;
int ix_SENSOR_4=44;

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) so that the call requests are not repeated in the array of movement.

Go to the index.

Arduino – TON, TOF and TP Timers V2 from microseconds to years!

Hello everyone!

I realized my libraries were not working properly as trying to set the timer to hours and let it for 12 hours. The problem is that I had written ((2^32)-1) for some calculations. At this point the variable was 0. I have solved it, anyway, if you test any of these libraries and find a bug or think of a better way to do it, I’ll be happy to hear about it.

It’s time to present a new version of the class TON that I’ll be using for my following projects. The delay for this timer can go from microseconds to years and it admits floats as the preset time. The code is far more simple than the previous version of my TON class. Here I’m not using interrupts and therefore the class is independent from them (for me a must). If in my previous version I used interrupts it was just to toy with them but in terms of pragmatism, I do rather this version.

The use of this class is very simple. But first let’s look at how this timer works, IN is the input variable that will initialize the timer. Q is the output and ET the elapsed time. Once the input is true, if the time that has gone by with IN being true is bigger than PT (Preset time) then our Q output will be true as long as IN is true. However if IN is true for a period smaller than PT then our output will never be true. This in words is a bit messy, but here’s the diagram of what words describe:

To use this class we instance the TON class.

TON TON1;

Then we pass its parameters in the

void loop() {

TON1.parameters(Input,T_DELAY,“Format”);

}

 

Where:

  • Input is a boolean that will initialize the delay.
  • T_DELAY is the preset time (after which if Input is true, TON1.Q() will be true as well).
  • “Format” can be:
    • “Microseconds”
    • “Miliseconds”
    • “Seconds”
    • “Minutes”
    • “Hours”
    • “Months” (I’ve determined 30 days for each month)
    • “Years”

There’s another thing we can retrieve from our TON class which is the elapsed time by accessing the method, TON1.ET().

In the following link I’ve updated an example of use.

In the same way as described below, there’s the TOF timer, which follows the following diagram:

TOF_Diagramm

In the following link you can get the class of the TOF Timer.

The TP timer is slightly different, its diagram is the following one:

TP_Diagramm

In the following link you can download the class of the TP Timer.

 

Twincat 3 – Modeling a circuit breaker.

Hello everyone!

As it has been long since last post of a program using Twincat 3 I wanted to program an algorithm to transfer the power supply from one feeder to another but the very first step is to model a circuit breaker and then program the algorithm, today I’m publishing the Circuit breaker and the testing carried out through the HMI, I still am unable to modify values from the HMI, I have to write the variables through the IDE itself.

By the way, just as a reminder, Timers should be used in this manner: INSTANCE_TMR(IN:=CONDITION_TO_INITIALIZE, PT:=TIME_DELAY, Q=>OUTPUT); because if you try to do this:

INSTANCE_TMR.IN:=CONDITION_TO_INITIALIZE;

INSTANCE_TMR.PT:=TIME_DELAY;

It won’t work 😉

The circuit breaker is in charge of interrupting the energy for the Loads 1 to N connected to the Busbar. To represent the circuit breaker, the filled squared means that the circuit breaker is closed, in case of the square being empty, the circuit breaker is open and the cross means that the status of the circuit breaker is unknown.

As an exercise I propose you to add each event such as fail to open, fail to close and any change of status of the circuit breaker to an array of strings with N registers using a FIFO structure click here for more information about this structure.

Here’s the video of the testing:

 

There are two external lockings which are not wired, this is because circuit breakers vary and so does criteria. Therefore, the lockings that affect to the operation of the CB is whether there has been a fail to change its status or the status is already the one that has been commanded to be.

From here you can download the project.

 

 

STL – Tia Portal 14 – Start On Delay Timers

Hello everyone!

Today I’m presenting you to an example of how to use Start on delay timers in STL.

These two pdf sheets with the instructions of the STL may be of use for you:

Sheet 1– Sorted by category.

Sheet 2 – Sorted alphabetically.

However I would strongly recommend using F1 on your IDE to find out more about the particular function you want to use.

For my particular case and following the thread of the last post I’ve decided to model a tank with its respective High alarm, high warning, low warning and low alarm.

So, in STL how do I initialize a timer comparing values?

Let’s start by writing the High level alarm

We have must compare values, to do so we’ll use the function Load, L.

L #CV // We load the current value read from an analog input to the Accumulator 1.

L #HAlarmSP //We load the Set point when we’ll see an alarm to the accumulator 1, deplacing #CV to accumulator 2

>=R // We compare whether The accumulator 2 (#CV) is greater than the accumulator 1( #HAlarmSP) if this is true then the program continues its execution downwards.
L #AlarmDelay // We load the time to delay the alarm.
SD “TimerHAlarm” // We put the loaded time in the timer initializing it in case the condition mentioned above is true. (This has been declared in a TagList within the TIA Portal IDE.
A “TimerHAlarm” // This is the output of the timer (TMR.Q for those who use . notation)
= #HAlarm // This will be the bool that will be true once the time has elapsed.

So far, so good? I hope so, if not I’ll let the example I’ve programmed here.

And as an exercise I encourage you to program the rest of the code to get a High warning , Low warning  and Low alarm.

Here is the video of what I’ve programmed:

OOP and Arduino. TON, a practical example.

Hello everyone!

This TON class has been replaced by a better and more versatile version, with a float as an input and a delay from microseconds to years!! visit it here!

If you don’t fancy visiting the new version, you can keep on reading this post to know how I first programmed my TON timer.

Continue reading “OOP and Arduino. TON, a practical example.”