JoeJohnson34
Member
Hello, I have an IR Breakbeam Sensor and am attempting to create a simple sketch to detect when the beam has been broken. I'm following the tutorial here https://learn.adafruit.com/ir-breakbeam-sensors/arduino (though this is not where I got my sensor from). digitalRead() returns 1 all the time and I am not sure why. I can confirm with my cellphone camera that the transmitter is working. I am not sure how to verify the receiver works. I've tried different pins. I've tried pinMode() of INPUT and INPUT_PULLUP. I've powered the sensor with both 3.3V and 5V. I've made sure the sensors are properly aligned and within range of each other (even tried them touching). Any tips on this? Below is the complete sketch:
Thanks
Code:
const int LEDPIN = 13;
const int SENSORPIN = 6;
void setup() {
pinMode(LEDPIN, OUTPUT);
pinMode(SENSORPIN, INPUT_PULLUP);
digitalWrite(SENSORPIN, HIGH);
Serial.begin(9600);
}
void loop() {
if(digitalRead(SENSORPIN)) {
Serial.println("Broken");
digitalWrite(LEDPIN, HIGH);
} else {
//never gets here
Serial.println("Unbroken");
digitalWrite(LEDPIN, LOW);
}
delay(1000);
}