Go Down

Topic: LED walkway lighting, Some help would be appreciated (Read 438 times) previous topic - next topic

pop_motion

Hi,

It's been years since I have messed with writing scripts for an Arduino. please forgive my lack of knowledge.

My Goal: 
To light the walkway with 8x automotive 12v COB LED arrays, using PIR modules on either end of the walkway to start the sequence.
(COB - stands for chip-on-board. took me a while to figure out what these arrays are called) 

Lighting: I want  each array to fade ON in sequence, starting for the closest array to the triggering PIR module
then stay ON for 30 seconds,
then fade OFF, if the PIR module isn't triggering.

Since the LED arrays are 12v and assume are going to draw a lot of current for LEDs (still in the mail. Planning on testing the amperage draw) and the issues with PWM and standard relays, I planning on using a 8 channel solid state relay module, with a dedicated 12v power supply from an old 3d printer (converted the printer to 24v a while ago)

Writing a script without the fade ON/OFF, would be easy enough for me write, but fade ON/OFF is where I am having difficulties adding.

The following sketch is from an example FADE sketch from TinkerCAD that I modified with 8 more LEDs. 
There are not PIR inputs in this sketch. It seems to work in the TinkerCAD simulator, for the sequential fade.
Can someone can give me some guidance on how to add the inputs in the context of the posted sketch?

Code: [Select]
/*
  Fade
  This example shows how to fade an LED on pin 9
  using the analogWrite() function.

  The analogWrite() function uses PWM, so if  you
  want to change the pin you're using, be  sure to
  use another PWM capable pin. On most  Arduino,
  the PWM pins are identified with   a "~" sign,
  like ~3, ~5, ~6, ~9, ~10 and ~11.
*/

int brightness = 0;

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop()
{
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(5, brightness);
    delay(21); // Wait for 21 millisecond(s). Beginning of fade up sequence
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(6, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(7, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(8, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(9, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(10, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(11, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(12, brightness);
    delay(21); // Wait for 21 millisecond(s)
  }
 
  delay (3000); // delay 3 seconds before starting dimming sequence
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(5, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(6, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(7, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(8, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(9, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(10, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(11, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(12, brightness);
    delay(27); // Wait for 27 millisecond(s)
  }
  {delay (10000); // delay 10 seconds to test end of loop
  }
}




Thanks,
Pop_Motion

P.S. reason why I want to use these automotive COB LED arrays and not the serial LED strips is; I plan on routing a channel to recess the LED arrays into the bottom of the hand rail, and using some almost paper thin Ash wood veneer to use a diffuser. Because of the veneer, I'll need some powerful LEDs. 


gilshultz

#1
Oct 16, 2020, 02:37 am Last Edit: Oct 18, 2020, 09:46 pm by gilshultz
As I understand relays they are on and off devices and are not designed for PWM but I could be wrong.  I am currently switching about 75 amps using PWM and the BTS7960 43A High Power Motor Driver Modules. They can be wired as a high side or low side switch. I use them as high side because the RDSon is lower. I believe I have less then 15A on each. The result is they work good and do not get warm. The other thing I did was wire them appropriately and took into account the voltage drop from the feed line, and remember it is a two way trip. Since the wire was not that expensive I went to the next heavier gauge wire. To make it more interesting since it is a bridge there are two drivers per unit. They are available on ebay for less then $10.00 per unit. I hope this helps. It has been operating without a glitch for over three years.
This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

pop_motion

#2
Oct 16, 2020, 06:43 pm Last Edit: Oct 16, 2020, 06:45 pm by pop_motion
As I understand relays they are on and off devices and are not designed for PWM but I could be wrong.  I am currently switching about 75 amps using PWM and the BTS7960 43A High Power Motor Driver Module. They can be wired as a high side or low side switch. I use them as high side because the RDSon is lower. I believe I have less then 15A on each. The result is they work good and do not get warm. The other thing I did was wire them appropriately and took into account the voltage drop from the feed line, and remember it is a two way trip. Since the wire was not that expensive I went to the next heavier gauge wire. To make it more interesting since it is a bridge there are two drivers per unit. They are available on ebay for less then $10.00 per unit. I hope this helps. It has been operating without a glitch for over three years.
About relays and PWM, this is why I stated that I will be using solid state relays.
I received the LEDs today. From my testing, each one draws about 0.002 amps (could be 0.0002. I just did a quick test and am going off of memory).
I'll be using high strand count 12 gauge silicone insulated wire to make my runs, since I've had it laying around from when I was into building quadcopters. It's overkill, but to me, if it's not being used for something, then it might as well be garbage.
For the sketch, I've decided to just make the sequence to just omit the fade (basically trash the posted sketch, and write a new one), so it just turns on each LED in succession, then use a 1000uf capacitor and a resistor on each LED circuit to induce the fade ON/OFF affect.
I need to play around in TinkerCAD more with the settings to get an idea of what rating resistor and capacitors I need to get. 

pop_motion

The following is my sketch for turn the LEDs on in sequence, waiting 24 seconds and then turning them off in sequence.
It does not have the fading affect and doesn't use PWM. The fading will be done with a 3Kohm resistor and 470uf 16v capacitor inline with the LED circuit. 

Code: [Select]
int pir1 = A2;
int pir2 = A1;

int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;
int relay5 = 6;
int relay6 = 7;
int relay7 = 8;
int relay8 = 9;

void setup()
{
  pinMode (pir1, INPUT);
  pinMode (pir2, INPUT);
  pinMode (relay1, OUTPUT);
  pinMode (relay2, OUTPUT);
  pinMode (relay3, OUTPUT);
  pinMode (relay4, OUTPUT);
  pinMode (relay5, OUTPUT);
  pinMode (relay6, OUTPUT);
  pinMode (relay7, OUTPUT);
  pinMode (relay8, OUTPUT);
}
void loop() {
  if (digitalRead(pir1) == HIGH)
  {
    digitalWrite(2, HIGH);
    delay(750);
    digitalWrite(3, HIGH);
    delay(750);
    digitalWrite(4, HIGH);
    delay(750);
    digitalWrite(5, HIGH);
    delay(750);
    digitalWrite(6, HIGH);
    delay(750);
    digitalWrite(7, HIGH);
    delay(750);
    digitalWrite(8, HIGH);
    delay(750);
    digitalWrite(9, HIGH);
    delay(750);
    delay(24000);
    digitalWrite(2, LOW);
    delay(1250);
    digitalWrite(3, LOW);
    delay(1250);
    digitalWrite(4, LOW);
    delay(1250);
    digitalWrite(5, LOW);
    delay(1250);
    digitalWrite(6, LOW);
    delay(1250);
    digitalWrite(7, LOW);
    delay(1250);
    digitalWrite(8, LOW);
    delay(1250);
    digitalWrite(9, LOW);
    delay(1250);
  }
  if (digitalRead(pir2) == HIGH)
  {
    digitalWrite(9, HIGH);
    delay(750);
    digitalWrite(8, HIGH);
    delay(750);
    digitalWrite(7, HIGH);
    delay(750);
    digitalWrite(6, HIGH);
    delay(750);
    digitalWrite(5, HIGH);
    delay(750);
    digitalWrite(4, HIGH);
    delay(750);
    digitalWrite(3, HIGH);
    delay(750);
    digitalWrite(2, HIGH);
    delay(750);
    delay(100);
    digitalWrite(9, LOW);
    delay(1250);
    digitalWrite(8, LOW);
    delay(1250);
    digitalWrite(7, LOW);
    delay(1250);
    digitalWrite(6, LOW);
    delay(1250);
    digitalWrite(5, LOW);
    delay(1250);
    digitalWrite(4, LOW);
    delay(1250);
    digitalWrite(3, LOW);
    delay(1250);
    digitalWrite(2, LOW);
    delay(1250);
  }
 
}   



pop_motion

#4
Oct 24, 2020, 12:05 am Last Edit: Oct 24, 2020, 12:07 am by pop_motion
I've tested the code and components for what I'm planning, and it doesn't seem to work as intended.

So, I basically bashed the PIR parts of the code with the code found here (just giving credit).
This is what I was going for, with PWM and not having to used capacitors

https://forum.arduino.cc/index.php?topic=315309.0

This is the code I came up with. Seems to work in simulation, and loading it into a mega2560 pro with solid state relay board (using the smd LED that are on the relay board). Just need to go home throw it on the test bench.

EDIT: well, the sketch is too large for me to post here.

wildbill


pop_motion

I deleted all the comments that were in the fade sketch that I used.
Added 3 more LEDs (15 LED in total)

Also, the solid state relay boards that I got don't seem to want to disable the relays after the the sequence is finished, so I switched to using some N channel mosfets.

LED signal pins are 2 through 13, 44 through 46


pop_motion

#7
Oct 27, 2020, 07:24 pm Last Edit: Oct 27, 2020, 07:30 pm by pop_motion
I ran a simulation in tinkerCAD with only 12 LED with the sketch posted, because they don't have the arduino mega as a component. They only have the arduino uno.

It seemed to run as intended.

BUT when I loaded it into my arduino mega 2560 pro, it started to run it with some odd issues.
With PIR sensors connected, it would run as if they were constantly triggering, even after adjusting sensitivity and time delay on the sensors.

disconnecting the sensors, and triggering the sequence by shorting A1 or A2, it would work as intended, but would trigger randomly at times.
I was thinking that there maybe some noise in the wires going to the sensors. Replaced wires with shorter ones, and still had the issue.

Looking on other PIR example sketches, I added the following after the "int pir2 = A2" entry
int pirState = LOW;

It seems to be all working now.
I assume "pirState" is in a library that is loaded by default.

The attached sketch has the new entry, and has pir2 using pin A10.

EDIT: Any suggestions on how to simplify anything and/or anything you would have done differently?
Just curious.

Go Up