Skip to main content

How to control RGB LED using Arduino Uno

RGB LED is the abbreviation of ‘’Red Green Blue Light Emitting Diode’’. RGB LED is the most amazing type of LED which has the ability to create millions of different shades of light colors using red, green, and blue colors.

How to operate LDR using Arduino Uno



A light-dependent resistor (LDR) is the light-sensitive device most frequently used to measure the intensity of the light. Light-dependent resistors are also known as photoresistors whose resistance increases as the intensity of light decreases which helps to identify the presence and absence of light.

If the resistance is high that means it's dark (less light) but if some light falls on LDR then this resistance reduces rapidly which describes that there is enough brightness (more light). Hence photoresistors are used as the light detector in applications such as Automatic Street lighting systems, security systems, light intensity meters, burglar alarm systems, and camera shutter control. I have made two advanced level projects using LDR which are a Smart plant watering system using Arduino Uno and a Locker guard based on Arduino Uno.

In this article I will explain to you, how can you use a light-dependent resistor with Arduino Uno using digital and analog inputs. In the first example, I will explain to you how an LED can be operated with the help of the light-dependent resistor with the help of analog input pins. In the second example, I will explain to you the same project with digital input pins. I will use the same circuit connection (except for the inputs) for both the examples which will help you to understand the concept in a very easy way.

How to operate LED using LDR with Arduino Uno (using analog input):

LDR is used to sense the intensity of the light. In this example, I will try to turn on the LED whenever LDR senses darkness (low value of LDR). The LED will turn off whenever LDR senses enough brightness (high value of LDR). I have compared the real-time measured LDR value with the threshold value ( I used 300 as the threshold value it can be changed according to your need). If the measured LDR value is less than or equal to the threshold value that means it's dark so the LED should turn on. if the measured LDR value is greater than the threshold value that means it's bright so the LED should turn off. 

Required components:

1.  1 x Arduino Uno board............................BUY
2. 1 x breadboard..........................................BUY
3. 1 x LED (Light emitting diode)................BUY
4. 1 x Light-dependent resistor (LDR)..........BUY
5. 1 x 220-ohm resistor..................................BUY
6. 1 x 10 k ohm resistor.................................BUY
7. 1 x USB cable...........................................BUY
8. Few jumper wires.....................................BUY

Connection diagram:


Circuit description

In this example, I have used the A2 analog pin of the Arduino Uno board to provide input. LDR has no polarities so that it can be connected in any direction. As shown in the connection diagram I have connected the 3.3-volt power supply pin of the Arduino Uno board with one pin of the LDR. Another pin of the LDR is connected with one terminal of 10k ohm resistor and analog input pin A2 of the Arduino Uno board. The other terminal of the 10 k ohm resistor is connected with the ground pin of the Arduino Uno. 

10 k ohm resistor is used along with LDR to make a voltage divider circuit. As the light intensity increases, the resistance of LDR decreases which allows the high voltage to pass through LDR to the analog pin, which in the result achieved a higher LDR value. LDR gives an analog voltage as an output voltage at analog pin A2 which may be any value between o to 5 volts which is converted into a digital value between 0 to 1023 with the help of inbuilt analog to digital converter of the Arduino Uno board. Hence the analog pin A2 reads the value between 0 to 1023.





 LED has two legs one is shorter and the other one is longer. The longer leg is known as the anode (positive leg) and the shorter leg is known as the cathode (negative leg). As shown in the connection diagram the shorter leg is connected to the ground and the longer leg is connected with a 220-ohm resistor. If we place the LED directly to the Arduino board then an unrestricted current may burn the LED so to avoid this, it’s better to connect a series resistor with an LED. Therefore I have used a 220-ohm resistor in series with the LED. The other end of the 220-ohm resistor is connected with pin 5 of the Arduino Uno board as an output pin.

Serial monitor output:

Here I am providing screenshots of the serial monitor which shows the output of two types. If the LDR value is less than or equal to 300 that means it's dark and if the LDR value is greater than 300 that means it is bright. The serial monitor displays information according to the code and real-time values observed by the LDR.





Code: Click here

Output:


How to operate LED using LDR with Arduino Uno (using digital input):

In this example, I will try to turn on the LED whenever LDR senses darkness (0 value of LDR). The LED will turn off whenever LDR senses enough brightness (1 value of LDR). I have compared the real-time measured LDR value with the threshold value ( I used LOW as a threshold value). If the measured LDR value is equal to the threshold value that means it's dark so the LED should turn on. if the measured LDR value is not equal to the threshold value that means it's bright so the LED should turn off.

Required components:

1. 1 x Arduino Uno board
2. 1 x breadboard
3. 1 x LED (Light emitting diode)
4. 1 X Light-dependent resistor (LDR)
5. 1 x 220-ohm resistor
6. 1 x 10 k ohm resistor
7. 1 x USB cable
8. Few jumper wires

Connection diagram:


Circuit description:

In this example, I have used digital pin 12 of the Arduino Uno as the input pin. The one terminal of LDR is connected with a 3.3-volt power supply pin of the Arduino Uno board. The other terminal of LDR is connected with digital pin 12 and 10 k ohm resistor’s leg. The other terminal of the 10 k ohm resistor is connected with the ground pin of the Arduino Uno. The LED’s shorter leg is connected to the ground and the other longer leg is connected to the 220-ohm resistor. The other terminal of the 220-ohm resistor is connected with pin 5 of the Arduino Uno board. I have tried to use a similar connection circuit for both examples to make things easier for you to understand. In the second example’s connection circuit only the input pin 12 is used instead of analog pin A2 (pin A2 was used as input pin in the first example) left whole connection is similar to the first example.

Serial monitor output:

Here I am providing screenshots of the serial monitor which shows the output of two types. if the LDR value is 0 which means its dark and if LDR value is 1 that means it's bright. The serial monitor displays information according to the real-time values calculated by LDR as mentioned in the code.





Code: Click here

Output:



Comments

  1. All information you included on your blog that's really commendable about 4000k Led Bulb. All things are very useful. I hope you keep sharing your knowledgeable information with all of us.

    ReplyDelete
  2. Firetech fire monitors are robust products designed with advanced technology and have been tested to provide the high-quality water jet and fog patterns.
    foam generator

    ReplyDelete

Post a Comment

Popular posts from this blog

Smart Plant Watering System Using ARDUINO UNO

As we all know, plants play an important role in our life, there are countless benefits we get from plants but the most important is fresh air and the pleasant atmosphere on the earth. Hence,   It is not only our social duty as well as the responsibility that we should plant trees as much as we can and also take care of them. But  the biggest challenge we face, is, taking care of them,

How to operate soil moisture sensor with Arduino

The soil moisture sensor is the most amazing sensor used to measure the quantity of water present in the soil and defines the moisture level of the soil as the output. Because of its amazing operating principle, this sensor is used in applications such as automatic irrigation systems, agriculture research applications, landscape irrigation, indoor planting system, and lawns. I have also made an advanced level project  "Smart Plant Watering System" using a soil moisture sensor.

How to use temperature sensor with Arduino Uno

The temperature sensor is the most popular measuring device which is capable to sense the intensity of heat generated by the object to which it is connected. These sensors are most frequently used by us through our household devices such as microwaves, refrigerators, air conditioners, and so on. In this tutorial, we will learn about LM35 (LM means linear monolithic) temperature sensor which is an integrated circuit analog temperature sensor.

ad

ad