Electronic Project 30: A simple guide on how to control the RGB LED display using the Force sensitive resistor

in #utopian-io8 years ago (edited)

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

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

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.

image.png

Now this is our final circuit diagram.

image.png

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.

image.png

Our microcontroller is programmed to give output at the three pins connected to the RGB led.

image.png

Now our RGB led will give lights, namely for RED, GREEN and BLUE. Though we can display different colors base from the programmed codes

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

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

image.png

int fsrValue = 0; //initial setting for the fsr

image.png

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); 
}

image.png

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
}

image.png

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.

image.png

Arrange each component in the breadboard before connecting.

image.png

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

image.png

Application

The readers can create their own lighting system using RGB led display.

link source

Curriculum

Here are my other tutorials for electronic projects.

ELECTRONIC PROJECTS

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20

Tutorial 21

Tutorial 22

Tutorial 24

Tutorial 25

Tutorial 26

Tutorial 27

Tutorial 28

Tutorial 29



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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