Najad
Published © GPL3+

LDR With Arduino

In this tutorial, we are going to learn about how to use Light Dependent Resistor with Arduino

BeginnerProtip2,528
LDR With Arduino

Things used in this project

Hardware components

UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1
UTSOURCE Arduino UNO
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1
LED (generic)
LED (generic)
×1

Story

Read more

Schematics

ldr_with_arduino_circuit_lfyTjbPdZT.jpg

Code

Code snippet #1

Arduino
//https://diyustahd.com
//https://youtube.com/diyusthad

const int ledPin = 13; //pin at which LED is connected

const int ldrPin = A0; //pin at which LDR is connected

int threshold = 600;

void setup() {

  Serial.begin(9600);

  pinMode(ledPin, OUTPUT); //Make LED pin as output

  pinMode(ldrPin, INPUT); //Make LDR pin as input

}

void loop()
{

  int ldrStatus = analogRead(ldrPin); //saving the analog values received from LDR

  if (ldrStatus <= threshold) //set the threshold value below at which the LED will turn on
  {                     //you can check in the serial monior to get approprite value for your LDR

    digitalWrite(ledPin, HIGH);  //Turing LED ON

    Serial.print("Its DARK, Turn on the LED : "); 

    Serial.println(ldrStatus);

  }

  else

  {

    digitalWrite(ledPin, LOW); //Turing OFF the LED

    Serial.print("Its BRIGHT, Turn off the LED : ");

    Serial.println(ldrStatus);

  }

}

Credits

Najad

Najad

30 projects • 95 followers
Just crazy stuff​

Comments