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.
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.
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.
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.
ReplyDeleteFiretech fire monitors are robust products designed with advanced technology and have been tested to provide the high-quality water jet and fog patterns.
ReplyDeletefoam generator
These are by far the most effective bets in a game of roulette and the only ones a beginner should concentrate on to}. If you love on|you like} to position crazy and expensive bets, this isn't for you. I am here to assist folks to seek out|to search out} the most effective roulette methods 토토사이트 to win, not the most expensive hobby on the planet. Most of the web video games I included within the record above settle for bets ranging from €/£/$1 to €/£/$5.
ReplyDelete