Arduino LDR sensor + LED Tutorial


Hardware Required

  • Arduino Uno
  • LED
  • LDR (photo resistor) , Light Dependent Resistor
  • 220 and 10k ohm resistors
  • Wires
  • Breadboard


Schematic diagram





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 → Arduino D13
  4. The black wire attach o LED short leg → Arduino GND
 

LDR Connection

  1. LDR attach to board
  2. Resistor (10k ohm) attach to LDR one leg
  3. The Black wire attach to LDR other (empty) leg → Arduino Gnd
  4. The Yellow wire attach to LDR and resistor same column → Arduino A0
  5. The Red wire attach to resistor empty leg → Arduino 5V

Arduino Sketch


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 <=800) { 

digitalWrite(ledPin, HIGH);

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

}

else {

digitalWrite(ledPin, LOW);

Serial.println("LED OFF");

}

}

ความคิดเห็น