Arduino LDR shield

  

This LDR shield is often available on eBay for about £1 with free postage. It has 4 pins, 5volts, GND, Digital Output and Analog Output. There are two leds, one for power and the other shows the state of the digital output. There is a potentiometer that is used to set the trip level, this output goes LOW when the light level is greater than the trip level. The output from the analog output decreases as the light level increases and is about 1000 mv in darkness to about 50 mv in bright light. 

 The following simple sketch displays the outputs on the Serial Monitor and there is a delay that reduces the output to a reasonable rate. The four pins are plugged into the Analog pins A0 to A3, power is supplied from pins A2 and A3, A0 is set as an Analog input and A1 is set as a Digital input.

Before using this sketch make sure your board pin outs match the board shown in the picture above.   

/***********************************************************

LDR board

this sketch reads the Analog and Digital outputs
and displays them on the serial monitor.
The digital output could be used to activate an alarm etc

Connections:

AO to Arduini A0 - the analog output
DO to Arduino A1 - the digital output
GND to Arduino A2 - supplies gnd
Vcc to Arduino A3 - supplies 5 volts

The output of the LDR falls from about 1000mv in darkness to about 50 mv in bright light
The digital output goes LOW lighting an LED on the LDR board
when the light is brighter than the set trip level.
Use the potentiometer to adjust the trip level.

***********************************************************/

int analog = 14; // Arduino A0
int digital = 15; // Arduino A1
int gnd = 16; // supplies 0 volts
int power = 17; // supplies 5 volts

void setup() {
Serial.begin(9600); // start Serial Monitor
pinMode(13, OUTPUT);
digitalWrite(13,LOW); // turn OFF the LED on Arduino pin 13
pinMode(digital, INPUT); // this pin reads the digital output, either HIGH or LOW
pinMode(power, OUTPUT);
digitalWrite(power,HIGH);// this pin will supply 5 volts
pinMode(gnd, OUTPUT);
digitalWrite(gnd,LOW); // this pin will supply the GND to the board
}

void loop() {
// print the analog output in milli volts
Serial.print("Analog level = ");
Serial.print(analogRead(analog));
Serial.println(" mv"); // milli volts
// print the digital Output LOW = alarm tripped
Serial.print("Digital level =");
if (digitalRead(digital) == HIGH){
Serial.println(" HIGH");
}
else{
Serial.println(" LOW");
}
delay (1000); // this just makes it easier to read the serial output.

}

Advertisements

2 thoughts on “Arduino LDR shield”

    1. Thanks for that, the mistake was in the comments, the actual sketch was OK. I have corrected the mistake and changed the picture to show the board used in this page. The original picture showed a three pin version.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s