⭐ Q15. IR Sensor (Object Detection)
Hindi:
IR sensor का उपयोग करके object detect करने का प्रोग्राम लिखिए।
English:
Write an Arduino program to detect objects using IR sensor.
🔧 Components
Arduino Uno
IR Sensor
LED (optional)
🔌 Connections
IR Output → Pin 8
LED → Pin 13
✅ CODE
void setup() {
pinMode(8, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
int val = digitalRead(8);
if (val == 0) {
digitalWrite(13, HIGH);
Serial.println("Object Detected");
} else {
digitalWrite(13, LOW);
Serial.println("Object Not Detected");
}
delay(100);
}
📘 Working
IR rays किसी object से टकराकर वापस आती हैं, जिससे Arduino object detect करता है।