LED Control With LDR and Arduino

LED Control With LDR and Arduino



    Youtube Tutorial:-



    Components Required:-
  1. Arduino Uno
  2. Breadboard
  3. led light
  4. LDR
  5. Resistor 200 ohm *1
  6. Resistor 10k ohm *1
  7. jumper wire
    Circuit Diagram:- 

            Watch full Youtube video for diagram

    Code:-
    //set pin numbers

    //const won't change

    const int ledPin = 13;   //the number of the LED pin

    const int ldrPin = A0;  //the number of the LDR pin

    void setup() {

      Serial.begin(9600);

      pinMode(ledPin, OUTPUT);  //initialize the LED pin as an                 output

      pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input

    }

    void loop() {

     Int ldrStatus = analogRead(ldrPin);   //read the status of the LDR     value

      //check if the LDR status is <= 300

      //if it is, the LED is HIGH 

       if (ldrStatus <=300) {

        digitalWrite(ledPin, HIGH);               //turn LED on

        Serial.println("LDR is DARK, LED is ON");

       }

  else {

    digitalWrite(ledPin, LOW);          //turn LED off

    Serial.println("---------------");

      }

    }

   

Post a Comment

0 Comments