Arduino Interface LDR.JPG

Code

  1. /*
  2. Lets measure the light in the room with LDR
  3. Turns on an LED on , then off , repeatedly according to the Light.
  4. */
  5.  
  6. // Pin 13 has an LED connected on most Arduino boards.
  7. // LDR is connected to analog input A0 as shown in Diagram.
  8. // give it a name:
  9. int led = 13;
  10. // the setup routine runs once when you press reset:
  11. void setup() {
  12. // initialize the digital pin as an output.
  13. pinMode(led, OUTPUT);
  14. }
  15. // the loop routine runs over and over again forever:
  16. void loop() {
  17. digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
  18. delay(1000); // wait for a second
  19. digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
  20. delay(1000); // wait for a second
  21. }