What Will I Learn?
At the end of this tutorial:
♦ The readers will be able to create a circuit that can control the RGB LED display using a force sensitive resistor
♦ The readers will be able to know how the circuit works.
♦ Learn to apply the circuit in the future electronic projects
Introduction
Today, we will control the output led display of the RGB LED using a force sensitive sensor. The sensor will act as the controlling element of the RGB LED. We will program our microcontroller to give outputs at the RGB pins. Then the RGB will give the light color according to the programmed codes.
You can read more about RGB led Here and Force Sensitive Resistor here
Requirements
Electronic Components
♦ Arduino Uno
♦ RGB led
♦ Force Sensitive Resistor
♦ Resistor
♦ Breadboard
♦ Connecting wires
Software
♦ Fritzing application
Intermediate
♦ Advance
Tutorial Contents
Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard
Part I. Schematic Diagram
So first let us construct our circuit diagram.
Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 RGB led, 1 Force Sensitive Resistor, and 3 resistors.
Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
In this tutorial the input component will be the force sensitive resistor and the output will be the RGB led with the three resistors.
Now let us construct our circuit diagram.
At the input side of our circuit, we have a force sensitive resistor that has two terminals. One of the terminals is to be connected to the 5V source from the arduino output. Then we will get the input of our microcontroller to the other pin of the force sensitive resistor. Since we choose pin A0 as our input pin then we connect it to that pin as you can see below.
Then at the output side of our circuit, we have three pins that will be connected to the corresponding pin of the RGB led, the pin 9 is to be connected to Red led terminal, pin 10 is to be connected to Green led terminal and pin 11 for the Blue led terminal.
Though we can connect it directly to each pin, but I choose to use the resistor before connecting the output to the RGB to avoid damaging the RGB led. The three resistors will limit the flow of current through the RGB led.
To limit the flow of current at the output side we connect the three output pins to the three resistors. As you can see in the figure below.
Now this is our final circuit diagram.
When the force is applied at the force sensitive resistor, a current will flow through the input pin 0. This is because; the force sensitive resistor will conduct current due to change in its resistance. The resistance will decrease when there is an applied force making it to conduct.
Our microcontroller is programmed to give output at the three pins connected to the RGB led.
Now our RGB led will give lights, namely for RED, GREEN and BLUE. Though we can display different colors base from the programmed codes
Part II. Code
Now let us do programming of our Arduino uno.
Click on code to start.
Our input is the force sensitive resistor; we will choose the analog pin input of our microcontroller. So here, I will use pin 0. Then we declare the our pin output for the RGB led, let us assign pin 9 for the Red Led, 10 for Green Led and pin 11 for the Blue led.int fsrValue = 0; //initial setting for the fsr
int fsrPin = 0; // select the input pin for the force sensitive resistor
int redPin = 9; // select the pin for the red color display
int greenPin = 10; // select the pin for the green color display
int bluePin = 11; // select the pin for the blue color display
int fsrValue = 0; //initial setting for the fsr
void setup() {
// declare each Pin as an INPUT:
pinMode(fsrPin, INPUT);
// declare each pin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
digitalWrite(bluePin, OUTPUT);
}
void loop() {
// read the fsr and store it in the variable fsrValue:
fsrValue = analogRead(fsrPin);
// if the force sensitive resistor detects force
if (fsrValue >= threshold) {
// toggle the status of the three pins:
setColor (255, 0, 0); //red color display
delay(500);
setColor (0, 255, 0); //green color display
delay(500);
setColor (0, 0, 255); //blue color display
delay(500);
setColor (180,0 , 255); //for purple color
delay(500);
setColor (255, 255, 255); //for white color
delay(500);
}
void setColor(int redValue, int greenValue, int blueValue){
analogWrite(redPin,redValue); //color red
analogWrite(greenPin,greenValue); //color green
analogWrite(bluePin,blueValue); //color blue
}
Here are our arduino codes.
int fsrPin = 0; // select the input pin for the force sensitive resistor
int redPin = 9; // select the pin for the red color display
int greenPin = 10; // select the pin for the green color display
int bluePin = 11; // select the pin for the blue color display
int fsrValue = 0; //initial setting for the fsr
void setup() {
// declare each Pin as an INPUT:
pinMode(fsrPin, INPUT);
// declare each pin as an OUTPUT:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
digitalWrite(bluePin, OUTPUT);
}
void loop() {
// read the fsr and store it in the variable fsrValue:
fsrValue = analogRead(fsrPin);
// if the force sensitive resistor detects force
if (fsrValue >= threshold) {
// toggle the status of the three pins:
setColor (255, 0, 0); //red color display
delay(500);
setColor (0, 255, 0); //green color display
delay(500);
setColor (0, 0, 255); //blue color display
delay(500);
setColor (180,0 , 255); //for purple color
delay(500);
setColor (255, 255, 255); //for white color
delay(500);
}
void setColor(int redValue, int greenValue, int blueValue){
analogWrite(redPin,redValue); //color red
analogWrite(greenPin,greenValue); //color green
analogWrite(bluePin,blueValue); //color blue
}
Part III. Breadboard
Click on the breadboard.
Arrange each component in the breadboard before connecting.
Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard
Application
The readers can create their own lighting system using RGB led display.
Curriculum
Here are my other tutorials for electronic projects.
ELECTRONIC PROJECTS
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @rfece143 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x