QTI RCtime

Here is my problem, I use a sensor QRD1114 with my UNO and I don’t have any problem. I just bought a Zero, I make the same connection with the same program and it does not work.
I do not understand. Could you give me any help?

Thank You

Here is the test code:

Test QTI

*/

// SETUP PINS

// – QTI –
#define QTIL 9 //Connecté à Arduino pin 9

int qtiVal = 0;
long setPointDef = 25; // Default value in case we don’t use de calibration procedur

void setup() {
pinMode(13, OUTPUT);
// initialize serial communication
Serial.begin(115200);

}

// Main loop of program
// Repeat forever

void loop() {

if ( QTI(QTIL) ) {
digitalWrite(13, HIGH);
// delay(2000);
}
else
{
digitalWrite(13, LOW);
// delay(2000);
}
}

//# QTI procedur ###
//

bool QTI(int sensorIn) {
long duration = 0;
bool line = false;

pinMode(sensorIn, OUTPUT); // Make pin OUTPUT
digitalWrite(sensorIn, HIGH); // Pin HIGH (discharge capacitor)
delay(1); // Wait 1ms
pinMode(sensorIn, INPUT); // Make pin INPUT
digitalWrite(sensorIn, LOW); // Turn off internal pullups
while (digitalRead(sensorIn) & duration <= setPointDef * 2) { // Wait for pin to go LOW
duration++;
}
if (duration < setPointDef) line = true;
return line;
}

Try to remove this line in your QTI procedur :

digitalWrite(sensorIn, LOW);   // Turn off internal pullups

And maybe you really need to set the pin PULLUP mode if you're polling the low state :

  pinMode(sensorIn, INPUT_PULLUP);      // Make pin INPUT with internal PULLUP resistor

Hello,

Thank you for your help. Unfortunately this does not work! With Zero, there are two changes the 3.3v and speed of execution can this have an effect?