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:
;
}
}