ansh2919
Published © GPL3+

Light Sensing

Turn on/off LED using LDR Sensor.

BeginnerProtip961
Light Sensing

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×7
5 mm LED: Red
5 mm LED: Red
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Code

LDR Sensor Code

Arduino
int ldrPin = A2;
int ledPin = 11;
int ldrValue;

void setup() {
  Serial.begin(9600);
  pinMode(ldrPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

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

  if (ldrValue <= 80) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

Credits

ansh2919
1 project • 8 followers
Contact

Comments

Please log in or sign up to comment.