Arrduino Candle

This is a very simple sketch that makes a convincingly realistic candle illumination for jack-o-lanterns. Just need the board, a power supply (not a battery, it drains in 20 hours a 9V), two yellow, one orange, one red ultra-bright 5mm LEDs on PWM pins. Insulate and bunch LEDs together and wrap with thin or translucent paper like product to diffuse the color and intensity of these directional LEDs.

I thought it up after hearing my Wifey bought some of the little electronic ones which are never convincing.

int rDelay, rBright, y1Bright, y2Bright, oBright;

// PIN-MAP
//*****************************************************************************************************************************************************************
// -1: InputPullup, 0: Not installed, 1: Input Positive, 2: OUTPUT
int installed[20] = {   0,  0,   2,      2,    2,     0,    2,    0,    0,     2,     2,     2,    1,      0,    1,     0,      0,    0,     0,          0 };
//char* pinNames[20] = { '0', '1', '2',   '3',   '4',   '5', '6', '7',   '8',   '9',  "10",  "11", "12",  "13",  "A0",  "A1",  "A2",  "A3",  "A4",      "A5"  };
//char* ssNames[20] = {  "x", "x", "FN6", "HT6", "AC6", "x", "LB6", "x", "x", "LO6", "LR6", "LG6",  "tm6", "LED",   "sd6", "x", "x", "x", "x", "x" };
const int                       FN6 = 2,     AC6 = 4,     LR0 = 6,                         LY1 = 11,     LED = 13,       sd6 = A0     ;
const int                             HT6 = 3,                          LO0 = 9, LY0 = 10,      tm6 = 12      ;
// *****************************************************************************************************************************************************************

void setup() {
  Serial.begin(9600);

  for (int i = 0; i < 18; i++) {
    // Array init loop

    // Set pin-modes based on installed flags
    if (installed[i] == -1) {
      pinMode(i, INPUT_PULLUP);
    }
    if (installed[i] == 0) {
      pinMode(i, INPUT_PULLUP);
    }
    if (installed[i] == 1) {
      pinMode(i, INPUT);
    }
    if (installed[i] == 2) {
      pinMode(i, OUTPUT);
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:
rBright = random(58,255);
y1Bright = random(58,255);
y2Bright = random(58,255);
oBright = random(50,255);

analogWrite(LR0,rBright);
analogWrite(LO0,oBright);
analogWrite(LY0,y1Bright);
analogWrite(LY1,y2Bright);

rDelay = random(20,100);
delay(rDelay);
}

Hey matt, long time. Good to see you're still it and make working things.

Rechargeable batteries could do for a night.

If the 9V is connected through the Arduino power plug then almost half the power will be dumped to ground by the 7805 regulator. With a cheap adjustable buck converter you could get more than 30 hours. The converter is also good to run Arduino from a 6V source where the 7805 needs at least 7V to regulate properly.

If you add a light detector to the project it could turn off when lit (like in daytime).