lightning simulation help

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

marko

1 Like

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 :wink:

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

give it a try (it uses the onboard LED for easy testing)

//
//    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.begin(115200);
  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++)
    {
      Serial.println(millis());
      digitalWrite(LEDPIN, HIGH);
      delay(20 + random(DURATION));
      digitalWrite(LEDPIN, LOW);
      delay(10);
    }
  }
  
  // do other stuff here

}
1 Like

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

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

/*
Blink
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 ([u]example[/u]). 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 [u]xenon flash tube[/u]. 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.

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

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.

not a problem arduino is new to me as i'm a pic man at heart and the answers i had confused me

I made a few changes,
used analogwrite, brighter flashes,
and added two more LEDs

Enjoy

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

int LEDPIN7=7;
int LEDPIN6=6;
int LEDPIN5=5;

unsigned long lastTime = 0;
int waitTime = 0;

void setup()
{
Serial.begin(115200);
Serial.println("lightning 0.0");

pinMode(LEDPIN7, OUTPUT);
pinMode(LEDPIN6, 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++)
{
Serial.println(millis());
analogWrite(LEDPIN7, 255);
analogWrite(LEDPIN6, 255);
delay(20 + random(DURATION));
analogWrite(LEDPIN7, 0);
analogWrite(LEDPIN6, 0);
delay(10);
}
}

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++)
{
analogWrite(LEDPIN5, 255);
delay(10 + random(DURATION));
analogWrite(LEDPIN5, 0);
delay(10);
}
}
}

1 Like