In this tutorial we are going to demonstrate how to use the LDR (Light Dependent Resistor) in your 14Core Starter Kit, we are going to adjust the speed of flashing base on LDR Light Dependent Resistor.
Parts Required:
Arduino UNO/MEGA/MINI/PRO
1x LED Any color
100k Resistor
3x 1k 5 Ohms Resistor
Jumper Wire
Solder-less Breadboard
Wiring the components
Arduino Sketch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* 14CORE LDR -for 14CORE Starter Kit */ int ledPin = 6;// D6 Pin connected to LDR int ldrPin = 0;// A0 Value read from LDR int lightVal = 0; void setup()// Set both pins as outputs { pinMode(ledPin, OUTPUT); } void loop() { lightVal = analogRead(ldrPin); // Read in value from LDR digitalWrite(ledPin, HIGH); // Turn LED on delay(lightVal); // Delay of length lightVal digitalWrite(ledPin, LOW); // Turn LED off delay(lightVal); // Delay } |
Light Sensor using LDR Light Dependent Resistor