In the Arduino projects that I completed so far, I really enjoyed the ones including a LDR (light dependent resistors). So I made the following project.

At the highest light intensity green led blinks, at an intermediate intensity yellow blinks faster and at low light red blinks more faster.

[youtube=http://www.youtube.com/watch?feature=player_embedded&v=nGHlc32dCFI]

RYG Lights with LDR yigitaltay-448572357185464002_6011624

 

and here is the code:

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin1 = 11; // select the pin for the red LED
int ledPin2 = 10; // select the pin for the yellow LED
int ledPin3 = 9; // select the pin for the green LED

int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPins as an OUTPUT:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {

// read the value from the sensor:
sensorValue = analogRead(sensorPin);

if (sensorValue <= 20) {

// turn the ledPin on
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);

delay(100);
// turn the ledPin off:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
delay(100);
}
if  (sensorValue < 100 && sensorValue > 20) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);

delay(200);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
delay(200);
}

if (sensorValue >= 100) {

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);

delay(400);

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);

delay(400);
}
}

 

Share this:

One Comment to “Arduino Projects No.2: LDR controlled blinking LEDs”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.