Boris Shabanov
Published

ATtiny85 Candle

Fast and simple project that imitates candle light powered with ATtiny85 and CR2023.

BeginnerShowcase (no instructions)904
ATtiny85 Candle

Things used in this project

Hardware components

Microchip attiny85v-10su
×1
R75 1206
×2
R4.7k 1206
×1
C 100nF 1206
×1
RGB Led 5x5
×1

Story

Read more

Custom parts and enclosures

3D Enclosure - Cap

Nozzle diameter: 0.4 mm
Layer: 0.19 mm
Tolerance between top part and ring is 0.5mm

Body

Ring

Schematics

ATtiny85 Schematic

Code

ATtin85 Candle.ino

Arduino
#include <avr/sleep.h>
#include <avr/interrupt.h>

#define RED PB1
#define GREEN PB0

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
}

void fire() {
  // Set min and max value for led brightness
  int step = random(128, 255);
  for (long i = 0; i < 90000; i++) {
    // Smooth increase or decrease value
    step += random(-32, 32);
    // Never go below 128
    step = max(128, step);
    // Never go above 255
    step = min(255, step);
    // Tweak the green value
    int g = step - random(0, 32);
    analogWrite(RED, step);
    analogWrite(GREEN, g);
    // Random delay to eliminate artificial look
    delay(random(8, 16));
  }
}

void goToSleep () {
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  ADCSRA = 0;
  sleep_enable();
  sleep_cpu();
  sleep_disable();
}

void loop() {
  fire();
  goToSleep();
}

Credits

Boris Shabanov

Boris Shabanov

7 projects • 5 followers

Comments