Relay with arduino, string lighting

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Hi.
Can some one please clarify, before purchasing? Much appreciated.
Ok using the nano, after weeks of figuring out (NooB).
Figured the sketch out to fade 2 string of LED`s (D9 and D10) massive achievement for me.
Ok now need independent power supply for the Arduino (switching to the Uno) and the string lights (5v 2a)
The only way i can see this being done is using a relay. Trying on a 2 channel remote relay KGS-B20.
But dont think this will work (not figured out the wiring).
Would i need something different, and still get the string LEDS to fade etc?
Thank you for reading.
 

dl324

Joined Mar 30, 2015
16,846
Would i need something different, and still get the string LEDS to fade etc?
  1. How are you fading the LEDs now?
  2. What is the current required for the LEDs?
  3. Are you switching high side or low side?
A schematic of what you've tried would be helpful.
 

Reloadron

Joined Jan 15, 2015
7,501
Using an Arduino UNO I have used RGB LED strings with the following circuit.

LED RGB MOSFET DRIVEN.png

The LED strings were common anode and the MOSFETs were FQP30N06L which are Logic Level MOSFETs. The drawing leaves out the "L" on MOSFET part number. The left is how each section of each string is wired. I used PWM for fade in and fade out as well as color selections. I used low side switching.

So per the above post those questions need answered as to your setup.
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
  1. How are you fading the LEDs now?
  2. What is the current required for the LEDs?
  3. Are you switching high side or low side?
A schematic of what you've tried would be helpful.
Hi, thank you for the reply.
Unsure of the current of the String LEDS unfortunately, just what picked up cheap £1.49 20 LED battery operated string lights (3V) but had test to 5.5v, no issues.
Unable to use RGB`s as too far apart, so opting for
5m 50 LEDs Battery Silver Copper Wire Fairy String Lights Firefly Lights Halloween Lights DIY Christmas Decoration for Bedroom Wedding Party Festival Outdoor (Red) Which are easy tgo bend to shape..

High low side? as say a noob my friend.
A schematic, not as yet sorry. Project, made a pyromist fire, (optymyst) seriously, if didnt know looks so real. (500mmx250MM)
So for the logs and base wanted a red glow effect. placed a few red 5mm leds on a log, covered and sprayed, gives that slight red glow lol.
Also needing to incorporate a MP3 player module, with just volume up and down, sd card with fire crackle sound.
Initially was looking to buy but at £1300, total what looking at £120.
Just ordered
ELEGOO Relay Module 4 Channel DC 5V with Optocoupler for Arduino UNO R3 MEGA Project 1280 DSP ARM PIC AVR STM32 Raspberry Pi. From Amazon uk.
Again from amazon something like: YX5200 DFPlayer Mini MP3 Player Module MP3 Voice Decode Board Supporting TF Card U-Disk IO/Serial Port/AD for Arduino.
Best wishes.. :)
 

Reloadron

Joined Jan 15, 2015
7,501
Back to your original post you mention wanting to fade in and out the LED string. Using an Arduino NANO for example this is done with a PWM (Pulse Width Modulation) signal from any of your digital pins which will handle PWM, on the NANO that is digital pins 3, 5, 6, 9, 10 and 11 so using digital pins 9 and 10 will do just fine. If you want fade effects with a 5 volt 2 amp string you use a MOSFET to drive the LED string. As to high side or low side switching it is just a matter of if you are switching the + or - side of your LED string. Using an Arduino UNO low side switching is the popular way to go. In the drawing I used yes, it was for RGB but any single channel will work for example just Red LEDs. I guess I don't see where a relay module fits into the scheme of things?

As to your audio any number of modules will work. Just put a crackling fire file on it and run a loop. Trigger it with your Arduino or however you wish.

Ron
 

BobTPH

Joined Jun 5, 2013
8,813
Ok now need independent power supply for the Arduino (switching to the Uno) and the string lights (5v 2a)
The only way i can see this being done is using a relay. Trying on a 2 channel remote relay KGS-B20.
But dont think this will work (not figured out the wiring).
To use separate power supplies, all you need is two power supplies with their grounds connected. Can’t even imagine why you think a relay is needed.

Bob
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
To use separate power supplies, all you need is two power supplies with their grounds connected. Can’t even imagine why you think a relay is needed.

Bob
Hi, Thank you for the time to answer. Was just looking on youtube, seen many references using relays.
Dont quite get what saying sorry. If join both grounds of the psu to lights and arduino? then one positive to arduino other to lights? so where will get signal from, as only 2 wires? Would the negative from light go to D pin? negative from arduino, go also to its gnd?
Regards
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Back to your original post you mention wanting to fade in and out the LED string. Using an Arduino NANO for example this is done with a PWM (Pulse Width Modulation) signal from any of your digital pins which will handle PWM, on the NANO that is digital pins 3, 5, 6, 9, 10 and 11 so using digital pins 9 and 10 will do just fine. If you want fade effects with a 5 volt 2 amp string you use a MOSFET to drive the LED string. As to high side or low side switching it is just a matter of if you are switching the + or - side of your LED string. Using an Arduino UNO low side switching is the popular way to go. In the drawing I used yes, it was for RGB but any single channel will work for example just Red LEDs. I guess I don't see where a relay module fits into the scheme of things?

As to your audio any number of modules will work. Just put a crackling fire file on it and run a loop. Trigger it with your Arduino or however you wish.

Ron
Hi Ron, thanks for time out.
Quite correct. used D9 & D10. Regarding mosfets, again did look into this, but as a beginner was just a mine field lol. Unsure in which to get, hence opted for the https://www.amazon.co.uk/gp/product/B06XK6HCQC/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&th=1
4 Channel DC 5V with Optocoupler for Arduino.
This was the sketch im using, using lights on D9 and D10m, worked great..
Best Wishes...

C:
int led_1 = 9; // the PWM pin the LED is attached to
int led_2 = 10;
int brightness_1 = 0;    // how bright the LED is
int brightness_2 = 100;

int fadeAmount_1 = 5;    // how many points to fade the LED by
int fadeAmount_2 = 5;

void setup() {
  pinMode(led_1, OUTPUT);
  pinMode(led_2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led_1, brightness_1);
  analogWrite(led_2, brightness_2);

  // change the brightness for next time through the loop:
  brightness_1 = brightness_1 + fadeAmount_1;
brightness_2 = brightness_2 + fadeAmount_2;
  // reverse the direction of the fading at the ends of the fade:
if (brightness_1 == 0 || brightness_1 == 255) {
    fadeAmount_1 = -fadeAmount_1;
}else if (brightness_2 == 0 || brightness_2 == 255) {
    fadeAmount_2 = -fadeAmount_2;
  }
  // wait for 90 milliseconds to see the dimming effect
  delay(30);
}
Mod edit: code tags - JohnInTX
 
Last edited by a moderator:

BobTPH

Joined Jun 5, 2013
8,813
Dont quite get what saying sorry. If join both grounds of the psu to lights and arduino? then one positive to arduino other to lights?
Exactly.
so where will get signal from, as only 2 wires? Would the negative from light go to D pin? negative from arduino, go also to its gnd?
The grounds are now the same. You only need one wire for the signal, going from the Arduino to the MOSFET gate, just the same as your single supply circuit.

Bob
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Exactly.

The grounds are now the same. You only need one wire for the signal, going from the Arduino to the MOSFET gate, just the same as your single supply circuit.

Bob
Ahh ok, as mentioned hence rerlay than mosfet was unsure what to get, mine filed lol. Ohms law and all that :)
 

Reloadron

Joined Jan 15, 2015
7,501
BobTPH covered the wiring pretty much.

Why a MOSFET? Well you want a fade in and out on your LEDs. While relay modules like the one you linked to they are pretty much On or Off and will not work for PWM. So for PWM and a LED fade in and out we need a transistor. This is where the MOSFET figures into things. Since your voltage out on the digital pins is about 5.0 volts you need a logic level MOSFET or simply a MOSFET we can turn on fully with a 5.0 volt gate signal.

Here is what things will look like:
LED PWM Example.png

D1 and D2 are merely there to represent your LED strings. The + (POS) side of the LED strings is connected to your + 5.0 volt supply. M1 and M2 are both logic level MOSFETs acting as a switch to drive your LEDs with PWM. Since a MOSFET gate is a capacitive input R1 and R2 are there to make sure when your digital signals go low the MOSFETs turn off and the gates are not floating. So on the MOSFETs I included the Source is GND, the Gate are your digital signals from pins 9 & 10 of your Arduino and the Drain connects to the low (negative) side of your LED strings. FQP30N06L data sheet. The data sheet will show you the pin identifications. Don't let it worry or confuse you. These MOSFETs cost about a buck each ($1.00 USD).

The only quirk I see in your code is:
Code:
// wait for 90 milliseconds to see the dimming effect
delay(30);
You call out a 90 milli-sec delay but use a 30 milli-sec delay which is no real problem. :)

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Ahh well the relay dont work on fade for string lights, Guess lesson learned, only turns on and off, so in a blink mode :-(
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
BobTPH covered the wiring pretty much.

Why a MOSFET? Well you want a fade in and out on your LEDs. While relay modules like the one you linked to they are pretty much On or Off and will not work for PWM. So for PWM and a LED fade in and out we need a transistor. This is where the MOSFET figures into things. Since your voltage out on the digital pins is about 5.0 volts you need a logic level MOSFET or simply a MOSFET we can turn on fully with a 5.0 volt gate signal.

Here is what things will look like:
View attachment 252511

D1 and D2 are merely there to represent your LED strings. The + (POS) side of the LED strings is connected to your + 5.0 volt supply. M1 and M2 are both logic level MOSFETs acting as a switch to drive your LEDs with PWM. Since a MOSFET gate is a capacitive input R1 and R2 are there to make sure when your digital signals go low the MOSFETs turn off and the gates are not floating. So on the MOSFETs I included the Source is GND, the Gate are your digital signals from pins 9 & 10 of your Arduino and the Drain connects to the low (negative) side of your LED strings. FQP30N06L data sheet. The data sheet will show you the pin identifications. Don't let it worry or confuse you. These MOSFETs cost about a buck each ($1.00 USD).

The only quirk I see in your code is:
Code:
// wait for 90 milliseconds to see the dimming effect
delay(30);
You call out a 90 milli-sec delay but use a 30 milli-sec delay which is no real problem. :)

Ron
HAHAHA No getting past you lot lol. Yea was a before edit typo.. :)
Yes correct with relay, but lesson learned, plus awful click.
Ok think also scrap idea on string led`s. As say this is just experiment. But with strings just on fast blink looks real impressive.
So opting for say:
Red LED`s x 100 Forward voltage: 1.8 - 2.2V DC
Forward Current: 20mA so 2000mA. 2amps?
Depending on the psu for led`s 12v (need resistor) 4a overkill?
So on a LED calculator using 6v You will need 33 x 1 ohm 1/8 watt and 1 x 200 ohm 1/8 watt resistors..
But then N channel mosfet looked at the IRF530N as with most mosfet datasheets. Just another foreign language.
Again much appreciated for the time means a lot...
 
Last edited:

Reloadron

Joined Jan 15, 2015
7,501
OK, so here is how LEDs play out. We work from the Forward Voltage and Forward Current keeping in mind the LED is a current driven device. Typil forward voltages run close to this:
Typically, the forward voltage of an LED is between 1.8 and 3.3 volts. It varies by the color of the LED. A red LED typically drops around 1.7 to 2.0 volts, but since both voltage drop and light frequency increase with band gap, a blue LED may drop around 3 to 3.3 volts
.
The above taken from here. You will hear quite a bit of "about", "approximately" and similar because the LED is not exactly a precise semiconductor in large bulk mass produced lots unless you are using very good ones which include a data sheet. So for a generic bulk LED red in color we figure the series resistance like this: Vsupply - Vled / forward current. You also really don't want to place more then three in series. So yes in a parallel circuit with each LED having a 20 mA current 100 LEDs would be 100 * 0.020 amp = 2.0 Amps and figure with a 2.0 amp total current you really want a 3.0 amp supply of the correct voltage based on a series resistor on each LED. A simple approach would be placing three red LEDs in series so we get Vfwd = 2.0 volts * 3 = 6.0 Volts. With a 9.0 volt supply we get 9.0 - 6.0 = 3.0 volts / 20 mA = 150 Ohms and the current will be 20 mA so the power = I^2 * R so 0.0004 * 150 = a 1/8th watt resistor will do or a 1/4 watt common resistor. This being merely an example. Since all red LEDs are not created equally any of the three in this example may glow a little brighter, normally not noticeable. Anyway, you get the idea. :)

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
This is a link to a test run... Having the base and faux fake burning log effect to create, hence red led implementation. Initial test: https://1drv.ms/v/s!AqpEdYPOs7XYyGrk4XWUbC9JNFiD?e=tWXGUJ
Lights out full scale. Base and fake burning embers to create.
https://1drv.ms/v/s!AqpEdYPOs7XYyGyRMbWWNy3RJpeL
having tested few Red LED`s unless obviously stood on end any angle looses luminosity.
So may have to incorporate the red 5050 LED strip lights, as these can be cut at every 3. String lights not bright enough.

Much appreciated to those have taken time out for input. Appreciated.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
18,176
Hi, Thank you for the time to answer. Was just looking on youtube, seen many references using relays.
Dont quite get what saying sorry. If join both grounds of the psu to lights and arduino? then one positive to arduino other to lights? so where will get signal from, as only 2 wires? Would the negative from light go to D pin? negative from arduino, go also to its gnd?
Regards
Please understand that at least half of what you see on yootoob is fiction and faked. Wrong data, circuits shown not similar to what is shown in the video part, and just plain incorrect information.
 

Reloadron

Joined Jan 15, 2015
7,501
My brother works with stage lighting and sound. Amazing what can be done with filter materials. One year he created my mother's bay window into a starry night with twinkling stars using gel filter material. Pretty cool effects and actually very inexpensive.

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
My brother works with stage lighting and sound. Amazing what can be done with filter materials. One year he created my mother's bay window into a starry night with twinkling stars using gel filter material. Pretty cool effects and actually very inexpensive.

Ron
Aww sounds brilliant. LoL heads absolute battered over this week lol. Know with the programable led strips no mosfet needed. But with standard single colour, then to get the fade needing mosfet. This where headache begins. Hundreds different types.
Example if looking at this
https://www.amazon.co.uk/YUNBO-Wate...lja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ&th=1

Number of Lights‎300
Maximum Compatible Wattage‎35 Watts

Thanks Ron, Sorry to be a pain mate, but really wanting this to work lol,,,
 

Reloadron

Joined Jan 15, 2015
7,501
First, you are not a pain. I know what a pain is, I have an Ex Wife. :)

Now moving right along you have a 12 volt strand of lights. We know the max power is 35 watts. Let's say 36 watts, so 36 watts / 12 volts = 3.0 Amps. So lets allow some overhead and 12 volt 5.0 amp power supplies are inexpensive. I would look for a 12 volt 5.0 amp power supply. Now for a MOSFET there are dozens which will work but all we need is a MOSFET we will use as a switch. We also want it to turn on fully with 5.0 volts on the gate. This is where I would use a FQP30N06L because it can easily handle 12 volts at 3.0 amps. Like I posted earlier as to a schematic.

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
First, you are not a pain. I know what a pain is, I have an Ex Wife. :)

Now moving right along you have a 12 volt strand of lights. We know the max power is 35 watts. Let's say 36 watts, so 36 watts / 12 volts = 3.0 Amps. So lets allow some overhead and 12 volt 5.0 amp power supplies are inexpensive. I would look for a 12 volt 5.0 amp power supply. Now for a MOSFET there are dozens which will work but all we need is a MOSFET we will use as a switch. We also want it to turn on fully with 5.0 volts on the gate. This is where I would use a FQP30N06L because it can easily handle 12 volts at 3.0 amps. Like I posted earlier as to a schematic.

Sorry to hear you not together. Not wanting to go down personal why`s..
You are a legend my friend thank you so much, appreciated.
Just when see something, get teeth into just gotta do lol.
Being a magician last 4 yrs (again something else never thought could do) Also managed to gain the balls to audition for local magic circle. Wish done yrs ago life changer.
There are items called spirit bells. Bells ring on their own. not my thing to perform, but just had to make, no help in this field.
Stupid prices.
The orig was just a plain bell, without the ending. Also made an authentic 1980`s box with original metal work.
https://1drv.ms/v/s!AqpEdYPOs7XYw060e7OEYTPQCHkg
This one taken months to make, unlike original, this can be fully examined.
Again seen just had to build lol.
https://1drv.ms/v/s!AqpEdYPOs7XYyG1swqFzd2OpFMm-
Have a great day my friend....
 
Top