Arduino, Tutorials

How to Build a Candle Light LED Lamp (flame effect) with Arduino Micro

Introduction

LED lamps are usually quite easy to build, and using simple materials you can create really fun effects. But what about an LED lamp that simulates the flickering effect of a candle light?

There are LEDs which have a “built-in” flickering effect, and there are also ways to create this effect at circuit level. But we’re not gonna bother about these. We can implement a pretty realistic flickering effect at code level, and use just regular LEDs in our circuit. You can use it as a decoration, maybe a desktop lamp to make you feel all cozy and warm this winter, or a for a romantic dinner by candle-led-light.

This tutorial will show you how to create a nice LED Lamp that simulates a candle light effect, using basic materials and some code trickery.

What you are going to need for this tutorial

  • 1/4 Breadboard (smallest size, fits the Arduino micro exactly)
  • Arduino Micro
  • 2 red LEDs and 1 yellow LED
  • 3x 220 ohm resistor
  • 1 short piece of wire
  • a piece of cardboard or any thick paper
  • a white plastic cup or other semi-transparent recipient like a white-ish glass
  • soldering or tape to connect the LED to the GND wire and to the resistors (the LEDs will be kinda “floating” on top of the Arduino, so everything fits in the cup)
  • some tape

The mix of red and yellow LEDs is important to give a “fire” look, however you can use any colors you want.

If you’re new to all this, I recommended checking out our basic Arduino LED tutorials:

Building the Circuit

The Arduino Micro board fits exactly a 1/4 sized breadboard. It’s a good idea to leave more room on the side you’ll connect the LEDs. We’re going to use pins 9, 10 and 11, since they are PWM pins. This is how my breadboard looks like with the Arduino:

 

Arduino Micro Pinout

A simple pinout of the Arduino Micro for reference.

Fixing the LED

We’re going to build a little “arc” using the piece of paper, and the LEDs will be fixated on top of it. It’s very important that the LEDs are placed all in the same direction (like, longer leads to the right, shorter leads to the left) so you can easily separate their GND and power leads.

First, make little holes in the middle of the paper where the LEDs should be. I used the pin of a jumper wire to make the hole. This is how it should look like when you get the LEDs in place:

Don’t worry if it’s off-center, we can cut a bit of the paper later! πŸ™‚

Now “open”the leads apart keeping together the ones of the same type. Make sure you separate the anodes from the cathodes. This is how it should look like:

The three cathodes (negative, shorter leads of the LED) will be connected together to a piece of wire that will be connected to GND. The anodes will be each one connected to one 220 ohm resistor. You can make the connections using tape or soldering. I used solder because it is just easier, in my opinion! This is how it looks like after soldering:

Now we can finally finish the breadboard setup. Connect the resistor to pins 9, 10 and 11, and the GND wire to a GND pin on the Arduino board. After making the connections, you should be able to adjust the position of the components to create the “arc” we need:

Now tape it over the breadboard. I used washi tape πŸ˜›

isn’t it the cutest little thing?

Let’s Write Some Code

Yep. It’s time! Go to your Arduino IDE and upload the following code to your Arduino:

/*
 RGB LED example - codingmama.io
*/

int led1 = 9;
int led2 = 10;
int led3 = 11;

void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

void loop() {
  flicker();
  //breathe();
}

void breathe() {
  for (int i=50 i<=255; i++) {
    analogWrite(led1, i);
    analogWrite(led2, i);
    analogWrite(led3, i);
    delay(10);
  }

  for (int i=255; i>50; i--) {
    analogWrite(led1, i);
    analogWrite(led2, i);
    analogWrite(led3, i);
    delay(10);
  }
}

void flicker() {
    analogWrite(led1, random(10, 255));
    delay(20);
    analogWrite(led2, random(10, 255));
    delay(20);
    analogWrite(led3, random(10, 255));
    delay(20);
}

There are two example functions here that you can use to animate your lamp. The “flicker” function turns the lamp into a sort of candle light, while the function “breathe” makes what the name suggests, slowly increasing and decreasing intensity to create a dimmer effect.

Below you can see the demo for the candle effect:

Now the same everything, except that this time it uses three red LEDs – basically, a Valentine’s Day led lamp:

ProTip: if you just want a colorful LED lamp, you can replace the three LEDs for an RGB LED and use basically the same code to get some really random colors.

Liked it? Take a second to support erikaheidi on Patreon!

1 thought on “How to Build a Candle Light LED Lamp (flame effect) with Arduino Micro”

Leave a Reply

Your email address will not be published. Required fields are marked *