Problem with code for stair lights project... UNO, 74HC595 & ULN2803A

Dear Arduino community,

as many before I was researching the net to build my own automated led stair lighting.. after some research I learned about the Arduino and its capabilities, and started digging in. Issue: I onl

So the desired outcome is the lights move up in front of you if you approach the stairs from below, then turn out on after the other the same direction after a set period of time, and vice versa if you approach from top.

Visually, just like here, which many will know: How to Assemble Stair Lights - YouTube

Hardware-wise I do have the following available for lighting up 14 steps:

1x Arduino UNO
2x 74HC595
2x ULN2803
2x HC-SR04
1x Photocell
1x Poti 10kOhm (thought: to adjust "sensitivity" when the circuit becomes active without having to connect the UNO to a computer, does this make sense/ should it work?)
14x LED stripes à 15 SMD 3528 warm white for 12v (incl. "on strip" resistors)
1x 12V Power source (wall plug)

The whole stuff I set up this way, borrowed by several tutorials, examples and forum threads I based my setup on this scenario about cascading shift registers: Arduino : Cascade two 74HC595 – Erwan's Blog , then added sensors and photocell.

My setup now looks like this, I did not find 12V capable LED strip icons, hence just the red LED's, please bare with me:

UPDATE: If the image is too big, here the direct link: http://up.picr.de/19163221if.png

I can rund Labalec's demo code, runs just fine, so connection wise I hope I am fine...

Then I started custom code, again, "inspired" by tut's, forums etc... but it is not working out well...
with the following code loaded, the LED's connected to the first HC595/ULN2803 combo glow a bit, and they even get pretty hot (even if I disconnect 12V, and just connect USB so the LED strips are unpowered, while the second "channel" simply does nothing...). Sensors/ photocells do not have any effect.. It is simply not doing what I was looking for ^^

Any suggestions, tipps where I am making the mistake between hardware and code? Thanks a million.

PS.: I am more than happy to do a summary for the whole project if we get it solved to help others building their own fancy stair lights.

Kind Regards from Germany,

tobimann!

//Pin connected to ST_CP of 74HC595
int latchPin = 2;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;

#define trigPin1 12
#define echoPin1 10
#define trigPin2 7
#define echoPin2 5

int setvalue = 500;
long duration1, distance1;
long duration2, distance2;
int sequence[9] = {0,1,3,7,15,31,63,127,255};
int i,j;

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
}

void loop() {
  
  if(analogRead(1)>setvalue){
  //count up routine
    SR04(1);
    SR04(2);
    if(duration1>100) i = 0;
    else if(duration1>90) i = 1;
    else if(duration1>80) i = 2;
    else if(duration1>70) i = 3;
    else if(duration1>60) i = 4;
    else if(duration1>50) i = 5;
    else if(duration1>40) i = 6;
    else if(duration1>30) i = 7;
    else if(duration1>20) i = 8;
    
    if(duration2>100) j = 0;
    else if(duration2>90) j = 1;
    else if(duration2>80) j = 2;
    else if(duration2>70) j = 3;
    else if(duration2>60) j = 4;
    else if(duration2>50) j = 5;
    else if(duration2>40) j = 6;
    else if(duration2>30) j = 7;
    else if(duration2>20) j = 8;
    
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, sequence[i]); 
    shiftOut(dataPin, clockPin, sequence[j]);
    digitalWrite(latchPin, 1);
    delay(1000);
  }
}

void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {	
      pinState= 0;
    }

    digitalWrite(myDataPin, pinState);
    digitalWrite(myClockPin, 1);
    digitalWrite(myDataPin, 0);
  }
}

void SR04(int num){
  switch (num) {
    case 1:
      digitalWrite(trigPin1, LOW); 
      delayMicroseconds(2);
      digitalWrite(trigPin1, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin1, LOW);
      duration1 = pulseIn(echoPin1, HIGH);
      distance1 = (duration1/2) / 29.1;
      break;
    case 2:
      digitalWrite(trigPin2, LOW); 
      delayMicroseconds(2);
      digitalWrite(trigPin2, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin2, LOW);
      duration2 = pulseIn(echoPin2, HIGH);
      distance2 = (duration2/2) / 29.1;
      break;
    default: 
      ;
  }
}

I cannot see the image that well but do you have series resistors in each LED circuit?
And you do have a common ground to the Arduino?

Hi, yes, the strips are 12V and come with resistors soldered.. pic seems to be too big? I have to scroll vertically indeed.. how can i change this?

anyway.. i can run sample code like the shiftpwm demo, or the code on labalec.fr, and strips light up fine, dim etc.. just my stuff returns no result :confused:

SPI and the 595 go together very nicely, you may want to use it.

What is this about?
if ( myDataOut & (1<<i) )

just reading into SPI, thanks for the tip.. looks like i have to change pins for that, since it is a protocol assigned to certain pins, right?

the code snippet.. had a friend advising/ helping me.. two noobs, haha. seems to be a leftover from a try before tbh..

generally.. please advise/ feedback: ist his a setup that could return my wished turnout, or am I doing some major mistake about the project? (apart from knowing only little out of each required portion of it :wink: )

Quick note, you need some decoupling in your circuit. Use ceramic .1uF capacitor on each 595 VCC to GND
I do not see a common ground to the Arduino, do you have one?

thanks for the tip with the capacitors, makes sense.

as common gnd, please advise.. you mean one straight to the Arduino, just like the 12V in? (apologies, non-native english speaker, hence the question for clarification)

The 12 volt ground must go to the Arduino ground.

Done, same result. I can run demo code, and even got a 'knight rider' like effect working, (no capaitors in yet, have to grab some next week) nearly out of the box, but me creation fails badly :smiley:

One thing i noticed: the strips connected to the first combi, the uln2803 gets warm/hot even with only 5v attached, led strips not working. If i then connect 12v, these strips slightly glow at very low stage, while the second group is off.

First thought i might have short circuited somewhere, but is not the case, and this does not happen with other code.weird..

  • Take a picture of the wiring and show us.
  • try removing the wire from pin 10 on the 2803s
  • Replace the LED strips with LEDs with series resistor and try.

Hello,

See it >>>>> from Marcio Valerio