1. //january 8, 2015
  2. // Light on/off
  3. // LED changes color depending on darkness that photo
  4. // resistor receives
  5. int Pr = 0; // will be used for analog 0.
  6. int PrValue = 0; // value of output
  7. int Pr_Input = 700; // value of when light is on
  8. void setup()
  9. {
  10. Serial.begin(9600); //start serial Monitor
  11. pinMode(13, OUTPUT); // pin 13 as output
  12. }
  13. void loop()
  14. {
  15. PrValue = analogRead(Pr);
  16. Serial.println(PrValue); //prints photoresistor value
  17. delay(100); // value updated every 0.1 second.
  18. if (PrValue < Pr_Input) // if sensor value is less than 700, light will turn on.
  19. {
  20. digitalWrite(13, HIGH); //turns on LED
  21. }
  22. else
  23. {
  24. digitalWrite(13, LOW); // LED off
  25. }
  26. }