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 IR=6; //IR sensor block is connected to digital pin 6
int BUZZER=2; //Buzzer block is connected to digital pin 2
void setup() {
// put your setup code here, to run once:
pinMode(IR,INPUT); //Declaring IR sensor as input device
pinMode(BUZZER,OUTPUT); //Declaring BUZZER as output device
}
void loop() {
// put your main code here, to run repeatedly:
int a=digitalRead(IR);
if (a==0)
{
digitalWrite(BUZZER,HIGH); //If sensor senses any object, buzzer will start buzzing.
}
if (a==1)
{
digitalWrite(BUZZER,LOW); //If sensor does not sense any object, buzzer will be OFF.
}
}
Output:
Once the code is uploaded, we can hear that the Buzzer 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!