Loading [MathJax]/extensions/MathZoom.js

Thursday, 31 December 2020

LED Firelight for Harry Potter

It's Lego Harry Potter, but I thought it would be fun to light up the great hall with LEDs setup to flicker like firelight 

I took three LEDs, one red and two yellow and wired them up on a breadboard as below


I used a 1KΩ resistor for each LED, connecting to Digital Pins 9, 10 and 11 on the Arduino.

Here's the Arduino script:

int LED_1 = 9;
int LED_2 = 10;
int LED_3 = 11;
void setup() {
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
}
void loop() {
analogWrite(LED_1, random(200)+55);
analogWrite(LED_2, random(200)+55);
analogWrite(LED_3, random(200)+55);
delay(random(100));
}
view raw Hogwarts.ino hosted with ❤ by GitHub

The analogWrite() call sets up Pulse Width Modulation (PWM). This is a square wave with a varying duration of "on" time, known as the pulse width or duty cycle. PWM can be used to simulate a range of voltages between 0 and 5V.

The value of the duty cycle is given to the analogWrite call. 0 is always off, 255 is always on. In this example, the minimum is set to at least 55 (about 20%) and a random amount up to the maximum is overlaid. 

The value is changed every 100ms to give a flicker-like effect.

Next, I replaced the breadboard by soldering the components onto 30-40cm long wires. Covered the bare wire with electrical tape and put the LEDs into the fireplace of the Lego Harry Potter Hogwarts Great Hall.

Here it is after dark...  Lego Harry Potter LED Great Hall Fireplace - YouTube



No comments:

Post a Comment