WORKING WITH LDR SENSOR and LED

Hello friends ,
        I am cyberautics and in the previous session we learn about the basics of LDR with Arduino and now in this session we learn about how to works with Arduino and how to become familier with LDR sensor.we learn how led works with as per the LDR sensors value.If you still not read the basics of LDR sensor than click here

COMPONENTS

  1. Arduino
  2. LDR sesnor
  3. LED light
  4. breadboard/pcb
  5. jumper wires

CIRCUIT DIAGRAM



You can see the diagram 
  1. LED connects with the arduino by +ve in digital 11 number pin, and -ve terminal connects with the ground.
  2. LDR connects in the arduino analog 0th num. pin with use of resistors , remaining LDR terminal in the +5 v and remaining  terminal of resistor connect in the ground.

CODE

//make a connection as per diagram

// declare analog input pin
int sensorpin=A0; 

 // clear the garbage value  
int sensorvalue=0;

//declare a led pin
int led = 11;

void setup()
{
  // declare led pin as output pin
  pinMode(led, OUTPUT);

// configure serial monitor
  Serial.begin(9600); 
}

void loop()
{
    //obtain a value of sensor
  sensorvalue=analogRead(sensorpin);  

//print the value of  sensor in serial monitor
  Serial.println(sensorvalue);
  delay(100); //sleeping time

//now make code for led by ldr sensor

// I choose 12 but you can choose any value
  if(sensorvalue<=12) 
  {
    digitalWrite(led, HIGH);  //turn on led 
    Serial.println("LED IS ON") ;
  }
  else
  {
    digitalWrite(led, LOW);    //turn off led 
  }
}

//COMPILE IT...
//upload it on Arduino
//increase the light on the LDR sensor..

EXPLANATION

  • Hello  friend for every Arduino program either it is complex or easy we have to follow 3 steps 
  1. declare and/or initialize variable
  2. define input/output and serial monitor(optional)
  3. make the execution mechanism which work again and again
  4. so the use of these three easy steps we can make any program 
  • same procedure will be followed in our program,
  • we  declare and initialize the value of out peripherals and set the execution loop which is take input from sensor and read the value of sensor if the value of the sensor is satisfy the condition then led are on or off mechanism are executed.
  • In this session we set condition for led is when ldr value is <=12(less than or equal to 12) then led on otherwise off , we done this by the use of if else condition.

  • so, we can see in this image, this image is captured on serial monitor output, The value of LDR sensor are change as per light intensity and it will increase/decrease correspondences to the light intensity.
  • The image indicate the status of the light when luminous(unit of light intensity) is <=12 then LED light is ON and when this condition is false that means luminous is >12 then LED is turn OFF.



So, My dear friends I hope this information is very useful for you , and please share this blog and support us for more useful content.
If you have any question or any problem you can contact me .


Comments

Post a Comment