Blogroll

Powered by Blogger.

Sunday 20 July 2014

Simple Circuit to Sense Light using Arduino Mega and LDR

by realfinetime  |  in transistor at  12:40

          Before starting this blog, you should have some idea about the basics of working of LDR and Transistor. Read this blog to get some idea about working of LDR and BC547 transistor .

          We have already seen the Circuit to Turn On an LED During Night and Turn Off the same During Day Using LDR. Here we will design the circuit to sense the presence of light around LDR using Arduino Mega.

           Connections are done as shown in the following circuit diagram. Collector pin of transistor is given to the digital pin 2 of arduino. 5V for the working of transistor is supplied from 5V pin of arduino. Ground for the circuit is given from the Gnd pin of Arduino. Pinout diagram of BC547 is given at the left side top in the following diagram.

Transistor - BC 547 is the transistor used here. It is an NPN transistor and is suitable for small operations.

5V - Normally supplied from Arduino.

R1 -  This is a current limiting resistor. It helps to switch the transistor between ON and OFF states by controlling the current through R1 and hence through the base of transistor. If that resistor is not connected, there is a possibility that, base current will always remain high because, LDR alone cannot resist the current considerably to turn off the transistor.

R2 -  It is a pull down resistor. It will ground the base, if there is no external signals to the base of transistor. When an external signal is connected, beginners confuse whether this signal get grounded through R2. But this signal will not get grounded because of high resistance of R2 ( 10K ).

R3 -  If R3 is not connected, when transistor turns on, power supply get shorted through A,C,B,E and F due to the low resistance of transistor. This will increase current abruptly which will damage the transistor as well as power supply.

Observations

Arduino will read 0, when LDR is kept at LIGHT.
Arduino will read 1, when LDR is kept at DARK.

Tabular column.

          Voltage across various components of the circuit, when LDR is kept at DARK and LIGHT conditions is given in the following table.


Explanation of the Circuit

          "Transistor as a switch" principle is used here. When transistor act as a switch, a small base current is sufficient to drive a large current from collector to emitter ( through ACEF ). Then transistor is said to be in saturation. If the base current is less than a particular amount, transistor will be off and current will not flow from collector to emitter ( through ACEF ).

           LDR is connected in the circuit in such a way that, it will control the current to the base of transistor. Arduino reads current flow from collector pin of transistor to digital pin of arduino. Since the collector pin is connected to the digital pin of arduino, it will read 1 if there is a current flow from collector pin to arduino pin and will read 0, if there is no current flow from collector pin to arduino pin, If the transistor get sufficient base current, transistor turn on and current at the collector pin will flow from collector to emitter and then to ground ( through CEF ). So no current will flow through arduino and it will read 0. If the transistor don't have sufficient base current, transistor get turn off. So current will flow to the digital pin of arduino. Then arduino will read 1.

         LDR controlls the current through the base of transistor. Arduino will read 1 at night and will read 0 during the day time. During the day time, resistance of LDR will be less which will drive more current to base. This will turn on transistor and collector current will flow through the transistor to ground ( through CEF ). So current will not reach the digital pin of arduino and it will read 0 during light. During night, resistance of  LDR will increase which will block current flow to the base of transistor. This will turn off the transistor and collector current will flow to the digital pin of arduino. So arduino will read 1 at dark.

Calculation of the Base current during DARK and LIGHT condition

LDR in DARK

Voltage across R1, Vag  =  0.02V
Resistance of R1             =  1K = 1000 Ohm
Current through R1, Ir1  =  0.02 / 1000  =0.02mA
This current will be approximately equal to the base current, which is not sufficient to turn on the transistor. So arduino will read 1. Because collector current will flow to the digital pin of arduino, not through the transistor.

LDR in LIGHT

Voltage acroos R1, Vag  =  0.18V
Resistance of R1             =  1K = 1000 Ohm
Current through R1, Ir1   =  0.18 / 1000  =0.18mA
This current will be approximately equal to the base current, which is sufficient to turn on the transistor. So LED will turn OFF. Because collector current will flow through the transistor ( CEF ), not through the LED.

Arduino Program to sense the presence of light.

// Collector pin is connected to the Digital pin 2 of Arduino
int collector_pin = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the collector pin's pin an input:
  pinMode(collector_pin, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int light_intensity = digitalRead(collector_pin);
  // print out the intensity of light, 1 for Dark and 0 for Light:
  Serial.println(light_intensity);
  delay(1);       
}

          After compiling, upload this program to your arduino board. If the uploading is successfull, open serial monitor. Change the baud rate to 9600. Serial monitor will display the "light_intensity". "light_intensity" will be 1 if the sensor is in darkness and will be 0 if the sensor is in light.

4 comments:

IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.

For More Electronic Tips



Blog Archive

Proudly Powered by Blogger.