LDR

by brentscheerlinck in Circuits > Arduino

469 Views, 1 Favorites, 0 Comments

LDR

ldr-5mm-600x315w.jpg

An LDR-sensor is handy to detect light.

Supplies

image.jpg
2395961-40.jpg
unnamed.jpg
ldr-5mm-600x315w.jpg
R5010KS-2-500x500.jpg

Used materials:

  • 3 jumper wires.
  • Breadboard.
  • Arduino-board UNO.
  • USB for Arduino.
  • LDR sensor.
  • 10K resistor.
  • Computer or laptop.
  • Arduino Editor to import the code (https://create.arduino.cc/editor).

CONNECT THE WIRES

arduino-ldr-analog-236x280.jpg
  • Connect a wire with input 5V on the Arduino to F6 on the breadboard.
  • Connect the second wire with input CND on the Arduino to H13.
  • Connect the resistor between H12 and H9 on the same line as the LDR.
  • Connect the last wire with input A0 on the Arduino to F9.
  • Login on arduino editor to import the code from step 2.
  • If you open a new sketch you will see that there is already some code on it, remove that code and copy the code from step 2.
  • Paste the code on your empty sketch.

Programming

Screenshot 2022-01-14 12.59.01.png

#define LDRpin A0 // pin where we connected the LDR and the resistor


int LDRValue = 0;   // result of reading the analog pin


void setup() {

 Serial.begin(9600); // sets serial port for communication

}


void loop() {

 LDRValue = analogRead(LDRpin); // read the value from the LDR

 Serial.println(LDRValue);   // print the value to the serial port

 delay(100);          // wait a little

}

Save and Upload

Screenshot 2022-01-27 13.07.35.png
Screenshot 2022-01-27 13.10.03.png
Screenshot 2022-01-27 13.11.23.png
  1. Press the save button
  2. Press upload
  3. Press on monitor and see the results