First Real Arduino Project - Christmas Lights!

Want to show off your own project? Want to keep a build log of it? Post it here!
Post Reply
cRow949
Posts: 26
Joined: Tue Apr 20, 2021 3:59 pm
Has thanked: 1 time
Been thanked: 1 time

First Real Arduino Project - Christmas Lights!

Post by cRow949 » Thu Mar 10, 2022 6:20 pm

Hey Forums! Recently I got a Sparkfun Inventors Kit and I have been tinkering around with it. I’ve learned a little about code and wanted to put my “skills” to the test. I decided to build alternating Christmas lights!
Check out these pictures!
image.jpg
image.jpg (2.19 MiB) Viewed 45150 times
image.jpg
image.jpg (2.42 MiB) Viewed 45150 times
image.jpg
image.jpg (2.38 MiB) Viewed 45150 times
I used a Photoresistor so that when you enter the room and turn on the light, the alternating lights turn on automatically with it! Then when you leave the room, and turn the lights off, the alternating lights turn off with it.

Here’s the sketch I use:
SpoilerShow
Just copy and paste into Arduino IDE:

/*
SparkFun Inventor’s Kit
Circuit 1C-Photoresistor

Use a photoresistor to monitor how bright a room is, and turn an LED on when it gets bright.

This sketch was written by SparkFun Electronics, with lots of help from the Arduino community.
This code is completely free for any use.

View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/sp ... uide---v41
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
*/

int photoresistor = 0; //this variable will hold a value based on the brightness of the ambient light
int threshold = 750; //if the photoresistor reading is below this value the the light will turn on

void setup()
{
Serial.begin(9600); //start a serial connection with the computer

pinMode(5, OUTPUT); //set pin 5 as an output that can be set to HIGH or LOW

pinMode(3, OUTPUT); //set pin 3 as an output that can be set to HIGH or LOW

pinMode(2, OUTPUT); //set pin 2 as an output that can be set to HIGH or LOW

pinMode(4, OUTPUT); //set pin 4 as an output that can be set to HIGH or LOW
}

void loop()
{
//read the brightness of the ambient light
photoresistor = analogRead(A0); //set photoresistor to a number between 0 and 1023 based on how bright the ambient light is
Serial.println(photoresistor); //print the value of photoresistor in the serial monitor on the computer

//if the photoresistor value is below the threshold turn the light on, otherwise turn it off
if (photoresistor < threshold) {
digitalWrite(5, LOW); // Turn on the LED
digitalWrite(3, LOW); // Turn on the LED
digitalWrite(2, LOW); // Turn on the LED
digitalWrite(4, LOW); // Turn on the LED
} else {
digitalWrite(5, LOW);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
delay(2000); // Wait for 2000 millisecond(s)
digitalWrite(5, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
delay(2000); // Wait for 2000 millisecond(s)
}

delay(100); //short delay to make the printout easier to read
}
I used a Sparkfun Inventors Kit sketch as a base, and built on from there. In the sketch, it says something along the line of “this sketch is free to use”, so have at it :D !

If you guys want to build it for yourselves, I’m more than willing to make a build guide. I’m still new to Arduino, but I think it’s awesome and want more people to get into building DIY electronics.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest