Katie Kristoff
Published © MIT

Programmable Christmas Mason Jar Lights

Use an Arduino Uno to adjust the brightness of your Christmas mason jar lights, including candle light mode!

BeginnerFull instructions provided1 hour4,678
Programmable Christmas Mason Jar Lights

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun ProtoShield Kit
SparkFun ProtoShield Kit
×1
Power MOSFET N-Channel
Power MOSFET N-Channel
×1
4xAA battery holder
4xAA battery holder
×1
Micro LED string
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Mason Jar
Ribbon

Story

Read more

Schematics

Circuit Schematic

Code

Mason Jar Christmas Lights Code

Arduino
int buttonPin = 2;
int led = 3;
int buttonState = 0;
int count = 0;
int preButtonState = 0;
int flickerDelay = 40;

void setup() {
   pinMode(led, OUTPUT);
   pinMode(buttonPin, INPUT);
   analogWrite(led, 0);
}

void loop() {
  preButtonState = buttonState;
  buttonState = digitalRead(buttonPin);
  if (preButtonState == 0 && buttonState == 1)
  {
    count = count+1;
    if (count == 5) 
    {
      count = 0;
    }
    Serial.println(count);
  }
    if (count == 0)
    {
      analogWrite(led, 0);
    }
    else if (count == 1)
    {
      analogWrite(led, 77);
    }
    else if (count == 2)
    {
      analogWrite(led, 153);
    }
    else if (count == 3)
    {
      analogWrite(led, 255);
    }
    else if (count == 4)
    {
      analogWrite(led, 153);
      delay(flickerDelay);
      analogWrite(led, 255);
      delay(flickerDelay);
    }
}

Credits

Katie Kristoff

Katie Kristoff

4 projects • 126 followers
Educator and enthusiastic crafter.

Comments