An Infrared (IR) Proximity Sensor is an electronic device that utilizes infrared radiation to detect the presence or absence of objects within its proximity. It emits an infrared signal and then measures the reflection to determine the distance to an object. This sensor is commonly used in various applications, including robotics for obstacle avoidance, security systems, and automatic faucets or soap dispensers.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | OUT | Output signal (Digital or Analog) |
4 | EN | Enable pin (optional, not present on all models) |
// Define the sensor output pin
const int sensorPin = 2; // Digital pin connected to the sensor's output
void setup() {
pinMode(sensorPin, INPUT); // Set the sensor pin as an input
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
int sensorValue = digitalRead(sensorPin); // Read the sensor output
if (sensorValue == HIGH) {
// Object detected
Serial.println("Object Detected!");
} else {
// No object detected
Serial.println("No Object Detected");
}
delay(100); // Wait for 100 milliseconds before reading again
}
Q: Can the sensor detect any material? A: The sensor is generally effective with most materials, but its sensitivity can vary depending on the object's surface and color.
Q: What is the maximum range of the sensor? A: The maximum range depends on the specific model of the sensor, but it is typically around 30cm.
Q: Can the sensor work in outdoor environments? A: Direct sunlight can interfere with the sensor's operation. It is best used in controlled indoor environments.
Q: How can I increase the sensor's range? A: The range is a fixed characteristic of the sensor. However, ensuring proper alignment and avoiding interference can help achieve the best performance within its specified range.