- This event has passed.
IR Sensor
May 5, 2024 @ 8:00 am - 5:00 pm
What is an IR Sensor?
- IR sensor with Arduino and interface it with some components like an LED and a buzzer. We’ll make a setup where the LED lights up and the buzzer sounds when motion is detected by the IR sensor.
Components Needed.
- 1.Arduino board
- 2.IR sensor module
- 3.LED
- 4.Buzzer
- 5.Jumper wires
Wiring Connections:
- Connect the VCC pin of the IR sensor module to the 5V pin of the Arduino.
- Connect the GND pin of the IR sensor module to the GND pin of the Arduino.
- Connect the OUT pin of the IR sensor module to digital pin 2 of the Arduino.
- Connect the positive (anode) leg of the LED to digital pin 3 of the Arduino through a current-limiting resistor (220-330 ohms).
- Connect the negative (cathode) leg of the LED to the GND pin of the Arduino.
- Connect one terminal of the buzzer to digital pin 4 of the Arduino.
- Connect the other terminal of the buzzer to the GND pin of the Arduino.
Code:
- // Pin definitions
const int irSensorPin = 2;
const int ledPin = 3;
const int buzzerPin = 4; - void setup() {
pinMode(irSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
} - void loop() {
int irSensorValue = digitalRead(irSensorPin); - if (irSensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
Serial.println(“Motion detected!”);
delay(500); // Delay to avoid multiple detections in quick succession
} else {
digitalWrite(ledPin, LOW); // Turn off LED
digitalWrite(buzzerPin, LOW); // Turn off buzzer
}
}
