Skip to content

Instantly share code, notes, and snippets.

Created September 14, 2012 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3720060 to your computer and use it in GitHub Desktop.
Save anonymous/3720060 to your computer and use it in GitHub Desktop.
LDR
/*
** Nightlight LDR test program
** Created 06 Feb 2010
**
** This example code is in the public domain.
** www.hobbytronics.co.uk
*/
int sensorPin = A0; // select the input pin for the ldr
unsigned int sensorValue = 0; // variable to store the value coming from the ldr
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600); // start serial for output - for testing
}
void loop()
{
// read the value from the ldr:
sensorValue = analogRead(sensorPin);
if(sensorValue<400) digitalWrite(13, HIGH); // set the LED on
else digitalWrite(13, LOW); // set the LED on
// For DEBUGGING - Print out our data, uncomment the lines below
//Serial.print(sensorValue, DEC); // print the value (0 to 1024)
//Serial.println(""); // print carriage return
//delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment