p05_LightControlLED.ino 706 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. Demo code for Project 5 Light Control LED
  3. Read the light information and then control led on or off.
  4. by Maker Studio
  5. http://makerstudio.cc
  6. */
  7. int sensorPin = A0; // select the input pin for the light sensor
  8. int ledPin = 9; // select the pin for the LED
  9. int sensorValue = 0; // variable to store the value coming from the sensor
  10. void setup() {
  11. // declare the ledPin as an OUTPUT:
  12. pinMode(ledPin, OUTPUT);
  13. }
  14. void loop() {
  15. // read the value from the sensor:
  16. sensorValue = analogRead(sensorPin);
  17. if(sensorValue < 300){
  18. // turn the ledPin on
  19. digitalWrite(ledPin, HIGH);
  20. }else{
  21. // turn the ledPin off:
  22. digitalWrite(ledPin, LOW);
  23. }
  24. }