IR Proximity Sensor (Pack of 25) Documentation
The IR Proximity Sensor is a compact and versatile sensor that detects objects or people within a certain range using infrared technology. This sensor is ideal for various applications, including robotics, smart home automation, and interactive installations. This pack of 25 sensors is perfect for prototyping, proof-of-concept projects, or large-scale deployments.
The IR Proximity Sensor has three pins:
VCC: Power supply (3.3V to 5V)
GND: Ground
OUT: Digital output (HIGH or LOW)
Detection range: 10 cm to 80 cm (adjustable)
Supply voltage: 3.3V to 5V
Output type: Digital (TTL compatible)
Response time: 10 ms
Power consumption: 5 mA (typical)
### Example 1: Basic Obstacle Detection (Arduino)
In this example, we'll connect the IR Proximity Sensor to an Arduino board to detect obstacles within a certain range.
```arduino
const int sensorPin = 2; // Digital input pin for the sensor
const int ledPin = 13; // Built-in LED pin for indication
void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int sensorState = digitalRead(sensorPin);
if (sensorState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED if an obstacle is detected
} else {
digitalWrite(ledPin, LOW); // Turn off the LED if no obstacle is detected
}
delay(50);
}
```
### Example 2: Smart Home Automation (Raspberry Pi with Python)
In this example, we'll use the IR Proximity Sensor with a Raspberry Pi to trigger a relay module when an object is detected within a certain range.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define sensor and relay pins
sensorPin = 17
relayPin = 18
# Set up sensor pin as input and relay pin as output
GPIO.setup(sensorPin, GPIO.IN)
GPIO.setup(relayPin, GPIO.OUT)
while True:
sensorState = GPIO.input(sensorPin)
if sensorState == 1:
print("Object detected!")
GPIO.output(relayPin, GPIO.HIGH) # Turn on the relay
else:
print("No object detected.")
GPIO.output(relayPin, GPIO.LOW) # Turn off the relay
time.sleep(0.1)
```
### Example 3: Interactive Installation ( CircuitPython with Micro:bit)
In this example, we'll use the IR Proximity Sensor with a Micro:bit board to create an interactive installation that displays a message on the LED matrix when an object is detected.
```python
import microbit
import utime
# Define sensor pin
sensorPin = microbit.pin0
while True:
sensorState = sensorPin.read_digital()
if sensorState == 1:
microbit.display.scroll("Hello!") # Display a message on the LED matrix
utime.sleep(1) # Wait for 1 second
utime.sleep(0.1) # Check the sensor every 0.1 seconds
```
Make sure to adjust the sensor's detection range according to your specific application requirements.
Use a suitable power supply for the sensor, and ensure that it operates within the recommended voltage range.
When using the sensor with microcontrollers, ensure that the output pin is compatible with the microcontroller's input voltage threshold.