Elevator Limit Switch sensor indicator

Hi Everyone !!

I am newbie and trying to make a remote Elevator position indicator panel with Bar GRAPH LED by using the Arduino Analog pin . It should indicate the position of the elevator. There are ten floors, each floor has a limit switch which activates whenever elevator moves upwards or downwards. I have written a small sketch but it does not work while the elevator is moving downwards. Kindly help to resolve this problem.

Code:

Int limitSw =1;
float limitSwValue =0;

int floor1 = 2;
int floor2 = 3;
int floor3 = 4;
//--------------
//---------------
int floor10 = 11;

int floor1State = 0;
int floor2 State = 0;
int floor3 State = 0;
//----------------
//----------------
int floor10 State = 0;

void setup() {

pinMode(floor1, OUTPUT);
pinMode(floor2, OUTPUT);
pinMode(floor3, OUTPUT);
//-----------------
//-----------------------
pinMode(floor10, OUTPUT);
}

void loop () {
limitSwValue=analogRead(limitSw);

if (limitSwValue >=100)
{
digitalWrite(floor1,HIGH);
delay (20);
}
if (limitSwValue >=200)
{
digitalWrite(floor1,HIGH);
digitalWrite(floor2,HIGH);
delay (20);
}
if (limitSwValue >=300)
{
digitalWrite(floor1,HIGH);
digitalWrite(floor2,HIGH);
digitalWrite(floor3,HIGH);
delay (20);
}
//-----------------
//-------------------------

if (limitSwValue >=1000)
{
digitalWrite(floor10,HIGH);

//-------------while elevator moves downwards--------------

if (limitSwValue <=1000)
{
digitalWrite(floor10, LOW); // only this part is working
delay(20);
//----------------------------
//----------------------------
digitalWrite(floor3,HIGH);
digitalWrite(floor2,HIGH);
digitalWrite(floor1,HIGH);
//----------------------------
//----------------------------
if (limitSwValue <=300)

digitalWrite(floor3,LOW);
digitalWrite(floor2,HIGH);
digitalWrite(floor1,HIGH);

if (limitSwValue <=200)

digitalWrite(floor3,LOW);
digitalWrite(floor2,LOW);
digitalWrite(floor1,HIGH);
delay(20);

if (limitSwValue <=100)
digitalWrite(floor3,LOW);
digitalWrite(floor2,LOW);
digitalWrite(floor1,LOW);
delay (20);
}

limitSwValue=analogRead(limitSw);

What kind of switches are these? Typically, a switch is digital. It is either on or off. There is no partially on state.

if (limitSwValue >=1000)
{
digitalWrite(floor10,HIGH); 

//-------------while elevator moves downwards--------------

if (limitSwValue <=1000)
{

The code for the downward motion is only executed if the upward motion reached the limit. There is only one value (1000) that will cause both of these if statements to evaluate to true.

Proper indenting of code between the curly braces would have made this error very apparent.

sir,

A limit switch is used to limit the activation of an electrical circuit. When a circuit is “closed,” it allows the flow of electrical current through the switch to pass to the device being powered. When the switch is “open,” the switch is disengaged and no electrical power will pass through it. In this case it will close the circuit when the elevator reach particular floor and opens when the elevator leaves the floor. In other word it is acting as momentary switch.

The upwards indications are OK. while the elevator travels back downwards i.e. ( value is <1000)
floor10 led goes OFF and other remains ON. But when the value is <900, floor10 led goes OFF but floor9led starts flickering and rest of the leds remains ON

codes upto 3 floors

Int limitSw =1;
float limitSwValue =0;

int floor1 = 2;
int floor2 = 3;
int floor3 = 4;
int floor1State = 0;
int floor2 State = 0;
int floor3 State = 0;
void setup() {
pinMode(floor1, OUTPUT);
pinMode(floor2, OUTPUT);
pinMode(floor3, OUTPUT);
}
void loop () {
limitSwValue=analogRead(limitSw);

if (limitSwValue >=100)
{
digitalWrite(floor1,HIGH); //Floor1 LED ON
delay (20);
}
if (limitSwValue >=200)
{
digitalWrite(floor1,HIGH); Floor1 LED ON
digitalWrite(floor2,HIGH); Floor2 LED ON
delay (20);
}
if (limitSwValue >=300)
{
digitalWrite(floor1,HIGH); Floor1 LED ON
digitalWrite(floor2,HIGH); Floor2 LED ON
digitalWrite(floor3,HIGH); Floor3 LED ON
delay (20);
}

//-------------while elevator moves downwards--------------

if (limitSwValue <=300)
{
:~digitalWrite(floor3,LOW); //Floor3 LED OFF
digitalWrite(floor2,HIGH); //Floor 2 LED ON
digitalWrite(floor1,HIGH); //Floor 1 LED ON

if (limitSwValue <=200)
digitalWrite(floor3,LOW); // Floor3 LED OFF
digitalWrite(floor2,LOW); // Floor2 LED remains ON :~
digitalWrite(floor1,HIGH); // Floor1 LED ON
delay(20);

if (limitSwValue <=100)
digitalWrite(floor3,LOW); //Floor 3 LED OFF
digitalWrite(floor2,LOW); // Floor 2 LED remains ON :~
digitalWrite(floor1,LOW); // Floor 1 LED remains ON :~
delay (20);
}

@karnika
Please use the # button to get [ code] [ /code] tags around your code (you can modify allready posted text)

Please take some time to look at the array tutorial - http://www.arduino.cc/en/Reference/Array -

the code would become something like (not tested)

#define FLOORS 10

int floor[FLOORS];    // ten integers , index 0..9 (the number of stairs you have to go :)
int state[FLOORS];    // ten integers representing the state of floor[i];
int limits[FLOORS];

void setup() 
{
  for (int i=0; i< FLOORS; i++) 
  {
     floor[i] = i;   
     state[i] = 0;
     limits[i] = i * 100;
     pinMode(floor[i], OUTPUT);  
  }
}

void loop ()
{
  int limitSwValue=analogRead(limitSw);

  for (int i=0; i< FLOORS; i++)
  {
    digitalWrite(floor[i],LOW);      // Forced LED[i]  OFF

    if (limitSwValue >= limits[i] )
    {
      digitalWrite(floor[i],HIGH);   // Conditionally set Floor[i] LED ON
    }
  }
}

Be carefull with setting pin0 and 1 to output as this is the Serial port ...

A limit switch is used to limit the activation of an electrical circuit. When a circuit is “closed,” it allows the flow of electrical current through the switch to pass to the device being powered. When the switch is “open,” the switch is disengaged and no electrical power will pass through it.

Exactly. So, why are you using analogRead to read how far the switch is open? It's either open or closed.

If you really had digital switches at each floor, you'd need to read 10 switches, not one.

So, what kind of building is this elevator in? Are there 10 digital limit switches?

If you go back to your original code, put each { on a new line, and properly indent the code between { and }, you will see exactly what your problem is.

You have the whole downward travel code inside the "am I on the 10th floor" block, instead of AFTER that block.

Sir,
Thanx

So, why are you using analogRead to read how far the switch is open? It's either open or closed.

If you really had digital switches at each floor, you'd need to read 10 switches, not one.

So, what kind of building is this elevator in? Are there 10 digital limit switches?

The remote elevator indicator panel is approx. 300 Mtrs from the elevator. If we use digital signal
the cost of the cable will escalate many folds, where as by using analog signal only three wire cable
will do the job.

Is it possible to latch each analog signal while elevator travels upward and unlatch while it travels
downwards ?

This isn't making a lot of sense karnika.

If you really want analog then one assumes you have a resistor network that is being switched so you can read the value and determine what floor the lift is at. In this case I think running such a signal over 300 metres may be a problem.

If this is not the case then the switches aren't "analogue" and you have no way of knowing what switch is on what floor except by counting pulses which is fraught with problems.

There are relatively easy ways to do this with just 3 wires using digital techniques or maybe using DTMF or plain frequencies.


Rob

Sir,
Thanx

If you really want analog then one assumes you have a resistor network that is 
being switched so you can read the value and determine what floor the lift is at.

Yes I have connected .5k resistors because it were available in our workshop. One end of resistor network is connected to +5V and other end to the Gnd and the limit switches circuit is connected to the analog pin
which is working as a potential divider. Hypothetically if we assume that floor1 limit switch gives us .5V and floor2 1V ,Floor3 1.5V----------and floor10 5V. Can we manipulate these voltages to act as a toggle switch (One
push ON second push OFF). I am asking this silly question out of curiosity.

If (LimitSwValue =.5V)
{
digitalWrite (floor1, HIGH);
}

If (LimitSwValue =1V)
{
digitalWrite (floor2, HIGH);
}
// and so on

I played with this code and observed that floor1 LED was ON but when the elevator left the floor1 towards floor2, floor1 LED extinguished. I have no idea how to hold this value. Valuable help and guidance will be
highly appreciated.

See my earlier post.

That code would never have compiled, and also you can't test for == because the value will never be exactly the theoretical amounts. You have to test for a range.

I've got some half-working code but it's late now so I'll post it tomorrow if you haven't figured it out from robtillaart's example by then.


Rob

If this is some sort or hypothetical elevator or simulation, fine.

If this is a real elevator in a real building that carries real people and you are not the manufacture or certified in some way to work on elevators, Stay the hell out of the panel!

That said. put an arduino at the elevator site to look at the digital out puts encode it send the signal down the three conductor wire and decode it at the other end. You can work forever with analog techniques and never get a usable system.

Sounds more like homework.

Sir,
Thanx

There is no safety issues are involved in this because it is only a remote elevator indicator panel and
these limit switches are extra for which the manufacturers of the elevator has permitted us to use.
I tried to write a sketch for three floors . The respective LEDs floor-wise glows and extinguishes when the
elevator travels upwards and downwards. Now the problem is when the elevator leaves floor1 towards floor2
floo1 LED does not glow but when it reaches to floor2 both floor1,floor2 LEDs comes ON and same thing
happens with other floors. I don't understand why this happens, kindly help me to resolve this issue.
I tried to load the image by using insert image icon but no luck. Pl. guide me how to load the image

//LEDs for indicators of elevator position floorwise 
int floor1 = 4; // 
int floor2 = 5;
int floor3 = 6;
int floor1State=0;
int floor2State=0;
int floorl3State=0;
// Resistor network/potential divider connected to Analog Pin 1
int limitSwSensor =1;
float limitSwSensorValue=0;

void setup() {

pinMode(floor1, OUTPUT); 
pinMode(floor2, OUTPUT);
pinMode(floor3, OUTPUT);
}
 
 void loop () {
  {
limitSwSensorValue=analogRead(limitSwSensor);
limitSwSensorValue /=1024;

  digitalWrite(floor3, limitSwSensorValue >=2.4 ?  HIGH : LOW);
  digitalWrite(floor2, limitSwSensorValue >=2.10 ? HIGH : LOW);
  digitalWrite(floor1, limitSwSensorValue >=1.4 ?  HIGH : LOW);

}
}

Here's a snippet that I think is close to what you need.

// values mid way between what you expect with each switch closed
int switch_vals [] = {  50, 150, 250, 350, 450, 550, 650, 750, 850, 950};
// floor              1    2    3    4    5    6    7    8    9    10

// pin numbers for each floor LED
int pins[10] = {3,4,5,6,7,8,9,10,11,12};

void setup () {
  
    Serial.begin (115200);
        
    int i, sw_val;
    int floor_num;
	
    sw_val = analogRead(A0);

    sw_val = 500;  // test value
    
    if (sw_val < 1000) { // don't do this unless a switch is closed
        floor_num = -1;
           for (i = 0; i < 10; i++) {
               if (sw_val > switch_vals[i]) {
                      digitalWrite (pins[i], HIGH);
                      Serial.print (1);
               } else {
                      Serial.print (0);
                       digitalWrite (pins[i], LOW);
                       if (floor_num == -1) floor_num = i;
                }
       }
        
        if (floor_num == -1) floor_num = 10; // bodge to catch 10th floor
 	Serial.print ("\nFloor #");
        Serial.println (floor_num);
    }
    delay(1000);
}

void loop () {

}

There's a bodgy bit of code I've added to catch the 10th floor after the loop, this could probably be done better by looking at the placement of code in th eloop but I'll let you figure that out.

Run this and look in the serial monitor, it will print say 1111000000 for the fourth floor where 1 is a LED on and 0 a LED off.

Edit the switch_vals array to have values roughly half way between the values you get for each floor.

Move the code into loop() and add a small delay for the real app.


Rob

Sir,

Thank you very much for the valuable 8) snippet. I hope this will solve my problem. I will revert back soon.

Regards