Aivaredze
Published © Apache-2.0

Led Stairs controller / Arduino Shield

✔    Up to 24 stairs setup availability. ✔    Fade out  effect. PWM modulation. ✔    Can be connected wirelessly with more th

IntermediateShowcase (no instructions)10 hours5,403
Led Stairs controller / Arduino Shield

Story

Read more

Schematics

002_k1S7R4kbnT.jpg

instruction_kmw1hrAx7H.png

Code

auotlightTest.ino

Arduino
/*
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. 
 * repeater and gateway builds a routing tables in EEPROM which keeps track of 
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributo
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 * 
 *ShiftRegister74HC595.h - Library for easy control of the 74HC595 shift 
 * Created by Timo Denk (www.simsso.de), Nov 2014.
 * Additional information are available on http://shiftregister.simsso.de/
 * Released into the public domain.
 *
 */
#define MY_RADIO_NRF24                          //For moor info visit www                                                          //.mysensors.org 
#define MY_REPEATER_FEATURE                     //
#include <SPI.h>                                //
#include <MySensors.h>                          //
#include <ShiftRegister74HC595.h>
ShiftRegister74HC595 sr (3, 6, 7, 8);           // ShiftRegister set-up                                                         //Do not change
#define sensorBottom_PIN A1                     // Bottom sensor                                                                 // Do not change                 
#define sensorUpper_PIN A2                      // Upper sensor                                                                  //Do not change
#define lightSensor_PIN A5                      // Light sensor                                                                   //Do not change
boolean climblightSequence = false;
boolean declimblightSequence = false;
boolean MysenSor=1;                               
int numberOfstairs = 19;                          //Set number of stairs                                                           //!!!!!!
int pause = 10000;                                //Set pause between on/off                                                      //!!!!!!!
int val;
int sensor;

void before() {
  MysenSor = loadState(sensor);                   // Seting relay to last known                                                     //state (using eeprom                                                          //storage)
}

void presentation() {
 present(sensor, S_LIGHT);                       // For moor info visit www.mysensors.org
}

void receive(const MyMessage &message) {          // For moor info visit www.mysensors.org
  if (message.type == V_LIGHT) {
    MysenSor = message.getBool();
    saveState(message.sensor, message.getBool());


  }
}
void setup() {
}


void loop() {
  val = analogRead(5);                             //Checking light level || Mysensors relay ON/OFF stage
  if (val <= 10 || MysenSor==1 ) {                 // Adjust photocell cencivity                                                    // . (val<10 dark.....val>800                                                                                                                                                                        
                                                    // Delete "val <= 10 ||" if                                                     //using  Mysensors relay for                                                     //controling a Day/Night                                                        //mode..!!!
                                                   // Delete "|| MysenSor==1" if                                                     //using  photocell..!!!
    BottomTriggerFire();                           //Checking bottom sensor
    UpperTrigerFire();                             //Checking upper sensor
    climbLightSequence();                          //Stairs on/off from down to                                                     //up
    declimbLightSequence();                        //Stairs on/off from up to                                                         //down
  }
}



void BottomTriggerFire() {

  if (analogRead (sensorBottom_PIN) >= 550 ) {      //Depands of the sensor tipe                                                       //, if  trigger signal is                                                       //0 ,than change the                                                            //comparation to opposide                                                        //value.
 climblightSequence = true;
  }
}

void UpperTrigerFire() {

  if (analogRead(sensorUpper_PIN) >= 550) {
    declimblightSequence = true;
  }
}

void climbLightSequence() {
  if (climblightSequence == true && declimblightSequence == false) {
    for (int i = 0; i < numberOfstairs; i++) {
      sr.set(i, HIGH);
      delay(250);
    }
    delay(pause);                                 // paus before to switch off

    for (int i = 0; i < numberOfstairs; i++) {
      sr.set(i, LOW);
      delay(250);
    }
    climblightSequence = false;
  }
}

void declimbLightSequence() {

  if (declimblightSequence == true && climblightSequence == false) {
    for (int i = numberOfstairs; i >= 0; i--) {
      sr.set(i, HIGH);
      delay(250);
    }
    delay(pause);                                 // paus before to switch off

    for (int i = numberOfstairs; i >= 0; i--) {
      sr.set(i, LOW);
      delay(250);
    }
    declimblightSequence = false;
  }

}

Arduino code

Arduino
#define SHIFTPWM_NOSPI                            //  Uncomment this part to NOT use the SPI port and change the pin numbers. This is 2.5x slower  Do not change!!!
const int ShiftPWM_dataPin = 6;                   //  Do not change!!!
const int ShiftPWM_clockPin = 7;                  //  Do not change!!!
const int ShiftPWM_latchPin = 8;                  //  Do not change!!!
#include <ShiftPWM.h>
const bool ShiftPWM_invertOutputs = false;         
const bool ShiftPWM_balanceLoad = false;         
#define sensorLight_PIN A5                        // Light sensor  Do not change!!!
#define sensorBottom_PIN A1                       // Bottom sensor Do not change!!!                     
#define sensorUpper_PIN A2                        // Upper sensor  Do not change!!!
unsigned char maxBrightness = 100;                // Here you set the number of brightness levels. Adjust(0-255)!!
unsigned char pwmFrequency = 75;                  // These values affect the load of ShiftPWM 
unsigned int numRegisters = 3;                    // Number of shift registers Do not change!!!
unsigned int numOutputs = numRegisters * 8;
unsigned int numRGBLeds = numRegisters * 8 / 3;
unsigned int fadingMode = 0;                      // start with all LED's off.
boolean sensorUpperActive;
boolean sensorBottomActive;
int numberOfstairs=24;                           // Setup Number of Your stairs. Adjust UP TO 24 !!!!
int pause=30000;                                    // Setup delay ON/OFF  Adjust!!! 
byte faidoutSpeed=5;                              // How fast to fadeout     Adjust!!!
byte faidinSpeed=5;                               // How fast to fadein      Adjust!!!
int val;

void setup() {


  
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency, maxBrightness);
  pinMode(sensorBottom_PIN, INPUT);
  pinMode(sensorUpper_PIN, INPUT);
  pinMode(sensorLight_PIN, INPUT);
  Serial.begin(9600);
  }



void loop() {

val = analogRead(5);                               //Checking light level 
  if (val <= 1000) {                               // Adjust photocell cencivity. (val<10 dark.....val>800 bright..)    !!!!!!!!
                                                   
    BottomTriggerFire();                           //Checking bottom sensor
    UpperTrigerFire();                             //Checking upper sensor
    switchONOFFfromdown();                         //Stairs on/off from down to up
    switchONOFFfromUp();                           //Stairs on/off from up to down
  }
}

void BottomTriggerFire() {

  if (analogRead (sensorBottom_PIN) >= 550 ) {      //Dependof the sensor type, if 0 when triggered ,than change the comparison to opposite value
    sensorBottomActive = true;
  }
}

void UpperTrigerFire() {

  if (analogRead(sensorUpper_PIN) >= 550) {
    sensorUpperActive = true;
  }
}


void switchONOFFfromdown() {
  if (sensorBottomActive==true && sensorUpperActive==false){
    
 
        for(int i=0; i<numberOfstairs; i++){
          Serial.print(i);
          for(int a=0; a<maxBrightness; a++){
          ShiftPWM.SetOne(i,a);
          delay(faidoutSpeed);
           }
          }
          
        delay(pause); 

        for(int i=0; i<numberOfstairs; i++){
          //Serial.print(i);
          for(int a=maxBrightness;a>=0;a--){
          ShiftPWM.SetOne(i,a);
          if(a==0){
          ShiftPWM.SetOne(i,0);  
          }
          delay(faidinSpeed);
           }
          }
        sensorBottomActive = false ;  
  }
}
         
 void switchONOFFfromUp () {
    if ( sensorUpperActive==true && sensorBottomActive==false) {


        for(int i=numberOfstairs-1; i>=0; i--){
          Serial.print(i);
          for(int a=0; a<maxBrightness; a++){
          ShiftPWM.SetOne(i,a);
          delay(faidoutSpeed);
           }
          }
          
        delay(pause); 

          
        for(int i=numberOfstairs-1; i>=0; i--){
          //Serial.print(i);
          for(int a=maxBrightness;a>=0;a--){
          ShiftPWM.SetOne(i,a);
          if(a==0){
          ShiftPWM.SetOne(i,0);  
          }
          delay(faidinSpeed);
           }
          }
        sensorUpperActive= false ;  
  }
}

     
    
    

        

  

Github

Mysensor

Github

Shift-Register

Credits

Aivaredze

Posted by Aivaredze

Comments