Play with LEDs
The idea for this week assignment is to control RGB LEDs to light up in the dark with Glowing lights and in normal mood with changing colors to enhance mood.
The Idea is a trial for my final projects idea "INFINITY BOX"
TinkerCad: To simulate & Build Code Blocks.
Arduino IDE: To Program the Arduino Board.
Components Used:
Arduino Uno Board
2 RGB LEDs.
16 Jumper Wires.
6 (1 OHM) resistors.
LDR Sensor.
Ultrasonic Sensor.
First I started with Tinkercad to simulate & create Codeblocks to control the LEDs
Next I connected all parts and connected them on Tinkercad
FYI: As Tinkercad don't have LDR sensor integrated, I used PIR sensor instead.
As I want to control the light intensity of LEDs using the LDR sensor. I decided to connect the RGBs to the Pins (3, 5, 6, 9,10,11) so I can use the OUTPUT BLOCK (SET PIN (X) to (0))
1st Code Page
2nd Code Page
3rd Code Page
For the code I wanted my device to respond as follow:
If there's no light around, then turn all RGBs ON on white color.
And If anybody come close to the Ultrasonic sensor less than or equal 20 cm then make a RGB LED changing colors.
Else, Turn all LEDs OFF.
And for it to be accomplished I had to have TWO IFs Conditions, The First for the PIR(IR) sensor & The Second one for the Ultrasonic Sensor & ONE ELSE Condition.
Using Simulation tool on Tinkercad, I checked if the code running as supposed. And surprisingly it did! lol
Using Breadboard, I connected all the compartments together in parallel with the power supply and Switch.
On Tinkercad, I selected (Blocks+Text) option so I can copy the Code text
Then Using Arduino IDE, I copied the code and Uploaded it to the Arduino board
Now my Smart device is ready, Lets play around!
During the Lab session. Our instructor Ahmed Khalied suggested to use Paint to get the variables for each color so we can use it in the code
During testing my code, in state of All LEDs are OFF, There was one of LEDs don't switch OFF & after double checking I found there is an extra block added by mistake which caused it after deleting everything went great!
After learning the logic behind controlling ON/OFF state and Colors of RGBs, I can implement this knowledge in my final project
The magic of If condition and how can I use it to control different INPUTS & OUTPUTS
I learned how to use the PWM(pulse width modulation) in different actions like controlling the intensity of light using values from 0-255.