Check out these pictures!
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
}
/*
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
}
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.