You are here

10 December 2011

Arduino light sensor circuit tutorial shows how to connect light sensor to Arduino and how to use it in your programs. Light sensor measures light intensity and you can read it with Arduino using an Analog Input.

Required components for arduino light sensor:

 
Source code viewer
// Makes LED on your Arduino development board blink at different rate, depending on the amount of light on the sensor.   // Select input pin for the photocell light sensor. int LDR = 0; // Select the pin for the LED int ledPin = 13; // Variable to store the value coming from the sensor. int val = 0;   void setup() { // Declare LDR as an input pin. pinMode(LDR, INPUT); // Declare ledPin as output led pin, in this case it's the surface mounted led on Arduino. pinMode(ledPin, OUTPUT); }   void loop() { // Read current value from the sensor. val = analogRead(LDR); // Turn led on. digitalWrite(ledPin, HIGH); // Delay depending on val. delay(val); // Turn led off. digitalWrite(ledPin, LOW); // Delay depending on val. delay(val); }
arduino light sensor circuit breadboard
arduino light sensor circuit schema