The idea of this week's assignment was a Smart Light & sound system using potentiometer, Buzzer, and RGB lED.
In this assignment, I'll control an RGB LED and Buzzer Based on the position of a 100K ohm Potentiometer.
Overview:
The Potentiometer will simulate Light sensitivity adjustment, so we can see the color changes through Red, Green, and Blue, also will hear Buzzer alert based on the potentiometer's Value.
I have used the TINKER CAD platform for simulating the electronic circuit, and be sure that every components working before start the actual circuit to avoid any damage.
Arduino Uno.
100k Ohm Potentiometer (Input).
RGB (Output).
3*220 Ohom Resistors.
Piezo Buzzer (Output).
Breadboard
Jumber wires.
First I Used the TINKERCAD platform to simulate the circuit and calculate the values of current and resistors that I will need.
I used the Arduino Uno as a power source
I had to use 3 of 220 Ohm resistor to prevent the RGB LED burning out as it has the range till (3 v) only.
I insert buzzer to be alarm when the potentiometer read lower than 2oo ohm
I also connected the components of the circuit in parallel, because if they are connected in series, the voltage will be divided by the number of components, each according to its resistance, and therefore not all components will work as required.
Then I start to write the code, so the RGB can glow green or blue or red or turn on the buzzer with the combine of the three colors.
I set the range for the potentiometer to be between 1024 Ohm and 700 Ohm at the first for the blue light, then 700 Ohm and 400 for the red light, also 400 Ohm and 200 Ohm for the green light, and finally I set the last If condition to be less than 200 Ohm Or more than 1024 Ohm so the buzzer will be activated beside the combination of all colors.
Circuit Connections and work flow:
The potentiometer adjusts an analog input value (0–1023) read by the Arduino.
Based on this value:
The RGB LED displays different colors.
The buzzer turns on when the value drops below a certain threshold.
The circuit uses PWM (Pulse Width Modulation) to control LED brightness and digital signals for the buzzer.
I placed all the needed components on the breadboard
Wrote the code
Clicked on starts simulation
Changing the value through the potentiometer.
Tinker cad "link"
1. Potentiometer (Analog Input A0):
Middle Pin (Wiper): Connect to A0 on Arduino.
One Side Pin: Connect to 5V on Arduino.
Other Side Pin: Connect to GND.
2. Buzzer (Digital Pin 8):
Positive (Long Leg): Connect to Pin 8 on Arduino.
Negative (Short Leg): Connect to GND on Arduino.
3. RGB LEDs (Pins 9, 10, 11):
Red LED:
Anode (Long Leg): Connect through a 220Ω resistor to Pin 9.
Cathode (Short Leg): Connect to GND
Green LED:
Anode (Long Leg): Connect through a 220Ω resistor to Pin 10.
Cathode (Short Leg): Connect to GND.
Blue LED:
Anode (Long Leg): Connect through a 220Ω resistor to Pin 11.
Cathode (Short Leg): Connect to GND.
4. Arduino Power:
Connect the Arduino’s GND to the breadboard’s negative rail.
Connect the 5V pin to potentiometer.
After building all components of circuit, I connected the Arduino to the laptop to upload the code.
and start to move the potentiometer through different value so we can see first through the highest (1024<value>700) Blue light, then (700<value>400) Red, or Green when it is (400<value>200), OTHERWISE all the color will combine to give like a rainbow with the sound of the buzzer as indicator to the low value of the potentiometer.
First the code wasn't working at all at tinker cad.
Second related to the coding on tinker cad, as the buzzer and the combination of the colors was showing after the green light and at the beginning, but the rest of the colors such as blue and red didn't.
Solution
I resolved that through choosing from "math", the option of "and" block, so I can but range for the potentiometer, and make every If condition specific.
I discovered that was happening as I inserted first If else condition, and the right choice was to make only If then condition with every status.
Within the last one that indicates the alert to choose or not only "and" so if the potentiometer reads any value less than 200 or more than 1024 it will be activated.
With no doubt, the skills and knowledge that I learned this week will help me to design and build the electronic circuit and coding it using Arduino for the final project.
This week was the most exciting week that I have spent during the diploma until now. I hope that the following weeks will be more exciting than this week. I really have learned a lot of things that I will mention in the next points:
Understanding the concept of Arduino.
Learning how to power every single component connected to the Arduino
Learning how to power multiple components on the same circuit in different state using code .
Understanding the basic of programing.