Christmas Treeduino, by Jojo and Leah
by PHS_Engineering in Circuits > Arduino
179 Views, 0 Favorites, 0 Comments
Christmas Treeduino, by Jojo and Leah
This project connects a light up tree to the Arduino. If it is dark the tree will light up, and if it isn’t dark then the tree won’t light up. To do this, use a photoresistor to read how dark it is. Also, use a relay to protect the Arduino from a high voltage.
Gather Materials
Photo resister
1k ohm resistor
100k ohm resistor
11 Wires
Relay
Diode Rectifier
Breadboard
Arduino Uno
Light-up Tree
NPN transistor
2 Alligator clips
Start Circuit
Connect one wire from pin 13 on the Arduino to the breadboard
Add a 1k resistor
Connect a wire from GND to the negative line
Connect a wire from 5V to the positive line
Relay
Add NPN transistor to the bread board, the middle prong should line up with the other end of the 1k resistor.
From the far end of the NPN transistor attach a wire going to the negative column.
Add diode extending from the positive column to the opposite end of the NPN transistor.
Add relay to the top of the breadboard keeping the middle prong in the valley.
The three pronged end should be closest to the edge of the bread board.
More Wires!
Add a yellow wire going from the row with the diode and the far prong of the NPN transistor, connecting to the left side of the relay (the row with the three prongs)
Add a red wire from the positive column to the right of the relay (the row with the three prongs)
Wedge a wire into the valley making contact with the middle prong of the relay
Add a wire to the left of the relay on the end with only two prongs
Photoresistor Time !
Add a 100k resistor to the bread board
Add a wire going from the positive column to the row below the top prong of the resistor
Add a wire going from the negative column to the opposite end of the resistor
Add a wire going from pin A0 to the top of the resistor
Add the photo resistor to the rows with the two wires next to one another
Breadboard Circuit Completed
Wiring the Christmas Tree
Pop out battery and light from the bottom of the tree
Cut the wire that is closest to the off switch but is connected to where the "on" switch is
(we accidentally cut both so added an extra alligator clip to connect the two)
Add an alligator clip to the exposed wire connected to the on switch and the other end to the black wire from the breadboard
Add another alligator clip to the white wire that is was connected to the on switch and the other end to the green wire
Step 9: Code
Next, write the code!
int AnalogIn = A0; //Define the photoresistor pin//
int RelayPin = 13; //Define the relay pin//
void setup() { // put your setup code here, to run once:
pinMode (RelayPin,OUTPUT); //Set the relay pin as an output//
pinMode (AnalogIn, OUTPUT); //Set the photoresistor pin as an output//
Serial.begin(9600);
}
void loop() { // put your main code here, to run repeatedly:
int value = analogRead(AnalogIn); //read the vale from the photoresistor and set it as a variable// Serial.println(value); //print the value read from the photoresistor//
if (value < 5) //ask if the value from the photoresistor is less than 5//
{
digitalWrite (RelayPin, HIGH); //if so, turn on the relay pin//
}
if (value > 5) //ask if the value from the photoresistor is more than 5//
{
digitalWrite (RelayPin, LOW); //if so, turn off the relay pin//
}
}