Arduino - LDR With LED

68,617

82

13

About: Arduino, Raspberry Pi, esp8266, Tutorials, Projects

This is simple arduino project; turn on LED when it's dark and turn off when is light.

Supplies:

Step 1: Hardware Required :

  • Arduino Uno
  • LED
  • LDR (photoresistor)
  • 220 and 10k ohm resistors
  • Wires
  • Breadboard

Step 2: LED Connection

  1. LED attach to board
  2. Resistor (220 ohm) one leg attach to LED long leg
  3. The green wire attach to resistor's empty leg
  4. The brown wire attach o LED short leg

Step 3: LDR Connection

  1. LDR attach to board
  2. Resistor (10k ohm) attach to LDR one leg
  3. The purple wire attach to LDR other (empty) leg
  4. The yellow wire attach to LDR and resistor same column
  5. The white wire attach to resistor empty leg

Step 4: Arduino Connections

  1. The green wire connect to digital 13 from resistor leg
  2. The brown wire connect to GND from LED short leg
  3. The purple wire connect to +5V from LDR
  4. The yellow wire connect to A0
  5. The white wire connect to GND

Step 5: Code

const int ledPin = 13;

const int ldrPin = A0;

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <=300) {

digitalWrite(ledPin, HIGH);

Serial.println("LDR is DARK, LED is ON");

}

else {

digitalWrite(ledPin, LOW);

Serial.println("---------------");

}

}

Step 6: If It Helps, Please Subscribe

First of all, I would like to thank you for reading this guide ! I hope it helps you.

If you want to support me, you can subscribe my channel and watch my videos.

Mert Arduino Tutorial & Projects

2 People Made This Project!

Recommendations

  • Gardening Contest

    Gardening Contest
  • Fandom Contest

    Fandom Contest
  • Woodworking Contest

    Woodworking Contest

13 Discussions

0
None
FernandoL3RahulN74

Reply 7 weeks ago

It limits the current flowing through the LED so neither the LED or the Arduino port burns up.

0
None
Pradip patil

6 months ago on Step 5

Sir I need a program code for using two Arduino Tx as led and Rx as ldr serial communication between them lifi system.

0
None
jagganath

8 months ago

which type of LDR did you use ? GL5506...GL5539 ?

0
None
tptaypun

1 year ago

I tried this and the LED light stays on despite what the input from the LDR says. The LED light on the Arduino board responds to the LDR but the LED doesn't.

What's wrong???

0
None
AndreiG43

1 year ago

Can somebody please explain what is the purpose of the resistor next to the LDR?
That is the only part that i do not understand.

2 replies
0
None
Tarantula3AndreiG43

Reply 1 year ago

10k resistor along with the LDR to create a voltage divider circuit. The varying resistance of the LDR is converted to a varying voltage that the analog pin of the Arduino will then be using in its logic.

0
None
blic19933AndreiG43

Reply 1 year ago

The 10k resistor creates a voltage divider circuit. The varying resistance of the ldr is converted to a varying voltage that the analog pin of the Uno can use.

0
None
ChitA2

1 year ago

Thank

0
None
fcfelix

2 years ago

This is a very nice tutorial if you want to extend the circuit to more complex functions afterwards. Will for sure be useful to many tinkers. For a basic circuit like this no Arduino is needed, there are instructables on this.