Arduino ldr led

Using An LDR Sensor With Arduino

Wouldn’t it be really cool if whenever a room gets dark, a light bulb automatically turns ON and eliminates the darkness?

Breadboard (generic)
× 1
Arduino UNO
× 1
LED (generic)
× 1
LDR
× 1
Resistor 10k ohm
× 1
Resistor 220 ohm
× 1
breadboard friendly connecting wires
× 1
USB-A to Micro-USB Cable
to upload the code to the Arduino
× 1

Hi Everyone, This is my 1st Arduino’s tutorial video. In this video I am going to show you how to use a LDR or Light Dependent resistor to turn on and off another circuit or a LED.

Wouldn’t it be really cool if whenever a room gets dark, a light bulb automatically turns ON and eliminates the darkness? In this very simple project, I am focusing on eliminating darkness. You can even use this as an emergency lighting system.

  • Connect the 3.3v output of the Arduino to the positive rail of the breadboard
  • Connect the ground to the negative rail of the breadboard
  • Place the LDR on the breadboard
  • Attach the 10K resistor to one of the legs of the LDR
  • Connect the A0 pin of the Arduino to the same column where the LDR and resistor is connected (Since the LDR gives out an analog voltage, it is connected to the analog input pin on the Arduino. The Arduino, with its built-in ADC (Analog to Digital Converter), then converts the analog voltage from 0-5V into a digital value in the range of 0-1023). — Now connect the other end of the 10K resistor to the negative rail
  • And the the second (free) leg of the LDR to the positive rail

Pretty much this is what we need for the light sensing. Basic circuits like this can be done without an Arduino aswell. However, if you want to log the values and use it to create charts, run other logics etc. I will recomend an Arduino or ESP8266 or may be a ESP32 for this.

Now, as we want our circuit to do something in the real world other than just displaying the values on the computer screen we will be attaching a LED to the circuit. The LED will turn on when its dark and will go off when its bright. To achieve this we will:

  • Place the LED on the breadboard
  • Connect the 220ohm resistor to the long leg (+ve) of the LED
  • Then we will connect the other leg of the resistor to pin number 13 (digital pin) of the Arduino
  • and the shorter leg of the LED to the negative rail of the breadboard

Источник

Arduino – LDR (Light-Dependent Resistor)

This tutorial explains concept and how to use LDR (Light Dependent Resistor) with Arduino. An example is included in which a LED is controlled on the basis of LDR.

1. Introduction:

A step by step illustrated tutorial to use LDR on Arduino.

This tutorial is made on Original Arduino UNO and Robo India’s R-Board(UNO compatible).

1.1 LDR:

A LDR (Light Dependent Resistor) or a photo resistor is a photo conductive sensor. It is a variable resistor and changes its resistance in a proportion to the light exposed to it. It’s resistance decreases with the intensity of light.

2. Required Hardware

Following Hardware will be required to perform this LDR circuit.

S.No. Item Quantity
1. R-Board with FTDI or Arduino Board 1
2. Bread Board 1
3. Male to male Jumpers 7
4. Indicator LED 1
5. 100 OHM Resistance&10 K Resistance 11
6. LDR 1

3. Building Circuit

Make following circuit with the help of above mentioned components. Some key points to understand about the circuit-

LDR is connected to a 10 Resistance in series. +5 Voltage is applied to this arrangement. As the light intensity changes LDR value changes thus the voltage drop on LDR will change and we are going to measure that voltage change.

3.1 You may go with Robo India’s R-Board(UNO Compatible)-

Here is the schematic of this circuit-

3.2 You may go with original Arduino UNO Board-

Here is the schematic of this circuit-

4. Programming:

Once we are done with circuit part, here is our programme to this circuit. Every command of the following programme is explained in the comment section. A few point to consider for this sketch.

1. It reads LDR value and prints them on Serial monitor. Once you upload this programme to your Arduino board open serial monitor and observe how values are changing with the change of Light intensity.

2. The attached LED glows in analog mode according to the LDR Values.

3. There is a condition of threshold; The attached LED remains OFF for all the values below Threshold limit. You can set your own threshold limit. In this programme we have given 800 as threshold. You can set t threshold to any value between 0 and 1023.

5. output:

Here is the output of this tutorial-

6. Serial Output:

This sketch gives LDR Readings at serial monitor. Here is the Screenshot of the serial output.

Источник

Using an LDR Sensor With Arduino

Introduction: Using an LDR Sensor With Arduino

Introduction

Hi Everyone, This is my 1st Arduino’s tutorial video. In this video i am going to show you how to use a LDR or Light Dependent resistor to turn on and off another circuit or a LED.

Wouldn’t it be really cool if whenever a room gets dark, a light bulb automatically turns ON and eliminates the darkness? In this very simple project, I am focusing on eliminating darkness. You can even use this as an emergency lighting system.

Step 1: Principle

The LDR is a special type of resistor which allows a lower voltage to pass through it (high resistance) whenever its dark and higher voltages to pass (low resistance) whenever there is a high intensity of light.

We are going to use a 10k resistor along with the LDR to create a voltage divider circuit. The varying resistance of the LDR is converted to a varying voltage that the analog pin of the Arduino will then be using in its logic.

Step 2: Hardware Requirement

For this very simple DIY Arduino project we need:

— an arduino uno/nano (whatever is handy)

— LED (Light Emitting Diode)

— A 10K Resistor for creating the voltage divider and a 220ohm resistor for the LED

— Few breadboard friendly connecting wires

— and a USB cable to upload the code to the Arduino

Step 3: Assembly

— Connect the 3.3v output of the Arduino to the positive rail of the breadboard

— Connect the ground to the negative rail of the breadboard

— Place the LDR on the breadboard

— Attach the 10K resistor to one of the legs of the LDR

— Connect the A0 pin of the Arduino to the same column where the LDR and resistor is connected (Since the LDR gives out an analog voltage, it is connected to the analog input pin on the Arduino. The Arduino, with its built-in ADC (Analog to Digital Converter), then converts the analog voltage from 0-5V into a digital value in the range of 0-1023). — Now connect the other end of the 10K resistor to the negative rail — And the the second (free) leg of the LDR to the positive rail

Pretty much this is what we need for the light sensing. Basic circuits like this can be done without an Arduino aswell. However, if you want to log the values and use it to create charts, run other logics etc. I will recomend an Arduino or ESP8266 or may be a ESP32 for this.

Now, as we want our circuit to do something in the real world other than just displaying the values on the computer screen we will be attaching a LED to the circuit. The LED will turn on when its dark and will go off when its bright. To achieve this we will:

— Place the LED on the breadboard

— Connect the 220ohm resistor to the long leg (+ve) of the LED

— Then we will connect the other leg of the resistor to pin number 13 (digital pin) of the Arduino

— and the shorter leg of the LED to the negative rail of the breadboard

Источник

Fading led with LDR(Light Dependent Resistor) using Arduino uno

Basic led brightness control circuit with ldr and passive components

Main functionality of the above traditional light dimmer circuit

  • Current passing through LDR increases/decreases depending on the amount of light thrown on the light detector. This current is input to the base of NPN transistor.
  • Varying current at input base of transistor varies the voltage across led, connected to collector side of transistor. ​

LED brightness control using Light dependent resistor

In order to take the same functionality with arduino we need to consider the above two points as both are dependent on each other. So what we want arduino to do for us in order to accomplish the above two tasks is?

  • Determine the current/voltage allowed by light sensor to pass through it.
  • Output a voltage on its digital pin to fade led. Output voltage is dependent on the current/voltage allowed to pass by light sensor(Or intensity of light). ​

How to determine the amount of voltage allowed by LDR to pass through it using Arduino Uno?

Arduino build in ADC(Analog to digital converter) peripheral can be utilized to measure voltage. We can use arduino ADC(analog to digital) pins to measure the voltage passing the light detector.

Arduino has a 10-bit ADC module. It can measure maximum voltage of rating on which arduino is working typically 5 volts precisely. 10-bit ADC max reading value is 1024. So 1024 corresponds to 5 volts. 512 corresponds to 2.5 volts and 0 represents no voltage. Adruino uno has 6 analog channels. We can use any one of them for our project.

To read an analog voltage we use the command
Val = analogRead (analogPin);
Where analogPin is analog channel used(A0—-A5) and Val is variable in which analog value returned by the function is saved.

So we are done with reading the light sensor allowed passing voltage which corresponds to the intensity of light.

How to fade/control brightness of led with arduino uno?

Led brightness can be varied by applying a variable voltage to it. Suppose if led max voltage requirement is 2 volts. If we supply varying voltage suppose 0.9 volts or 1.5 volts we can fade led. At 2 volts led will glow with full intensity/brightness and at 1 volt the led brightness will be half.

PWM(Pulse width modulation) is basic technique used by microcontrollers to fade or control the brightness of led. PWM actually outputs a varying voltage on digital pins of microcontroller. Varying voltage is generated using the timers of microcontrollers. I assume you people know about PWM. In case no, I am just giving a short introduction.

PWM utilizes timers and a particular pin is switched on and off for a specified period of time. On period is generally know as duty cycle we can compute the output voltage by changing the duty cycle. 100% duty cycle represents full voltage output and 50% duty cycle outputs half voltage.

PWM(Pulse width modulation) using Arduino

Arduino provides a lot of feasibility for pwm even a predefined library is present. We only need to initialize the pwm pin and output the voltage we want to that pin. Pwm functionality is present on arduino uno pins (3, 5, 6, 9, 10, or 11). PWM signal ranges between 0 to 255. Where 255 represents 5 volts and 0 represents 0 volts. 127 represents 2.5 volts.

Arduino analogWrite(x,y) function allow us to output a pwm voltage of desired voltage. In function the x argument is the pin number to which we want our pwm signal to appear. y argument is pwm value.

Lets start the main project. I am going to output the pwm signal on pin 9 of arduino. To read the input voltage by light sensor i am using analog channel 0 of arduino.

In the project below I am going to read analog signal from LDR(light detecting resistor) and then write the signal corresponding pwm value to led in order to fade it. Actually writing means fading led. Analog Write outputs value in the form of PWM(Pulse width modulation). For high values PWM duty cycle will be high and for low values PWM(Pulse width modulation) duty cycle will be low.

Fading led with ardino and light sensor – Project circuit diagram

Coming to the schematic of the circuit. Connect one leg of LDR(light detective resistor) with 10 k ohm resistor in series. Make the other end of resistor ground. Apply 9 volts on the other leg of the LDR(light sensor). Now take a wire and connect it in between the LDR and resistor. Connect other end to A0 analog pin 0 of the Arduino uno.

May be you people are thinking why we connect the wire in between the LDR and 10 k ohm resistor or why we use resistance here. Well their is a big logic behind it. Actually LDR normally has very high resistance and in this condition no current flows through it and when light is thrown on its surface its resistance decreases and it allows the current to flow through it. In the schematic if i directly connect the LDR with the A0 analog pin of Arduino and shine/through some light on it whole of the 9 volt will start appearing across the analog pin of arduino. Which might destroy the arduino analog channel or potentially arduino board. Since arduino operates on 5 volts so its pins can only sink 5 volts. Any voltage greater than the operational voltage(5 v) can destroy the arduino board or produces buggy output. R2 is used to lower down the voltage appearing on the arduino analog channel in its acceptable range(0-5 volts).

Using 9 volts are even dangerous you can reduce it to 5 volts. Since light dependent resistor resistance plays an important role in determining the below of R2. We need some extra resistance calculations which is hard to understand at this level. So its better to use 5 volts as input.

Connect led anode to pin# 9 of arduino and cathode to ground in series with a resistor.

Arduino led brightness control- Project Code

The code of the project is simple. First I initialized the pins that are going to be part of arduino project. Pin name sensor is for analog channel 0 of arduino and output is for arduino pwm pin#9. Then I declared the pin mode for both pins in void setup() function. Pin#9 of Arduino is declared as output pin and Pin#A0 is declared as input pin.

Note: You have a choice to declare arduino analog pin as input or not. It will work if you do not define it but you are bound to define all other pins that are not used as analog input. I did not declared it as input in setup function.

Next in the void loop function i started reading the output voltage value by light sensor from analog channel 0. The code statement int reading=analogRead(sensor) reads the sensor output voltage and place the numeric value in variable reading.

​I divided the reading by 4. This is because arduino analog channel outputs analog value ranging from 0 to 1023. Where as arduino PWM function analogWrite() can only output the values ranging from 0 to 255. So to brought the read value in 0 to 255 range i divided the reading by 4. Now 1023 corresponds to 255, like wise 1000 to 250 and 0 to 0. At last I outputted the analog read value corresponding pwm signal on pin 9 using analogWrite() function.

Источник

Adblock
detector