Created
May 9, 2009 21:10
-
-
Save bastos/109405 to your computer and use it in GitHub Desktop.
Light Sensor Example with Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LDR = 0; // select the input pin for the LDR | |
int lightOnPin = 13; // select the pin for the LED | |
int val = 0; // variable to store the value coming from the sensor | |
int turnOnValue = 1000; | |
void setup() { | |
pinMode(LDR, INPUT); // declare the LDR as an INPUT | |
pinMode(lightOnPin, OUTPUT); // declare the ledPin as an OUTPUT | |
Serial.begin(9600); | |
} | |
void loop() { | |
val = analogRead(LDR); // read the value from the sensor | |
Serial.print(val); | |
if (val >= turnOnValue) { | |
digitalWrite(lightOnPin, HIGH); // turn the ledPin on | |
} else { | |
digitalWrite(lightOnPin, LOW); // turn the ledPin off | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment