Alex Merchen
Published © GPL3+

Emergency Candle

A custom PCB that simulates a candle when not plugged into power.

IntermediateFull instructions provided4 hours149

Things used in this project

Hardware components

CPG-04-B - POGO Pin
×1
MCP73831T-2ACI/OT
×1
ATtiny85
Microchip ATtiny85
I used ATTINY45 but it's functionally the same
×1
LED (generic)
LED (generic)
×3
Resistor 10k ohm
Resistor 10k ohm
Check schematics for exact values
×7
Capacitor 47 µF
Capacitor 47 µF
Non polarized and 4.7uF
×2
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
Try to use as small as possible
×1

Software apps and online services

Arduino IDE
Arduino IDE
KiCad
KiCad
PCBWay
SolidWorks for Makers

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Piece for power source to mount to

Piece for Candle PCB to mount to

Github with all the files

Schematics

Power Source Schematic

Candle Schematic

Code

Main Sketch for ATTINY45

Arduino
const int LED_D1 = 1;
const int LED_D2 = 2;
const int status = 0;        // Pin for status (power availability)
const int voltage_in = 3;    // Pin for voltage_in (external power detection)

const int THRESHOLD_STATUS = 400;  // Threshold for 2.5V (in analog range 0-1023)
const int THRESHOLD_VOLTAGE = 512; // Threshold for voltage detection (adjust according to your voltage divider)
int already_blunk = true;

void setup() {
  // Initialize LED pins as outputs
  pinMode(LED_D1, OUTPUT);
  pinMode(LED_D2, OUTPUT);
  pinMode(status, INPUT);
  pinMode(voltage_in, INPUT);
}

void loop() {
  // Check power status (whether power is below 2.5V)
  int status_value = analogRead(status);
  
  if (status_value < THRESHOLD_STATUS) {
    // Power is below 2.5V, show error mode: both LEDs flash 2 seconds on, 2 seconds off
    flashErrorMode();
  } else {
    // Check if external voltage is available
    int voltage_value = analogRead(voltage_in);
    
    if (voltage_value < THRESHOLD_VOLTAGE) {
      // External voltage is not detected, mimic a candle flicker
      candleFlickerEffect();
    } else {
      // Both LEDs blink normally (as per your original plan)
      normalBlinking();
    }
  }
}

// Function to flash both LEDs slowly (2 seconds on, 2 seconds off)
void flashErrorMode() {
  digitalWrite(LED_D1, HIGH);
  delay(1000);  // Both LEDs on for 2 seconds
  
  digitalWrite(LED_D1, LOW);
  digitalWrite(LED_D2, LOW);
  delay(2000);  // Both LEDs off for 2 seconds
}

// Function to mimic a candle flicker effect (flicker the LEDs)
void candleFlickerEffect() {
  int flickerDelay = random(20, 500);  // Random delay between flickers to simulate candle effect
  digitalWrite(LED_D2, HIGH);
  delay(flickerDelay);
  digitalWrite(LED_D2, LOW);
  delay(20);
  already_blunk = false;
}

// Function to blink LEDs normally (your original functionality)
void normalBlinking() {
  if (already_blunk) {
    digitalWrite(LED_D2, LOW);
  }
  else {
    already_blunk = true;
    digitalWrite(LED_D1, HIGH);
    delay(1000);
    digitalWrite(LED_D1, LOW);
    delay(1000);
    digitalWrite(LED_D2, HIGH);
    delay(1000);
    digitalWrite(LED_D2, LOW);
    delay(1000);
    digitalWrite(LED_D1, HIGH);
    delay(1000);
    digitalWrite(LED_D1, LOW);
  }
  delay(1000);                  // Wait for 1 second
}

Credits

Alex Merchen
27 projects • 40 followers
I'm an EE with a Masters in ECE. I like building things.

Comments