LDR Light Sensor
Size 5mm
Product features
|
Product description
Component Details: Size: 5mm, Dark Resistance: 0.5M Ohm, Light Resistance: ~5-10KOhm
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 <= 200) {
digitalWrite(ledPin, HIGH);
Serial.print(“Its DARK, Turn on the LED : “);
Serial.println(ldrStatus);
} else {
digitalWrite(ledPin, LOW);
Serial.print(“Its BRIGHT, Turn off the LED : “);
Serial.println(ldrStatus);
}
}