Electrical dimmer switch
For Week 6, my goal was to practice with the components I will be using in my final project. To get into the trial and error stage early and be better prepared when I begin the actual project, I chose RGB LEDs and potentiometers for this week's assignment.
This week, I designed a circuit that gives full control over the color of the light using three potentiometers. Each potentiometer adjusts one of the RGB channels, allowing the user to mix and create different colors. My inspiration came from dimmer switches: instead of just controlling brightness, I reinterpreted the idea to allow full control over color.
Arduino IDE
Jumper wires
3 x potentiometers
3 x 220 ohm resistors
RGB LED
Arduino UNO & USB cable
Breadboard
Smart circuit simulation on Tinkercad
Connected RGB LED to breadboard and Arduino
Cathode: negative rail on breadboard
R pin: connected to 220 ohm resistor and analog output pin 5
G pin: connected to 220 ohm resistor and analog output pin 9
B pin: connected to 220 ohm resistor and analog output pin 6
Connected positive and negative rails on breadboard to Arduino
Connected 3 potentiometers. Each to the positive and negative rails and analog input pins.
A0: controls red
A1: controls green
A2: controls blue
Forever block: Arduino will continuously loop the instructions inside.
"set pin 5 to...": this controls red
The code reads analog pin A0 (the potentiometer connected to A0)
That reading is a value from 0–1023
The map block converts this into a range of 0–255, which is what the Arduino uses
Then the mapped value is sent to pin 5, which controls the red in the RGB LED.
Therefore, turning the potentiometer on A0 changes the red brightness.
"set pin 6 to...": this controls blue
The code reads analog pin A2 (the potentiometer connected to A2)
That 0–1023 reading is mapped to 0–255
The mapped value is sent to pin 6, which controls the blue of the RGB LED
"set pin 9 to...": this controls green
The code reads analog pin A1 (the potentiometer connected to A1)
That 0–1023 value is mapped to 0–255
The mapped value is sent to pin 9, which controls the green of the RGB LED
Gathered materials
4. Connected R, G and B pins to analog output on Arduino + added potentiometers
2. Connected RGB LED and resistors at R, G and B pins
5. Connected potentiometers to positive and negative rails
3. Connected breadboard to ground and 5V + connected RGB LED to negative rail
6. Connected potentiometers to analog input on Arduino
(final circuit)
7. Copied and pasted the text code from Tinkercad to Arduino IDE. Then, I connected the circuit via USB cable and uploaded the code.
Final result
My output connections were first connected like the picture on the right. However, when coding, I couldn't find pin 7 in the dropdown menu.
I did a quick Google search to find out why certain pins were not there, and the AI overview brought my attention to the fact that pin 7 is a digital pin, and the dropdown menu was only showing analog pins.
The solution was to move the green wire to an analog output pin, since the RGB LED is an analog component.
This challenge will now remind me to focus on the analog and digital pins and choose where to connect the wires accodingly.
These were my initial connections
In the code blocks, I couldn't find pin 7
This was my inital wiring
My plan for this week was to use one potentiometer to choose either red, green or blue light. However, I thought that this was limiting, as an RGB LED is capable of producing countless hues.
When researching for my final project, I thought of the idea of using three potentiometers, to have full control over the colours produced by the RGB LED. Now, when using a component for a project, I will make sure it is being utilized to it's full capabilities, and that the technical challenges are not limiting