Attiny13 PWM Candle

While ago I found project that emulates candle flame using attiny13 MCU and two colored LED (red/yellow) or alternately two separate LED’s. Project author used method of randomly turning on and off LED’s and it looked relatively OK but it was a bit hard for eyes. I decided to make it from scratch using PWM (Pulse wide modulation) that randomly changes light intensity instead of turning on and off completely LED’s. It resulted in much more realistic candle flame simulation. It’s handy for making romantic atmosphere without fear of setting fire 😉


LED’s are connected through 100Ω resistor to PB0 and PB1 attiny13 pins (pin 5 and 6). Attiny is powered from 5V source. Program is written in Bascom. One thing that should be done while programming attiny is to change lfuse from 6A to 7A so that MCU clock is changed from default 1.2MHz to 9.6MHz and that also changes PWM speed so there is no visible blinking of LED’s due to low PWM frequency.

And here is source and compiled hex file for download


2 thoughts on “Attiny13 PWM Candle”

    1. Waveform Generation Mode:
      Phase Correct PWM mode (8 bit PWM).
      Clock source: I/O Clock / 64
      Clear OC0A on Compare Match when up-counting.
      Set OC0A on Compare Match when down-counting.
      Clear OC0B on Compare Match when up-counting.
      Set OC0B on Compare Match when down-counting.

      To be honest that part is something I found on Bascom forum and it was while ago.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.