Self flashing LEDs (pseudo random) - Page 1
Forum section: electronics / projects

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 04:15:45 am
content: I have a potential requirement for about 100 "self flashing" LEDs. Ideally each one would flash on and off somewhat randomly. I'm familiar with simple flashing LEDs (2Hz or whatever) and the RGB ones that cycle every n seconds, but that's not the effect required.They are to be attached to a piece of "art", but there is an acrylic cover over the whole area so people can't touch. Each LED will probably be a single colour and be functionally independent of the others. RGB may be an option but not the first choice.So, I could whip up some code and mount a PIC, the LED and a couple of passives on a small PCB about 15 or 20mm square. They need to be affixed to the art anyway, so don't have to have a tiny tiny footprint. A common 5V supply would loop in and out of the boards.Before I head down the custom path, is anyone aware of an off the shelf LED that flashes randomly?

author: pickle9000
author_rank: Super Contributor
timestamp: July 09, 2012, 04:29:12 am
content: I smell a mikeselectricstuff answer coming.

author: SeanB
author_rank: Super Contributor
timestamp: July 09, 2012, 04:39:42 am
content: Put a led on the output of a melody chip. If you get a job lot of 100 assorted mrlody boards then they will appear to be pretty random.

author: vk6zgo
author_rank: Super Contributor
timestamp: July 09, 2012, 04:48:24 am
content: Quote from: David_AVD on July 09, 2012, 04:15:45 amSelf flashing LEDs are not very stable,so they will drift out of sync fairly quickly after turn on --they are very unlikely to all sit there flashing in unison.The drift would be an interesting effect in itself.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 04:54:11 am
content: Just to clarify, the flash on and off times need to be somewhat random. I was thinking of a PIC with pseudo random flashes and using a few different seeds among them all.

author: Psi
author_rank: Super Contributor
timestamp: July 09, 2012, 05:44:11 am
content: you can store a block of random numbers in the EEPROM/FLASH and then use the ADC noise to pick a point to start from.That yields pretty good visual randomness and is fast to do.I do like the outside-the-box thinking of a melody chip though

author: codeboy2k
author_rank: Super Contributor
timestamp: July 09, 2012, 06:54:13 am
content: Build a 100-bit Linear Feedback Shift Register (LFSR), with outputs sinking or sourcing your LED current.Attach all 100 LEDs to the outputs of a 100-bit shift register. The 74HC595 seems popular for this, or the 74HC164 can work too, and is simpler as it doesn't have the latch or tristate outputs like the HC595 has. Both of these can and can source 20 mA and 500mW Pd. I think the HC164 can do 700mW Pd.You can cascade 12 of these to make a 96-bit shift register, 13 for 104 bits.Read up on the workings of a LFSR, and take a few taps back at appropriate places, feedback to the input.To get it started you need to seed it with 100-bits from user switches or random something or other, johnson noise or a transistor's PN junction, or the vibrations of the floor, etc.And if you place the LEDS in random places around the display, not in a linear sequence, it will appear to flash very randomly as the random bits shift through the display.Note, there is no MCU, and you have written no code. That's all you need for 100 random LEDs. If you want anything other than random, you need an MCU.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 07:04:34 am
content: codeboy2k,I need the each LED "assembly" to be independent. No central controller, etc. Just 5V (or 12V) looping in and out of each one.Psi,I did also consider using an SMD thermistor on the ADC and using the lower few bits to fiddle some table lookups. Not sure how much variance there will be in the ambient temperature as the artwork area is somewhat enclosed. Maybe suitable divider values will cause enough volatility of those low bits.

author: codeboy2k
author_rank: Super Contributor
timestamp: July 09, 2012, 07:30:40 am
content: Quote from: David_AVD on July 09, 2012, 07:04:34 amIs each assembly 100 LEDs ? A LFSR of 100 bits for 100 LEDs on each assembly can certainly be random and independent.Each assembly needs to be seeded differently. If you use a random noise source (a reverse biased PN junction) you can just shift that bit stream though the assembly. You don't even need any linear feedback then. The reversed biased PN junction is truly random, but you'll need to slow it down, it's too fast. In this case, use two cascaded D flip flops on the output of the random bit generator and clock one bit through at the rate you want.see herehttp://web.jfet.org/hw-rng.htmlThe output "TTL level random bits" is fed to a 100-bit shift-register and you put the LEDs randomly around your assembly.Here's another one, from this page:http://emergent.unpythonic.net/01257868826The random bitstream is at analog0. The (+/-) 10V @ V+/V- is generated by the MAX680CPA,which gives the needed 20V across the PN junctionActually the output of the random generator can be biased slightly, so they often say to whiten it by feeding it though a LFSR anyways.So that means to me, just XOR the output of the random reverse PN junction into the feedback input stream of a 100-bit LFSR. clock the LFSR at the rate you want to flash LEDs. The shifting and feedback will whiten the random generator, and of course you still have the LEDs distributed randomly throughout the assembly.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 07:55:37 am
content: 100 assemblies = 100 LEDs (one LED per little PCB)

author: G7PSK
author_rank: Super Contributor
timestamp: July 09, 2012, 08:01:29 am
content: These people have green ones and I have seen red ones on Amazon.http://www.ledtechpro.com/flashing-diodes/127-5mm-green-led-diode-16000mcd-self-flashing.htmlhttp://www.amazon.co.uk/self-flashing-LED-red-3mm-resistor/dp/B00418F782

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 08:05:10 am
content: Thanks for that, but it needs to be pseudo random flashing. I'll go fix the title now.

author: codeboy2k
author_rank: Super Contributor
timestamp: July 09, 2012, 08:59:38 am
content: Quote from: David_AVD on July 09, 2012, 08:05:10 amI've never used the self-flashing LEDs, but what is it that you don't like about them?They certainly make your application much, much easier to do.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 09:01:36 am
content: Quote from: codeboy2k on July 09, 2012, 08:59:38 amSigh... I don't want standard flashing LEDs because they flash in a regular manner. See top posts for more detail.

author: johnnyfp
author_rank: Frequent Contributor
timestamp: July 09, 2012, 09:06:41 am
content: If you don't need to update the firmware, then your original idea with a pic reading a floating adc pin will give you a decent random number to use as a start seed. Something like a pic10f directly connected to a led or rgb lead. No pcb needed. Should look funky.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 09:11:14 am
content: The PIC (with ADC) + LED + capacitor + resistor is probably how I'll go. The small PCB will make it easier as we need to glue 100 of these suckers down to a flat surface and solder the wires on.

author: codeboy2k
author_rank: Super Contributor
timestamp: July 09, 2012, 09:12:24 am
content: Yeah, I was just going to say the same, a small PIC is your best choice then.Anything else you do or buy with an oscillator will be random frequency compared to any other LED, but not flash randomly.Sorry I misunderstood what you meant by random.I don't know if I'd trust a floating ADC to be random enough. I'd still take that floating ADC input and feed it through a 48-bit at least LFSR inside the PIC code. use that stream of 1's and 0's to turn on and off the LED.

author: Psi
author_rank: Super Contributor
timestamp: July 09, 2012, 11:14:51 am
content: Yeah, you use ADC noise to seed some other random data.To get more ADC noise you can use a differential input with a high gain value set.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 09, 2012, 02:20:34 pm
content: Small PIC will be the easiest solution. a random sequence generator will create the randomness - you need to figure out what the min/max periods need to be and scale the ouput accordingly.The question is how to seed it if you need them to be random from power-up (they will drift apart anyway over time).Most PICs have both an internal RC osc and a seperate low-freq osc for WDT or slow clock modes (HFINTOSC and LFINTOSC). By timing one against the other you should get enough entropy to seed the randomizer within a second or two of powerup, without needing any external parts. Some devices have an internal reference, and comparing this against the supply via the ADC will probably give a bit or two. You may find you get random values in RAM on powerup.You could also measure the LED forward voltage against the supply, as this will vary a bit over temp and part-to-part.Another option if you have eeprom is time an eeprom write cycle, however for a single LED you'll probably looking at the cheapest 10F parts which don't have eeprom.With some imaginaiton you should be able to do it with no external parts.

author: markus_b
author_rank: Regular Contributor
timestamp: July 09, 2012, 03:48:52 pm
content: Just a pointer: There is an interesting paper on how to generate random numbers in microcontrollers 'Stochastic processes in embedded systems + Random number generation' by Sebastian Sohn. He did the tests on AVR, but the same principles to other micros too.Here the thread on avrfreaks.net, with links to the paper:http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59417

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 09, 2012, 04:40:51 pm
content: Here's how I'd do it on a PIC10F200On reset :if it is a power-up reset, set the WDT prescaler to a medium-to-high value, and timer 0 to free-run, then sit in a loop waiting for the WDT to time out.If it is a WDT reset, take the TMR0 value and use as a seed for the RNG.If you want more than 8 bits, use a software count to extent TMR0, but you may need to wait for a longer WDT period (or more resets)Timer 0 will have been counting at 1MHZ until the WDT times out, and the part-to-part and temp difference between the INTRC and WDT oscs should give you enough spread to make it look random enough.

author: codeboy2k
author_rank: Super Contributor
timestamp: July 09, 2012, 06:26:57 pm
content: I like Mike's ideas for seading the RNG. The 6-pin 10F200 is perfect for this single random flashing LED, you just needed to seed the RNG somehow, and Mike had some great ideas. The 10F2xx PIC's don't have an ADC and it's a waste of money to pay almost twice as much for a 12F series PIC just to get the ADC, when all you need it for is to seed a software LFSR to create a random bitstream.

author: David_AVD
author_rank: Super Contributor
timestamp: July 09, 2012, 10:43:54 pm
content: For this situation, it won't matter if the LEDs start out in unison. They will be running for at least 15 mins before the first "customer" sees them I'm told.Some good ideas in there guys. The seeding ideas will be useful for sure. Having a single version of the code will be easier to deploy.I'd pretty much assumed a PIC + LED solution from the start, but wondered if anyone had seen some "special" LEDs that I wasn't aware of.

author: johnnyfp
author_rank: Frequent Contributor
timestamp: July 09, 2012, 10:49:38 pm
content: Nah no special LED's, unless you want it custom made then your talking tens of thousands.

author: ivan747
author_rank: Super Contributor
timestamp: July 10, 2012, 03:45:07 am
content: Use the PIC10F series. Use one that includes an ADC. Perform some undersampling, one sample per 100ms or something. If the sample is odd, turn the LED on; if the sample is even, turn it off. You can use these PICs with a pseudo-random algorithm that has no multiplications (if that exists) and a random seed in every microcontroller.If you use a DIP package, you can directly solder an LED, with a series resistor, to 2 I/O pins on the PIC. Set one as a low output and use it as ground. Glue the LED to mount the assembly. You can make it more robust with heat-shrink or silicone.You can even get bi-color LEDs and use those. You can do software PWM as well, maybe taking the random ADC samples and amplifying them because they tend to be rather low.

author: ivan747
author_rank: Super Contributor
timestamp: July 10, 2012, 03:49:40 am
content: I have finally found a situation where the PICKit's standalone functionality is going to be useful. Load the program into the memory and use something like a minty boos to power the programmer. Now you just have to plug the programmer into the ICSP port push a button, disconnect and repeat the cycle 99 times.

author: David_AVD
author_rank: Super Contributor
timestamp: July 23, 2012, 03:20:50 am
content: Thanks again guys. I've written some basic code (for the PIC10F200) using Mike's watchdog idea while I wait for the prototype boards to come back.

author: David_AVD
author_rank: Super Contributor
timestamp: July 30, 2012, 04:07:41 am
content: Prototype boards are back. Here's one built up with an SMD LED. (can be SMD or TH type)The 6 pins are a standard ICSP header. Pins labelled "5" and "G" are for the power input once installed.Board size is approx 15mm x 15mm.Will have a play with some assembler code this week.

author: David_AVD
author_rank: Super Contributor
timestamp: July 30, 2012, 12:34:41 pm
content: I've written some simple code that uses lookup tables (on and off times) for the LED. Only 32 values per table for far, but the results are quite acceptable.Just for kicks, I also use the value gained from TMR0 to adjust the OSCCAL register so that different boards will run at slightly different rates too!I'll build some more boards up tomorrow and see what a bunch of them look like when started together.

author: David_AVD
author_rank: Super Contributor
timestamp: July 31, 2012, 10:35:38 am
content: Here's two boards running identical code, started at the same time:

author: deephaven
author_rank: Frequent Contributor
timestamp: July 31, 2012, 03:32:17 pm
content: Looks good. I can't wait to see a video with 100 of them!

author: vk6zgo
author_rank: Super Contributor
timestamp: July 31, 2012, 03:40:23 pm
content: The interesting thing is if they were truly random,the nature of probability is such that they are quite as likely to flash together as anything else.Perhaps that is the value of pseudo random?

author: David_AVD
author_rank: Super Contributor
timestamp: July 31, 2012, 09:28:08 pm
content: Exactly. People often say they want random, but what they usually want is an irregular flashing with no obvious pattern. True random data is a bad choice for many applications.