bastos (owner)

Revisions

gist: 109405 Download_button fork
public
Description:
Light Sensor Example with Arduino
Public Clone URL: git://gist.github.com/109405.git
Embed All Files: show embed
light_sensor.pde #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}