Stairs led , help me!

Hello, I need your help. I tried on the French forum but got no help. I suck at programming, I bought the following kit to light up the 16 steps of my staircase. I use sm5050 led strips, pir 501 sensors (one high and one low), a 12v 10A power supply. My concern is the following. If I only connect one sensor (top or bottom) the program works correctly when I pass in front of the sensor, on the other hand if I connect the 2 sensors, the program no longer works. The LEDs will light up for a few minutes without passing in front of a sensor before turning off then the program will no longer respond. I have to unplug the power supply to restart the program

you need to post your code using </>

Code
auotlightTest.ino
Arduino code
auotlightTest.inoArduino

/*

  • 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

*/
#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;

}

}

i simulated your code and it appears to work as I would expect.

i limited the # of LED to 4 and inverted the condition for recognizing an active sensor to < 500 using buttons on those pins

since you said it works for one sensor, but not 2, i suggest you comment out the code for setting either climblightSequence or declimblightSequence and verify that it works.

perhaps one explanation for it only working one is that both sensors are active after triggering a climb

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

The above text was automatically written down after typing a short hotkey-string which makes use of
https://www.autohotkey.com/download/

here is the autohotkey-script for doing this

:R:postcode::You should post code by using code-tags`rThere is an automatic function for doing this in the Arduino-IDE`rjust three steps`r1) press 

best regards Stefan

de/climbLightSequence() are both conditional on only de/climblightsequence being true.

how do you prevent both being true?

thanks for your reply man. yes the program works, I manage to light my 16 steps of stairs but either to go up or down. With the 2 sensors to connect it does not work. Unfortunately I don't know how to change the code, if you can help me please

isn't this a physical, not coding problem?

if you have sensors at the top and bottom of the stairs, how do you expect only one to be active if a person (?) approaches the stairs?

no it's not a physical problem. if I connect a single sensor on the shield, (up or down) the leds will light up either to go up to go down depending on the sensor that is activated. On the other hand if I connect the 2 sensors on the shield, the program no longer works

Juste on sensor no problem up or down

physical in the sense that both sensors are active

your program does check

if (declimblightSequence == true && climblightSequence == false) {

and

 if (climblightSequence == true && declimblightSequence == false) {

which means one variable has to be true the other false.

If both sensors are connected and both sensors are triggered both variables
climblightSequence and declimblightSequence become true

an dthis means that the condition

if (declimblightSequence == true && climblightSequence == false) {

is

if (true == true && true == false) 

which is all in all false
and then nothing happends.
So the logic of your program must be extended
best regards Stefan

thanks for your help stefan. I understand your reasoning. However when the 2 sensors are connected to the kit, the program works without even passing in front of a sensor to activate it (I'm trying to make a video for you tomorrow) Is it possible that the sensor is triggered by seeing the light of the leds in action? (that would explain why it activates itself)

You should analyse what is really happening with a testprogram that does nothing more than print to the serial monitor the status of the two sensors.

Do you know how to write such a test-program?
If not make a first small attempt towards it post your code and then the supporting can go on.

best regards Stefan

1 Like

when you say it works with one, but not with two,
I think hardware, wire, grounds, etc.

both PIR units should have the same Vcc and Gnd and Vcc should go to the Vcc pin and ground should go to the GND pin.
the signal lines of the two units should go to separate pins on the controller.

what it sounds like (wild guess) is that you have both connected to the same intput pin and no matter what, one is not calling for a change so the pin never sees it.

my other wild guess is that the LED power connects to a PIR in some way, interfering with operation

please post a wiring diagram or schematic.

ditto

aha. hm .... "a ready to use" product that does not behave like it should.

The instructions say

  1. Edit code : Set number of stairs, pause between on/off, check your sensors type, adjust photocell

Well "check your sensor-type" that's a "very precise" description of what you have to do.
This sensortype
image

looks like it has a digital output.
usually a sensor with a digital output is connected to an IO-pin that is configured as digital.
The code provided by the manufacturer works. Though the code configures the inputs as analog inputs.

The picture shows how it should be connected to the board.
Please post a picture of your device that sows how it is de facto connected

The microcontroller-world is not superstandardised like USB-devices.
You have to take care of more details than just

"Does the plug fit into the socket?"

So write about:

  • your knowledge-level about programming

  • your knowledge-level about electronics

  • if you have a digital multimeter

If it is not working as expected a careful analysis has to be done.
best regards Stefan

I would troubleshoot the old fashion way.

My understanding is when you connect two sensors, neither motion sensors will light up the LEDs
If you connect only one sensor the motion sensor will light the LEDs.

Have you tried connecting each sensor, one at a time? i.e. will the top sensor work alone and will the bottom sensor work alone?