Scan the QR to open the code. Copy the code and paste it in your Arduino IDE.
Once you paste the code in Arduino IDE, Compile the code and upload it in the Arduino Nano.
Code:
int LDR=6; //Light sensor is connected to digital pin 6
int LED=2; //Bright LED is connected to digital pin 2
void setup() {
pinMode(LDR,INPUT); //Declaring Light sensor as input device
pinMode(LED,OUTPUT); //Declaring Bright LED as output device
}
void loop() {
int a=digitalRead(LDR);
if (a==1)
{
digitalWrite(LED,LOW); //If Light sensor senses sunlight, Bright LED will remain OFF
}
if (a==0)
{
digitalWrite(LED,HIGH); //If Light sensor does not sense any sunlight, the Bright LED will turn ON
}
}
Output:
Once the code is uploaded, we can see that the Bright Led on pin 2 turns ON when you place a hand near the Light Sensor on pin 6 then it turns OFF once your hand moves away from it.
Login
Accessing this course requires a login. Please enter your credentials below!