Ashutosh M Bhatt
Published © GPL3+

Close Loop Control System Demo Using LED Light and LDR

It uses LDR to sense light intensity and LEDs to vary light intensity. It uses arduino as controller and LCD to display light intensity.

IntermediateFull instructions provided7,851
Close Loop Control System Demo Using LED Light and LDR

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
High Brightness LED, White
High Brightness LED, White
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Darlington High Power Transistor
Darlington High Power Transistor
×1

Hand tools and fabrication machines

Breadboard, 270 Pin
Breadboard, 270 Pin

Story

Read more

Schematics

close loop control demo with arduino using LED and LDR

it controls LED light intensity as per ambient light sensed by LDR

Code

program to control LED light intensity as per LDR input

C/C++
the LED light intensity varies as per the ambient light sensed by LDR
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int LDR_pin = A0;    		// pin that the LDR sensor is attached to
const int set_pot_pin = A1;
const int led_light_pin = 9;        	// pin that the LED array is attached to

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int threshold = 0;
int light_intensity = 55, led_intensity = 20;
void setup()
{
  lcd.begin(16, 4);
  lcd.clear();
  lcd.print("calibrating.....");
  analogWrite(led_light_pin, 0);
  digitalWrite(13, HIGH);
  while (millis() < 10000)
  {
    sensorValue = analogRead(LDR_pin);
    if (sensorValue > sensorMax) sensorMax = sensorValue;
    if (sensorValue < sensorMin) sensorMin = sensorValue;
  }
  lcd.clear();
  lcd.print("calibration over");
  lcd.setCursor(0, 1);
  lcd.print("max light:");
  lcd.print(sensorMax);
  lcd.setCursor(0, 2);
  lcd.print("min light:");
  lcd.print(sensorMin);
  delay(2000);
  lcd.clear();
  lcd.print("light intensity");
  lcd.setCursor(0, 2);
  lcd.print("threshold:");
  lcd.setCursor(0, 3);
  lcd.print("LED light:0%");
}

void loop()
{
  sensorValue = analogRead(LDR_pin);
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 100);
  sensorValue = constrain(sensorValue,0,100);
  lcd.setCursor(0, 1);
  lcd.print(sensorValue);
  lcd.print('%');
  threshold = analogRead(set_pot_pin);
  threshold = map(threshold, 0, 1023, 0, 100);
  lcd.setCursor(11, 2);
  lcd.print(threshold);
  lcd.print('%');
  if (sensorValue < threshold)
  {
    analogWrite(led_light_pin, light_intensity);
    lcd.setCursor(11, 3);
    lcd.print(led_intensity);
    lcd.print('%');
    if(light_intensity<255)
      {
        light_intensity += 25;
        led_intensity += 10;
      }    
   }
  delay(2000); 
}

Credits

Ashutosh M Bhatt
5 projects • 39 followers
Contact

Comments

Please log in or sign up to comment.