Relay with arduino, string lighting

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Just trying to get head round data sheets lol. so much to digest, go off on other tangents lol. hats off to you in this field lol...
 

Reloadron

Joined Jan 15, 2015
7,501
Reading and understanding data sheets is a steep learning curve. Many of us have put beanies and weenies on a table for over 40 years. This is all new to a hobby enthusiast or even those starting a career. Rome wasn't built in a day. :)

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Reading and understanding data sheets is a steep learning curve. Many of us have put beanies and weenies on a table for over 40 years. This is all new to a hobby enthusiast or even those starting a career. Rome wasn't built in a day. :)

Ron
HAHAHA yup. Why not make it simple.
Max voltage/amps, gate opening voltage.
Sorted lol.
 

Reloadron

Joined Jan 15, 2015
7,501
Good start, then comes things like on / off resistance and a bunch of temperature curves and other things. However, in the beginning the basics are often good enough for On / Off applications.

Ron
 

BobTPH

Joined Jun 5, 2013
8,813
HAHAHA yup. Why not make it simple.
Max voltage/amps, gate opening voltage.
Sorted lol.
Because it is not simple.

The max volts and amps are almost always in the first section, "absolute maximums". But you should stay far away from these values if you want reliable operation.

There is no "gate on voltage". The MOSFET comes on gradually beginning at Vgsth - the threshold voltage, which beginners usually misinterpret as the ON voltage. It is not, it is the voltage at which a tiny current, often 250uA flows. The on resistance continues to decline with increased gate voltage, typically all the way up to 10V. They usually do not give figures for above that.

Bob
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
YAY ok Came yesterday ws2812b 300 led`s, works brilliant. So OMG this is another language lol Fastled.
Will battle on. If anyone willing to help :) Again be much appreciated.
Cheers
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
When you have questions just ask. :)

Ron
Appreciated Ron. Guess was being very naïve. Sort of go the idea the basic blink fade example, as well as added few more LEDs. But this WS2B just total mind blowing. Spent time just going through fastled examples, altering numbers see if get colours wanting, and pattern. Just nightmare...
 

BobTPH

Joined Jun 5, 2013
8,813
You are not going to learn how to use WS2812B by changing numbers in an example randomly.

Do you know how they work? Do you know, for instance, that each LED on the strip is given 24 bits of data, 8 each for red, green and blue?

Bob
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Ha Just dont really have the months to figure out to be honest, been on a project for a month, just to give some more realism, adding the Strips. As say was so naive, when never touched coding, baring playing with the simple led fade blink lol.. Appreciate can take months/yrs to figure, hats off to you guys. But stuck with the strip, hence just changing numbers, hoping may find something im after. When have more time will put effort in, as its a whole new world. But trying to figure as go along...
Appreciate your time to comment.
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Hi.
Ok found this and got the colour (red) wanted.
But tried altering the flicker numbers, not getting much. This is the type of thig lookingat, also with more orange?
Thanks

C:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN 7
//  The overall fire brightness
//  (this can affect both color levels and power consumption)
int brightness = 255;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
// For the ultimate NeoPixel guide, check out:
// [URL]https://learn.adafruit.com/adafruit-neopixel-uberguide/overview[/URL]
void setup() {
  strip.begin();
  strip.setBrightness(brightness);
  strip.show(); // Initialize all pixels to 'off'
}
void loop() {
  //  Uncomment one of these RGB (Red, Green, Blue) values to
  //  set the base color of the flame.  The color will flickr
  //  based on the initial base color
 
  //  Regular (orange) flame:
    int r = 226, g = 1, b = 0;
  //  Purple flame:
  //  int r = 158, g = 8, b = 148;
  //  Green flame:
  //int r = 74, g = 150, b = 12;
  //  Flicker, based on our initial RGB values
  for(int i=0; i<strip.numPixels(); i++) {
    int flicker = random(12,55);
    int r1 = r-flicker;
    int g1 = g-flicker;
    int b1 = b-flicker;
    if(g1<0) g1=0;
    if(r1<0) r1=0;
    if(b1<0) b1=0;
    strip.setPixelColor(i,r1,g1, b1);
  }
  strip.show();
  //  Adjust the delay here, if you'd like.  Right now, it randomizes the
  //  color switch delay to give a sense of realism
  delay(random(5,13));
}
Moderators note : used code tags
 
Last edited by a moderator:

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Hi.
Ok found this and got the colour (red) wanted.
But tried altering the flicker numbers, not getting much. This is the type of thig lookingat, also with more orange?
Thanks

C:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
#define PIN 7
//  The overall fire brightness
//  (this can affect both color levels and power consumption)
int brightness = 255;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
// For the ultimate NeoPixel guide, check out:
// [URL]https://learn.adafruit.com/adafruit-neopixel-uberguide/overview[/URL]
void setup() {
  strip.begin();
  strip.setBrightness(brightness);
  strip.show(); // Initialize all pixels to 'off'
}
void loop() {
  //  Uncomment one of these RGB (Red, Green, Blue) values to
  //  set the base color of the flame.  The color will flickr
  //  based on the initial base color

  //  Regular (orange) flame:
    int r = 226, g = 1, b = 0;
  //  Purple flame:
  //  int r = 158, g = 8, b = 148;
  //  Green flame:
  //int r = 74, g = 150, b = 12;
  //  Flicker, based on our initial RGB values
  for(int i=0; i<strip.numPixels(); i++) {
    int flicker = random(12,55);
    int r1 = r-flicker;
    int g1 = g-flicker;
    int b1 = b-flicker;
    if(g1<0) g1=0;
    if(r1<0) r1=0;
    if(b1<0) b1=0;
    strip.setPixelColor(i,r1,g1, b1);
  }
  strip.show();
  //  Adjust the delay here, if you'd like.  Right now, it randomizes the
  //  color switch delay to give a sense of realism
  delay(random(5,13));
}
This is whats wanting but with flicker. Don like sound of last could burn out strip..

C:
#include "FastLED.h"
#define NUM_LEDS 40 // # of LEDS in the strip
CRGB leds[NUM_LEDS];
#define PIN 7 // Output Pin to Data Line on Strip
#define COLOR_ORDER GRB  // I had to change this for my strip if your color is off then you know.
int fadeAmount = 5;  // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
int brightness = 0;
void setup()
{
  FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop()
{
   for(int i = 0; i < NUM_LEDS; i++ )
   {
   leds[I].setRGB(255,30,0);  // Set Color HERE!!!
   leds[I].fadeLightBy(brightness);
  }
  FastLED.show();
  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade: 
  if(brightness == 0 || brightness == 255)
  {
    fadeAmount = -fadeAmount ; 
  }    
  delay(89); 
}
Moderators note : used code tags
 
Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
9,156
@Brinamo

Please learn how to post code in between code tags. The ellipsis icon has an option to insert code tags. Which formats your post for easy reading and leaves the cursor between the tags, making it easy for you to paste your code.

DFF04EB3-6B47-4317-ABBF-54F951E69876.jpeg

Code tags look like this:

88B80C4C-D134-4AC4-84FE-C225856C3F6B.jpeg
 

Reloadron

Joined Jan 15, 2015
7,501
The WS2812 is one I have never used but I did look at a code sample here on this page. Nice thing is the WS 2812 and other NeoPixel schemes are one wire programmable. I am sure by now you are familiar with the 0 through 255 scheme. If by now you haven't done so do a Google of "color picker". Remember you want a RGB scheme to get the numbers you want.

The following was originally written for a RGB LED using 3 wires but you may find a similiarity:

Code:
int led1 = 9;           // the PWM pins the LED is attached to
int led2 = 10;
int led3 = 11;
int brightness1 = 0;    // how bright the LED is
int brightness2 = 0;    // how bright the LED is
int brightness3 = 0;    // how bright the LED is
int fadeAmount = 3;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9, 10, and 11 to be an output:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 7, 8, and 9:
  analogWrite(led1, brightness1);
  analogWrite(led2, brightness2);
  analogWrite(led3, brightness3);

  // change the brightness for next time through the loop:
  brightness1 = brightness1 + fadeAmount;
  brightness2 = brightness2 + fadeAmount;
  brightness3 = brightness3 + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness1 <= 0 || brightness1 >= 255) {
    fadeAmount = -fadeAmount;
  if (brightness2 <= 0 || brightness2 >= 255) {
    fadeAmount = -fadeAmount;
  if (brightness3 <= 0 || brightness3 >= 255) {
    fadeAmount = -fadeAmount;
  }
Not sure how this may help with a one wire LED control

Ron
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
The WS2812 is one I have never used but I did look at a code sample here on this page. Nice thing is the WS 2812 and other NeoPixel schemes are one wire programmable. I am sure by now you are familiar with the 0 through 255 scheme. If by now you haven't done so do a Google of "color picker". Remember you want a RGB scheme to get the numbers you want.

The following was originally written for a RGB LED using 3 wires but you may find a similiarity:

Code:
int led1 = 9;           // the PWM pins the LED is attached to
int led2 = 10;
int led3 = 11;
int brightness1 = 0;    // how bright the LED is
int brightness2 = 0;    // how bright the LED is
int brightness3 = 0;    // how bright the LED is
int fadeAmount = 3;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9, 10, and 11 to be an output:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 7, 8, and 9:
  analogWrite(led1, brightness1);
  analogWrite(led2, brightness2);
  analogWrite(led3, brightness3);

  // change the brightness for next time through the loop:
  brightness1 = brightness1 + fadeAmount;
  brightness2 = brightness2 + fadeAmount;
  brightness3 = brightness3 + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness1 <= 0 || brightness1 >= 255) {
    fadeAmount = -fadeAmount;
  if (brightness2 <= 0 || brightness2 >= 255) {
    fadeAmount = -fadeAmount;
  if (brightness3 <= 0 || brightness3 >= 255) {
    fadeAmount = -fadeAmount;
  }
Not sure how this may help with a one wire LED control

Ron
Much appreciated trying to help Ron, thank you.
Only using the one program wire.
so all wanting really, wanting is random flicker between colours 255, 0, 0 and 255, 25 , 0
This is not done with arduino or fastled, but its the type effect looking at, skip towards end for the effect.
Still having a hunt and trying to get head round it lol.
Know its easy for someone to say i want this will you do. Sorry for that, Its not how i usually work lol. Just desperate to finish this project..
thanks again...
best wishes
 
Last edited:

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Found this, messed with numbers, but only 1 led works. orig 1 light flicker youtube.
Total lost, tried adding, from 8-40 leds, but just the 1. thanks
flicker:
#include <FastLED.h>
#define NUM_LEDS
#define LED_PIN 7
#define CLOCK_PIN 11
#define BRIGHTNESS 255




//===============================================================
CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 800);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear();
  FastLED.show();

}

void loop() {
leds[0] = CHSV( random8(255,15), random8(255,255), random8(255,255));

FastLED.show();
 

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Found this, messed with numbers, but only 1 led works. orig 1 light flicker youtube.
Total lost, tried adding, from 8-40 leds, but just the 1. thanks
flicker:
#include <FastLED.h>
#define NUM_LEDS
#define LED_PIN 7
#define CLOCK_PIN 11
#define BRIGHTNESS 255




//===============================================================
CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 800);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear();
  FastLED.show();

}

void loop() {
leds[0] = CHSV( random8(255,15), random8(255,255), random8(255,255));

FastLED.show();
Alls good, finally after days hunting, found a sketch, ok flicker and colours we not right, but changed them. Easy enough to change, led count, colours, and flicker amount. Perfect :)
 
Last edited:

Thread Starter

Brinamo

Joined Mar 29, 2021
46
Code:
/*

*/
#include <Adafruit_NeoPixel.h>
#define PIN 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(44, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Serial.begin(9600);
  randomSeed(analogRead(100));

  for (int i=0;i<=strip.numPixels();i++){
    strip.setPixelColor(i, strip.Color(255,   0,   0));
  }
}

void loop() {
  int i=random(1,strip.numPixels());
  int c=random(1,7);
  if (c==0){
    strip.setPixelColor(i, strip.Color(255,5,0));
  }
  else if (c==1){
    strip.setPixelColor(i, strip.Color(255,0,0));
  } else {
    strip.setPixelColor(i, strip.Color(15,0,0));
  }
  //Serial.println(c);
  strip.show();
  delay(random(5,22));
}
 
Top