Week 6
Automatic lighting in the dark
Automatic lighting in the dark
This week we want toBuild and Program a smart circuit using an Arduino UNO which reads a signal from an input component (Sensor, Switch, or variable resistor) to control an action component (Motor, Buzzer, LED...etc) using Code Blocks
So this was my inspiration, i wanted to make a smart lightining with different colores that can turn on automatically in the dark .
So i'll use the LDR module to sense the darkness and then turn on the lights, and i'll add a 7 segments to say HI when the lights turn on.💡👋
220 ohm Resistors
LDR module
(RED, GREEN, YELLOW) LEDs
Two 7 Segments
Breadboard
5V Adapter
Arduino UNO with arduino caple
Jumper Wires
First when you open tinkercad press on Designs and then choose Circuit to start design the circuit and simulate it before connecting it in reality.
Now from the basic componenets on the right side choose the componenets we're going to use :
1- Breadboard 2- LDR resistor 3- one yellow LED 4- One red LED
5- One white LED 6- one green LED 7- five resistors of 22o ohm
8- Arduino UNO
Now lets see the wiring pprocess of the circuit:
1- First take two wires (Red one) from the 5V of the arduino to the (+Ve) of the breadboard and (Black one) from the GND to the (-Ve) of the breadboard.
2- Connect the LDR resistor with a resistance of 220 ohm in series on the breadboard.
3- Take one wire from the leg of the LDR that's on the resistor and connect it to (pin 12) on the arduino as the input signal pin of the LDR.
4- Then connect the free terminal of the 220 ohm resistor to the negative of the breadboard, and the second terminal of the LDR to the positive of the breadboard.
5- Connect one resistor to every negative of the LEDs from one leg and the other leg of the resistor to the negative of the breadboard (as shown in the photo).
6- Connect the positives of the LEDs to the digital pins of the arduino (Yellow to pin 2), (Green to pin 3), (White to pin 4), (Red to pin 5)
7- Finally connect the Switch one terminal directly to the negative of the battery and the other terminal to the negative on the breadboard.
8- Now add the two 7 segments (connect the cathode to the -Ve on the breadboard) , (connect every LED of litter H (G,F,E,C,B) on the first 7 segment to a 220 ohm resistors then to digital pins (6,7,8,9,10) of the Arduino)
9- Then connect every LED of litter I (F,E) on the second 7 segment to a 220 ohm resistors then to digital pins (11,13) of the Arduino)
Now lets see how can we program the circuit to make it smart 🧠:
1- First open the code icon ubove and first drag and drop from CONTROL the (if/else) block.
2- Then from MATH drag and drop the equal calculation ( ) = ( ) and put it inside the if block.
3- From the INPUT drag and drop the ( read digital pin [] ) block and the change the pin number to 12 .
4- Take from MATH the HIGH block and put it in the second box of the operation and change it to LOW.
5- From OUTPUT drag and drop the ( set pin [] to [] ) block and change the pin number to 2 and the other box to HIGH .
6- Right click on the this block and duplicate it three times more for the other three pins and change the pin box to (3.4,5) as shown in the pic.
7- Duplicate all these OUTPUT blocks and put them in the else block, then change all the pin modes to LOW .
8- Now you can start simulation to see that the light is on when the LDR is detecting no light .
9- In the second pic i added the blocks of the digital pins of the 7 segments the same way i added the previous blocks as shown in the pic.
In the physical wiring i connected the LDR module directly the OUTPUT pin to the 12 pin on arduino without resistor because i have the module now,,then i added the 7 segments.
Tinkercad has no LDR module, so i connected one terminal of the LDR to the +Ve of the breadboard and the other terminal to the 12 digital pin of the arduino as it's the OUTPUT pin of the LDR , and then from this terminal line of the breadboard i connected the 220 ohm resistor, and from the second leg of the resistor to he -Ve of the breadboard.
When i wired the 7 segments in reality i forgot to put the resistors on every LED of the H litter in the first segment and i put only one resistor with the cathode and that's not right, so it affected the lightening as shown in the picture, so i advice you to follow the steps i made on tinkercad in the real circuit too.