Using an LDR Sensor to create an LED Light Meter

Description: A Light Dependent Resistor (LDR) Sensor is used to detect and show changes in light levels with an LED light meter

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
1 – Light Dependent Resistor (LDR)
9 – LEDs
9 – 220 Ohm Resistors
1 – 1k Ohm Resistor

Arduino Code:

const int ldrPin = A0;
const int ledPin1 = 10;
const int ledPin2 = 9;
const int ledPin3 = 8;
const int ledPin4 = 7;
const int ledPin5 = 6;
const int ledPin6 = 5;
const int ledPin7 = 4;
const int ledPin8 = 3;
const int ledPin9 = 2;

int ldrValue = 0;
int ldrlevel1 = 200;
int ldrlevel2 = 220;
int ldrlevel3 = 250;
int ldrlevel4 = 270;
int ldrlevel5 = 300;
int ldrlevel6 = 320;
int ldrlevel7 = 350;
int ldrlevel8 = 370;
int ldrlevel9 = 400;

void setup() {
  
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  
}

void loop() {
  
  ldrValue = analogRead(ldrPin);

  Serial.println(ldrValue);

  if (ldrValue < ldrlevel1) {
  digitalWrite(ledPin9, HIGH);
  
}

  else if (ldrValue < ldrlevel2) {
  digitalWrite(ledPin9, LOW);
  digitalWrite(ledPin8, HIGH);

}

  else if (ldrValue < ldrlevel3) {
  digitalWrite(ledPin8, LOW);
  digitalWrite(ledPin7, HIGH);
  
}

  else if (ldrValue < ldrlevel4) {
  digitalWrite(ledPin7, LOW);
  digitalWrite(ledPin6, HIGH);
  
}

  else if (ldrValue < ldrlevel5) {
  digitalWrite(ledPin6, LOW);
  digitalWrite(ledPin5, HIGH);
  
}

  else if (ldrValue < ldrlevel6) {
  digitalWrite(ledPin5, LOW);
  digitalWrite(ledPin4, HIGH);
  
}

  else if (ldrValue < ldrlevel7) {
  digitalWrite(ledPin4, LOW);
  digitalWrite(ledPin3, HIGH);
  
}

  else if (ldrValue < ldrlevel8) {
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin2, HIGH);
  
}

  else if (ldrValue < ldrlevel9) {
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin1, HIGH);
  
}

  else {
  digitalWrite(ledPin1, LOW);
  
}
}

Leave a Comment

+ 35 = 43