An IR (Infrared) beam break sensor is an electronic device that detects the presence or absence of an object based on the interruption of an infrared light beam. The sensor consists of an infrared emitter and a receiver. When an object passes between the emitter and receiver, the beam is broken, and the sensor outputs a signal indicating the event. This type of sensor is commonly used in applications such as security systems, manufacturing line item counting, and user input for electronics.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | OUT | Digital output signal |
// Define the pin connected to the IR beam break sensor
const int beamBreakPin = 2;
void setup() {
// Initialize the beamBreakPin as an input
pinMode(beamBreakPin, INPUT);
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Read the state of the beam break sensor
int beamState = digitalRead(beamBreakPin);
// Check if the beam is broken
if (beamState == LOW) {
// Beam is broken
Serial.println("Beam broken!");
} else {
// Beam is unbroken
Serial.println("Beam intact.");
}
// Small delay to avoid overwhelming the serial output
delay(100);
}
Q: Can the sensor be used outdoors?
Q: What is the maximum range of the sensor?
Q: How can I extend the range of the sensor?