Shrinkify Arduino Project – LED Pumpkin Candle

Shrinkify Arduino Project – LED Pumpkin Candle

I just successfully completed my first “shrinkified” project – a flickering LED pumpkin candle.

I built the project on an Arduino Uno and then using a tutorial from the High-Low Tech group at MIT, I flashed a ATtiny85 with the code and freed up my Arduino.

The LED candle flickers randomly and occasionally glares angry red for a few seconds before returning to flickering. The LEDs are tri-color and flickering is accomplished changing the green color value (against steady red) and the overall brightness of the LED. 3 LEDs seem to be enough and can be safely powered directly from the ATtiny85 pins. They pull a max of 6mA. The tiny85 can handle 40mA/pin with a max of 200mA/chip.

Parts:

  • 3 Tri-color LEDs
  • ATtiny85
  • 2 220 ohm resistors I had pulled from something in the last 20 years
  • 5-volt power supply
  • Candle glass and ceramic drill bit for making a wiring hole in the bottom
  • shrink tubing and wire
  • Uh, a pumpkin

Assembly:

  • Connect the resistors in series to the red and green LED pins
  • Connect the red LED pins to ground, pin 4 on the tiny85
  • Connect the common anode LED pin to pin 5 (PWM/digital pin 0) on the tiny85
  • Connect the green LED pin to pin 6 (PWM/digital pin 1) on the tiny85
  • Connect ground, pin 4 and Vcc, pin 8 on the tiny85 to a 5V power supply.
  • Frost candle glass (I bought from Target) with white candle wax. I lined the back with tin foil for reflection. I drilled a hole in the bottom of the candle glass with a ceramic drill bit to feed the wires through so they wouldn’t be visible.

Pictures. The angry red glare doesn’t show up in the pictures. When it’s activated, the flicking stops and it transforms to solid red. After a few seconds it transforms back to where it was and resumes flickering.

Here’s the code:

// pin assignments - Red is full on (Gnd), Blue is full off (+5V or disconnected)
int intensityPin = 0;  // common anode pin (+5v for full)  
int triGreenPin = 1;  // green LED pin

// green LED is modulated for flickering, common anode is modulated for intensity
int flickerHigh = 100; // outdide of pumpkin - 44, inside - 
int flickerLow = 40; // outdide of pumpkin - 28, inside - 
int flickerRed = 0;
int flickerVal = flickerHigh;  //starting val for flicker level
int triGreenVal = flickerVal;

int flickerDelayMin = 40;  // min & max time betweeen flickers
int flickerDelayMax = 100;

int intensityLow = 216;  // intensity min & max
int intensityHigh = 255;
int intensityVal = intensityHigh;  // intensity starts off

int cycleCount = 0;
int glareBaseCount = 500;
int glareTimer = 0;

void setup() {
  randomSeed(analogRead(0));
  
  pinMode(intensityPin,OUTPUT);
  pinMode(triGreenPin,OUTPUT);
  
  //setLED(flickerVal,intensityVal);
  rampUpLED(flickerVal,intensityHigh);
  glareTimer = getGlareTimer();
}

void loop() {
  int i = 0;
  int j = 0;
  int glareTask = 0;
  cycleCount++;
  // is it time for a glare?
  if (cycleCount>(glareBaseCount+glareTimer)) {
    glareTask = 1;
    cycleCount = 0;
    glareTimer = getGlareTimer();
  }

  int intensityVal = random(intensityLow,intensityHigh+1);
  if (glareTask == 0) {
    // flicker mode - "normal"
    flickerVal = flickerVal + randomInc();
    if (flickerVal < flickerLow) { flickerVal = flickerLow; }
    if (flickerVal > flickerHigh) { flickerVal = flickerHigh; }
  setLED(flickerVal,intensityVal);
    delay(random(flickerDelayMin,flickerDelayMax)); // flicker delay
  } else {
    //  fade down to red
    j = intensityVal;
    for (i=flickerVal; i>= flickerRed; i--) {
      j = j + (flickerVal-flickerRed)/(255-intensityVal);
      setLED(i,255);
      delay(100);
    }
    delay(7000);
    //  fade back up from red
    for (i=flickerRed; i<= flickerVal; i++) {
      setLED(i,255);
      delay(100);
    }

  }
}

// set flicker and intensity LED values
void setLED(int flick, int intensity) {
  analogWrite(triGreenPin,255-flick);
  analogWrite(intensityPin,intensity); 
}

// random flicker change (up or down)
int randomInc() {
  int val = random(17) - 8; // -8 to +8 range
//  Serial.println(val);
  return val;
}

void rampUpLED(int flick, int intensity) {
   int i = 0;
   for (i=0; i < intensity; i++) {
     setLED(flick,i);
     delay(5);
   }
}

int getGlareTimer() {
  int t=random(1,glareBaseCount+1);
  return t;
}

Comments are closed.