Difference between revisions of "Realistic Fire Simulation"

From Tuxamito
Jump to: navigation, search
Line 1: Line 1:
 
In this page is described how to create a realistic flickering fire effect with LEDs and an Arduino board. In this case I used a [[Digispark]] due to its small size.
 
In this page is described how to create a realistic flickering fire effect with LEDs and an Arduino board. In this case I used a [[Digispark]] due to its small size.
 +
 +
 +
== Component Schematics ==
 +
[[File:Fire_led_schema1.png]]
 +
 +
[[File:Fire_led_schema2.png]]
 +
 +
 +
== Building ==
  
 
[[File:firesimled01.jpg]]
 
[[File:firesimled01.jpg]]
Line 7: Line 16:
 
[[File:firesimled03.jpg]]
 
[[File:firesimled03.jpg]]
  
 +
 +
 +
 +
== Code ==
 
<pre>
 
<pre>
 
int p1 = 0; // Set the 3 pins with PWM
 
int p1 = 0; // Set the 3 pins with PWM

Revision as of 18:53, 4 January 2016

In this page is described how to create a realistic flickering fire effect with LEDs and an Arduino board. In this case I used a Digispark due to its small size.


Component Schematics

Fire led schema1.png

Fire led schema2.png


Building

Firesimled01.jpg

Firesimled02.jpg

Firesimled03.jpg



Code

int p1 = 0; // Set the 3 pins with PWM
int p2 = 1;
int p3 = 4;

void setup() {
  pinMode(p1, OUTPUT); // Set the pins as output
  pinMode(p2, OUTPUT);
  pinMode(p3, OUTPUT);
}

void loop() {
  int v1, v2, v3;

  v1 = random(155) + 100; // Calculate the new light
  v2 = random(155) + 100; // intensity values for each LED
  v3 = random(155) + 100;

  analogWrite(p1, 255 - v1); // Apply the light intensity
  analogWrite(p2, 255 - v2); // to each LED
  analogWrite(p3, 255 - v3);

  delay(20 + random(80)); // Wait some random time for next udpate
}


Demonstration: