Adafruit IR Breakbeam Sensor Reading problems.

Hi all,

I just bought an Adafruit IR Breakbeam Sensor for a project that I'm working on with color detection. After doing all the EE side of connections, I ran my long code with the IR connected to detect if the signal between the IR receiver and emitter is interrupted. Now, this works fine and once the signal is interrupted between the two, the code attached to my color sensor initiates. However, the problem is that even though the obstacle is removed, the IR sensor stays in the state of there being an obstacle between it and the IR emitter.

SO, as an attempt to debug, I just tried running the following simple code to detect the readings from the IR sensor, but I still get the same problem. At the beginning, when no obstacle is present, the pin from the IR sensor would read 1, but once it is interrupted, it would read 0 and would continue on reading 0 even when the obstacle is removed.

I would greatly appreciate any input, or feedback! :(((

Here is the simple example code I am running:

/* 
  IR Breakbeam sensor test code
*/
 

 
#define SENSORPIN 16

 
void setup() {
  // initialize the sensor pin as an input:
  pinMode(SENSORPIN, INPUT);     
  digitalWrite(SENSORPIN, INPUT_PULLUP); // turn on the pullup; was initially only set to HIGH, but I changed to input_pulllup
  
  Serial.begin(9600);
}
 
void loop(){
  // read the state of the pushbutton value:

Serial.println(analogRead(SENSORPIN)); 
}

I just bought an Adafruit IR Breakbeam Sensor

Please post a link to the exact sensor.

Please post a photograph that shows all your wiring.

Please read this:-
How to use this forum

#define SENSORPIN 16

Which Arduino are we talking about?
A15 is the highest on a Mega.

pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, INPUT_PULLUP); // turn on the pullup; was initially only set to HIGH, but I changed to input_pulllup

can be replaced with

pinMode(SENSORPIN, INPUT_PULLUP);

Those small Adafruit beambreak sensors use AFAIK constant (not modulated) IR light.
That makes them sensistive to ambient light.
Is there a light on the colour sensor, and how far are the gates apart.
Leo…