Wednesday, June 22, 2022

Lightning Simulator

I decided to start playing with the Attiny85 processors because they are small, cute, and cheap. I love the arduino nano, but even the knockoff clones shipped from China are costing more than $5. I decided a great first project would be the lightning simulator. Here's a video of the final project:




Here is the Fritzing layout: (with 12v's worth of AA batteries and a single LED for the 12v light)



and the schematic:




After making it on a breadboard, I had a PCB printed to make the process more compact:






The code is Rob Tillaart's lightning code. Simple and effective.
// 
//    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 0 
unsigned long lastTime = 0; 
int waitTime = 0; 
 
void setup() 
{ 
  randomSeed(analogRead(2));
  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); 
      delay(10); 
    } 
  } 
   
  // do other stuff here 

  

}