Christmas Treeduino, by Jojo and Leah

by PHS_Engineering in Circuits > Arduino

167 Views, 0 Favorites, 0 Comments

Christmas Treeduino, by Jojo and Leah

Screenshot 2021-12-09 1.13.39 PM.png

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

Screen Shot 2021-12-08 at 1.42.51 PM.png
Screen Shot 2021-12-08 at 1.41.08 PM.png
Screen Shot 2021-12-08 at 1.43.29 PM.png

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

Screen Shot 2021-12-08 at 1.49.51 PM.png
Screen Shot 2021-12-08 at 1.49.19 PM.png
Screen Shot 2021-12-08 at 1.48.51 PM.png
Screen Shot 2021-12-08 at 1.48.31 PM.png

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

Screen Shot 2021-12-08 at 2.00.01 PM.png
Screen Shot 2021-12-08 at 2.01.00 PM.png
Screen Shot 2021-12-08 at 2.01.56 PM.png
Screen Shot 2021-12-08 at 2.02.31 PM.png

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!

Screen Shot 2021-12-08 at 2.04.27 PM.png
Screen Shot 2021-12-08 at 2.04.52 PM.png
Screen Shot 2021-12-08 at 2.05.31 PM.png
Screen Shot 2021-12-08 at 2.08.47 PM.png
Screen Shot 2021-12-08 at 2.09.13 PM.png
Screen Shot 2021-12-08 at 2.09.38 PM.png

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 !

Screen Shot 2021-12-08 at 2.13.30 PM.png
Screen Shot 2021-12-08 at 2.13.23 PM.png
Screen Shot 2021-12-08 at 2.13.16 PM.png
Screen Shot 2021-12-08 at 2.13.08 PM.png
Screen Shot 2021-12-08 at 2.12.59 PM.png
Screen Shot 2021-12-08 at 2.12.46 PM.png

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

Screen Shot 2021-12-08 at 2.20.51 PM.png
Screenshot 2021-12-07 2.05.52 PM.png

Wiring the Christmas Tree

Screen Shot 2021-12-08 at 2.44.51 PM.png
Screen Shot 2021-12-08 at 2.45.02 PM.png
Screen Shot 2021-12-08 at 2.45.17 PM.png
Screen Shot 2021-12-08 at 2.45.30 PM.png

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//

}

}

Downloads