Combination Pulsing and Steady LED circuit needed

Thread Starter

spopop

Joined Jan 25, 2017
10
Hi all, I am trying to make a small project consisting of 7 white LED (standard), powered by either a 9v or 3v battery source. When switched ON the LEDs would flash independently and randomly for about 30 seconds, and then all stay ON for another 30 seconds, and then repeat. I would rather do this without some programmable unit like Arduino, but if thats not possible then how about a 3-way manual switch -- position 1 = flash random, position 2 = ON steady, position 3 = OFF. Thanks for you help.
 

eetech00

Joined Jun 8, 2013
3,961
You could use a CD4060B and some additional logic parts to accomplish that...I guess it depends on how random the flash needs to be.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,163
If the randomness includes an indeterminate number of LEDs that can be on at the same time, you might investigate a PRNG made with a LINEAR SHIFT REGISTER.

Your simple solution has a paradox. One state, all LEDs must be controlled together. In the other state, each LED must be controlled individually.

Unfortunately, your aversion to microprocessors is unfortunate. When I read your description. I said perfect for a uC.
 

Thread Starter

spopop

Joined Jan 25, 2017
10
If the randomness includes an indeterminate number of LEDs that can be on at the same time, you might investigate a PRNG made with a LINEAR SHIFT REGISTER.

Your simple solution has a paradox. One state, all LEDs must be controlled together. In the other state, each LED must be controlled individually.

Unfortunately, your aversion to microprocessors is unfortunate. When I read your description. I said perfect for a uC.

I guess I could reconsider the micro processor, but its been many years since I tried programming, and I don't have any of the kits or software, thats why I was hoping for a simpler solution. If I did consider it, what is the board of choice now-a-days?
 

Bernard

Joined Aug 7, 2008
5,784
To see if this random LED pattern is to your liking, scroll down to Connect With Us- You Tube- in Search box put Jack Bernard Fireflies. Uses 2 555's & 4017. Add 4060 for timing, & some gates might do it.
 
Last edited:

Thread Starter

spopop

Joined Jan 25, 2017
10
To see if this random LED pattern is to your liking, scroll down to Connect With Us- You Tube- in Search box put Jack Bernard Fireflies. Uses 2 555's & 4017. Add 4060 for timing, & some gates might do it.
Thanks for the suggestion, I checked it out and it is sort of what I want , but not quite. I think I will take the suggestion of a programmable unit, and if anyone can suggest their favorite or popular model I would appreciate it.
 

djsfantasi

Joined Apr 11, 2010
9,163
First, what do you need?

Seven pins for output.

Maybe another pin as an input to turn the LEDs on off.

I use Arduino and compatible boards. There are likely other options. The Sparkfun Trinket is too small for your needs because it cannot support more than 5 pins . The standard Arduino UNO would work.

I am working on some sample code.
 

Thread Starter

spopop

Joined Jan 25, 2017
10
First, what do you need?

Seven pins for output.

Maybe another pin as an input to turn the LEDs on off.

I use Arduino and compatible boards. There are likely other options. The Sparkfun Trinket is too small for your needs because it cannot support more than 5 pins . The standard Arduino UNO would work.

I am working on some sample code.

Hey thats great!! I just ordered the Arduino Mega2560 kit, so any help you can get me would be great... I have modified my goal a bit and here they are:
7 - LEDs representing stars... so they should be constantly ON but with a little twinkle on random occasion
2 inputs -- one is probably a master on switch, second one might be a motion detector that would activate the LEDs
 

Bernard

Joined Aug 7, 2008
5,784
Can you define a twinkle, a brief outage or several brief outages together ?
Visualize Fireflies inverted, almost always on with brief random outages. Close ?
 

Thread Starter

spopop

Joined Jan 25, 2017
10
Can you define a twinkle, a brief outage or several brief outages together ?
Visualize Fireflies inverted, almost always on with brief random outages. Close ?
I would define a twinkle as -- always ON but with intermittent and brief reductions in brightness or intensity. But never fully dark.
 

djsfantasi

Joined Apr 11, 2010
9,163
Ok, the Mega it is. The Uno only has 6 PWM pins. The Mega has 15. More than enough.

More than enough what? As you describe it, a twinkle is intermediate and brief dimming of an LED. To do this, you are probably going to need pulse width modulation or PWM to control the brightness of the LEDs.

I will (sometime) attach a sketch that provides the framework for this. However, I recommend you expirement with one LED and your Mega. There is a sample sketch included when you download the IDE, called Fading or something like that, which demonstrates this technique.

Check out this link.

One problem may be that this framework will randomly "twinkle" an LED. However two or more LEDs will not do so simultaneously. Is this an issue?

It can be done. You can program parsllel execution in a sequential program. I can get into that later. If you are curious, here is my article on the technique. If you are not a coder, it may be difficult to grok.
 

djsfantasi

Joined Apr 11, 2010
9,163
Ok, this sample sketch is what I promised. There are some comments, but not a lot.

The Arduino site provides many resources. Like a program reference guide. You can look up the keywords I used there.

Without further ado...

Code:
/*

Blinkies, a structural framework


pin numbers will work for the Uno and Mega

a Mega is required to use PWM (the UNO does

not have enough PWM pins for this application

*/


#define numberLEDs 7


// connect your LEDs to these pins

int const  pinLED[numberLEDs] = {2, 3, 4, 5, 6, 7, 8};

// connect your switch to this pin

int const Switch = 9;

// connect your motion sensor to this pin

int const Motion = 10;

// the following line defines that a twinkle will occur [URL='http://forum.allaboutcircuits.com/x-apple-data-detectors://0']3/10th[/URL] of the time

int const probabilityTwinkle = 3;


// the setup function runs once when you press reset or power the board

void setup() {


  // initialize pins to drive LEDs as an output.

  for (int myPin = 1; myPin++; myPin <= numberLEDs) {

  pinMode(myPin, OUTPUT);

  }


// Define the pin used to switch on/off

pinMode(Switch, INPUT);


// randomize function

randomSeed(analogRead(0));


}


// the loop function runs over and over again forever

void loop() {

  int OnOff;

  long endLoop;

  OnOff = digitalRead(Switch);


  while (OnOff) {

  endLoop = millis() + 30000;

  while (millis() < endLoop) {

  for (int myPin = 1; myPin++; myPin <= numberLEDs) {

  if (random(0,10) < probabilityTwinkle)  {

  twinkle(pinLED[myPin]);

  }

  }

  }

  }

}


void twinkle(int whichPin) {

  //insert your "twinkle" code here

}
 

k7elp60

Joined Nov 4, 2008
562
Here is a circuit I developed a few years ago. The LED's flash semi random. It uses a CD4051. If pin 8 is connected to Vdd all the LED's would be off. A manual switch could be connected to connect pin 8 to Vss or Vdd, or you could set up a 555 timer to be a astable oscillator at 30 seconds, connect pin 3 of the 555 to pin 8 of the 4051 and you would be done. Here is the schematic of the ckt I described.My ckt has 2 LED's in series and R4 determins the LED Current. Since you are using only 7 LED's just eliminate the LED's connected to pin 13.
HOLIDAY SCHEMATIC.jpg
 

Thread Starter

spopop

Joined Jan 25, 2017
10
Ok, this sample sketch is what I promised. There are some comments, but not a lot.

The Arduino site provides many resources. Like a program reference guide. You can look up the keywords I used there.

Without further ado...

Code:
/*

Blinkies, a structural framework


pin numbers will work for the Uno and Mega

a Mega is required to use PWM (the UNO does

not have enough PWM pins for this application

*/


#define numberLEDs 7


// connect your LEDs to these pins

int const  pinLED[numberLEDs] = {2, 3, 4, 5, 6, 7, 8};

// connect your switch to this pin

int const Switch = 9;

// connect your motion sensor to this pin

int const Motion = 10;

// the following line defines that a twinkle will occur [URL='http://forum.allaboutcircuits.com/x-apple-data-detectors://0']3/10th[/URL] of the time

int const probabilityTwinkle = 3;


// the setup function runs once when you press reset or power the board

void setup() {


  // initialize pins to drive LEDs as an output.

  for (int myPin = 1; myPin++; myPin <= numberLEDs) {

  pinMode(myPin, OUTPUT);

  }


// Define the pin used to switch on/off

pinMode(Switch, INPUT);


// randomize function

randomSeed(analogRead(0));


}


// the loop function runs over and over again forever

void loop() {

  int OnOff;

  long endLoop;

  OnOff = digitalRead(Switch);


  while (OnOff) {

  endLoop = millis() + 30000;

  while (millis() < endLoop) {

  for (int myPin = 1; myPin++; myPin <= numberLEDs) {

  if (random(0,10) < probabilityTwinkle)  {

  twinkle(pinLED[myPin]);

  }

  }

  }

  }

}


void twinkle(int whichPin) {

  //insert your "twinkle" code here

}


Thats a great start, thanks. I should be able to work my way around some code once I get into it.. I actually wrote my first program, professionally, in 1970, in octal, machine language. So you can do the math on my age, but its been quite a few years since my last big effort.
 

Thread Starter

spopop

Joined Jan 25, 2017
10
Here is a circuit I developed a few years ago. The LED's flash semi random. It uses a CD4051. If pin 8 is connected to Vdd all the LED's would be off. A manual switch could be connected to connect pin 8 to Vss or Vdd, or you could set up a 555 timer to be a astable oscillator at 30 seconds, connect pin 3 of the 555 to pin 8 of the 4051 and you would be done. Here is the schematic of the ckt I described.My ckt has 2 LED's in series and R4 determins the LED Current. Since you are using only 7 LED's just eliminate the LED's connected to pin 13.
View attachment 119465

Nicely done, thanks, but I have now convinced my self to go with an arduino solution.
 

djsfantasi

Joined Apr 11, 2010
9,163
Thats a great start, thanks. I should be able to work my way around some code once I get into it.. I actually wrote my first program, professionally, in 1970, in octal, machine language. So you can do the math on my age, but its been quite a few years since my last big effort.
I did my first programming in artificial intelligence using Fortran around the same time... but I wasn't out of HS yet.
 

Thread Starter

spopop

Joined Jan 25, 2017
10
I did my first programming in artificial intelligence using Fortran around the same time... but I wasn't out of HS yet.
Well I guess you are getting a little long in the tooth as well !, Yes those were the days of machine code, assembly language, and then the advanced ones like Fortran, Forth, BAL, Cobol, etc. Compilers sure grew up in a hurry.
 

djsfantasi

Joined Apr 11, 2010
9,163
Oops,

I forgot to mention that while my sample code compiles, it has not been tested. Having said that, while driving to work, I realized that I forgot an important line.

The following code needs one more line.

C:
  while (OnOff) {
    endLoop = millis() + 30000;
    while (millis() < endLoop) {
      for (int myPin = 1; myPin++; myPin <= numberLEDs) {
        if (random(0,10) < probabilityTwinkle)  {
          twinkle(pinLED[myPin]);
        }
      }
    }
It should read as follows. Note the additional line and where it is located! To show the exact location is why I provided before and after listings.

JavaScript:
  while (OnOff) {
    endLoop = millis() + 30000;
    while (millis() < endLoop) {
      for (int myPin = 1; myPin++; myPin <= numberLEDs) {
        if (random(0,10) < probabilityTwinkle)  {
          twinkle(pinLED[myPin]);
        }
      }
      OnOff = digitalRead(Switch);
    }
Without this extra line, one the on/off switch was turned on, you couldn't turn it off! Like I said, Oops.

Note that once the code exits the Arduino loop() function, it is restarted. Hence the name loop! For motion sensing, you would add a line after each time the OnOff variable is set that checks for motion. The the encompassing while loop would execute if OnOff was true -OR- motion was sensed.

Good luck!
 

Thread Starter

spopop

Joined Jan 25, 2017
10
Oops,

I forgot to mention that while my sample code compiles, it has not been tested. Having said that, while driving to work, I realized that I forgot an important line.

The following code needs one more line.

C:
  while (OnOff) {
    endLoop = millis() + 30000;
    while (millis() < endLoop) {
      for (int myPin = 1; myPin++; myPin <= numberLEDs) {
        if (random(0,10) < probabilityTwinkle)  {
          twinkle(pinLED[myPin]);
        }
      }
    }
It should read as follows. Note the additional line and where it is located! To show the exact location is why I provided before and after listings.

JavaScript:
  while (OnOff) {
    endLoop = millis() + 30000;
    while (millis() < endLoop) {
      for (int myPin = 1; myPin++; myPin <= numberLEDs) {
        if (random(0,10) < probabilityTwinkle)  {
          twinkle(pinLED[myPin]);
        }
      }
      OnOff = digitalRead(Switch);
    }
Without this extra line, one the on/off switch was turned on, you couldn't turn it off! Like I said, Oops.

Note that once the code exits the Arduino loop() function, it is restarted. Hence the name loop! For motion sensing, you would add a line after each time the OnOff variable is set that checks for motion. The the encompassing while loop would execute if OnOff was true -OR- motion was sensed.

Good luck!

This is great... I can't wait to try it when my kit arrives... I will keep you all posted... thanks so much!!
 
Top