Go Down

Topic: lightning simulation help (Read 4953 times) previous topic - next topic


May 08, 2012, 09:42 pm Last Edit: May 10, 2012, 12:40 am by markthespark Reason: 1
hi all
i'm looking to find any thing in the forum about thunderstorms but no luck
i am wanting to simulate a thunderstorm with arduno mega nothing flashy just simple i want to drive a strip of led's 900Ma  any help would be appreciated with the code and what hardware to use ie relays or transistors and witch one to use i would like the simulation to work for 3 seconds and a 1 minute pause.

thanks all



this is a starting point for the software , there are three parameters:

BETWEEN is max number of milliseconds between two flashes
DURATION is the max duration of one flash
TIMES is the max number of subflashes in a flash

These numbers are randomized to get random effects (you might want to seed the random function)

it is based upon the tutorial blink without delay to do the timing between flashes - but it uses delay for the flashes themselves -
it can be rewritten completely without delays but that is left as an exercise for the reader ;)

You can extend this to multiple LEDS with their own "rythm"

give it a try (it uses the onboard LED for easy testing)
Code: [Select]

//    FILE: lightning.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012-05-08
// PUPROSE: simulate lighning POC
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7

#define LEDPIN 13

unsigned long lastTime = 0;
int waitTime = 0;

void setup()
  Serial.println("lightning 0.0");

  pinMode(LEDPIN, OUTPUT);

void loop()
  if (millis() - waitTime > lastTime)  // time for a new flash
    // adjust timing params
    lastTime += waitTime;
    waitTime = random(BETWEEN);

    for (int i=0; i< random(TIMES); i++)
      digitalWrite(LEDPIN, HIGH);
      delay(20 + random(DURATION));
      digitalWrite(LEDPIN, LOW);
  // do other stuff here

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


thats perfect dude many thanks will an irf530 do the job i have seen on other sites that there compatable with arduino


May 08, 2012, 11:08 pm Last Edit: May 08, 2012, 11:12 pm by markthespark Reason: 1
i have just tried to add this code to the bottom buttom of the one above

i have changed the code myself to blink like eyes

 Turns on an LED on for one second, then off for one second, repeatedly.

 This example code is in the public domain.

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 9;

// the setup routine runs once when you press reset:
void setup() {                
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);    

// the loop routine runs over and over again forever:
void loop() {
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(150);               // wait for a second
 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
 delay(5000);               // wait for a second


The software is no big deal...

But the hardware is a big deal...
   You can't just use a MOSFET, because you need constant-current and with 10W LEDs it's not practical to use a linear current regulator.  With a regular every-day 40mW LED, a resistor works fine to control/limit the current.    But, with a high-power LED you end-up needing a high-power resistor and a high-power power-supply to provide the power for the LED plus the extra power wasted in the resistor.

Typically, you'd use a special constant-current switching power supply (example).  You'd need to find a power supply that allows you to "flash" the LED for a few milliseconds, or you'd need to build your own.  I assume that's an easy feature to find, since LEDs are often flashed & dimmed.

As you may know, most medium & hign-power strobe lights use a xenon flash tube.  But, these things are not easy to build either, because they require a high-voltage power supply and a high-voltage trigger circuit. Plus, the light from the flashtube is not directional so you need a reflector.


May 09, 2012, 07:47 pm Last Edit: May 09, 2012, 08:09 pm by markthespark Reason: 1
would the relay module do the job ?
i'm powering a 12volt led strip with 12 volts and just need something to do the switching


May 09, 2012, 11:02 pm Last Edit: May 09, 2012, 11:40 pm by markthespark Reason: 1
i used this circuit with an irl520n it works fine any one see any problems ?
a string of led's 900Ma


vid here



Embedded in your LED strips there are resistors that limit the current to the LEDs and in that respect your circuit is inaccurate and/or doesn't match what you described in your initial post at all. Please show some respect for the time that others spend answering your questions in the future.

With that said it's good to see you accomplished your goal.


May 10, 2012, 12:42 am Last Edit: May 10, 2012, 01:21 am by markthespark Reason: 1
not a problem arduino is new to me as i'm a pic man at heart and the answers i had confused me

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131