logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Arduino Leonardo stair lighting with motion sensors - how to write a sketch?

Filip5665 3054 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 14912044
    Filip5665
    Level 2  
    Posts: 3
    Hi. I have this question, I have decided to make a stair lighting based on arduino leonardo.
    My problem is that I don't know much about it and I would like to get something like this so that by using motion sensors which, will give a signal and run a program in the arduino.
    The sensors are located at the beginning of the stairs at the top and at the bottom, depending on the direction of exit the light will turn on from the bottom or from the top. My problem is that I don't know how to write a sketch to make the programme switch on the sensors.
  • ADVERTISEMENT
  • #2 14912196
    Zbigniew 400
    Level 38  
    Posts: 4356
    Help: 283
    Rate: 793
    And if someone comes in from below and above, what should happen?
  • ADVERTISEMENT
  • #3 14912232
    Filip5665
    Level 2  
    Posts: 3
    I did not envisage this possibility, although it could light up from the top and bottom and meet in the middle.
  • ADVERTISEMENT
  • #4 14914074
    Filip5665
    Level 2  
    Posts: 3
    Has anyone encountered such code on an arduino?
  • ADVERTISEMENT
  • #5 14979716
    zbyszekskibinski
    Level 33  
    Posts: 2811
    Help: 179
    Rate: 340
    Hello buddy, I don't know if your topic is still relevant, but such installations can be easily realised with LOGO! 230R(C) controllers. You insert one sensor at the bottom, another one at the top, then you program the device in such a way that the lamps are switched on in sequence one after another using special function blocks (SF), e.g. ON DELAY, but for this you must first learn the basics of construction and operation of simple PLCs.
  • #6 15408019
    Decembrie
    Level 9  
    Posts: 10
    Rate: 2
    void setup() {
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(10, OUTPUT);

    pinMode(1, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);

    digitalWrite(13, LOW); /Disabling the LEDs
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    }

    void loop()
    {


    delay(1000); //Stop the program before entering the loop for 1 second
    while (digitalRead(1) == HIGH) {} //If the button is pressed

    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(12, HIGH);
    delay(1000);
    digitalWrite(11, HIGH);
    delay(1000);
    digitalWrite(10, HIGH);

    delay(3000);

    digitalWrite(13, LOW);
    delay(1000);
    digitalWrite(12, LOW);
    delay(1000);
    digitalWrite(11, LOW);
    delay(1000);
    digitalWrite(10, LOW);

    delay(1000); //Stop the program before entering the loop for 1 second
    while (digitalRead(2) == HIGH) {} //If the button is pressed

    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(11, HIGH);
    delay(1000);
    digitalWrite(12, HIGH);
    delay(1000);
    digitalWrite(13, HIGH);

    delay(3000);

    digitalWrite(10, LOW);
    delay(1000);
    digitalWrite(11, LOW);
    delay(1000);
    digitalWrite(12, LOW);
    delay(1000);
    digitalWrite(13, LOW);
    }

    I have used two buttons only I don't know how to break the loop.
    After pressing the first button (e.g. at the bottom) I have to press button two (at the top) to make the first button work again
ADVERTISEMENT