Joshua's Thoughts

arduino + photoresistor + led

Tags: , , ,

i spent a little time last night playing with arduino and i thought i’d share this little experiment i put together.


Arduino + Photo Resistor + LED from Joshua McGinnis on Vimeo.

here’s the source:

/*
 * Power LED on Dark by Joshua McGinnis
 *
 * This basic example uses a photo resistor to determine
 * whether light is present or not. If it is not, an led
 * will be set to high.
 *
 * http://www.joshuamcginnis.com
 */

int photoPin = 1; // designate pin 1 as the analog in for the photo resitor
int val = 0;

int ledPin = 13; // designate pin 1 as the analog in for the photo resitor

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT); // set the pin
  pinMode(ledPin2,OUTPUT); // set the pin
}

void loop()                     // run over and over again
{

  val = analogRead(photoPin); // set val equal to the resitor input

  if(val == LOW) { // if nothing from photo resistor (low light), turn on led

    digitalWrite(ledPin, HIGH);
    delay(500);

  } else {
    digitalWrite(ledPin, LOW);
  }
  Serial.println(val);
}

No Comments, Comment or Ping

Reply to “arduino + photoresistor + led”