Problem with photo-sensors

Hi everybody !
I just got my Arduino Uno and I’m new on this forum, so excuse me if I’m wrong posting in this section.
I’m having trouble with the KTIR 0611S sensor ( datasheet :
Here’s my setup : anode to 5V, cathode to digital pin 2 (OUPUT and LOW), collector to pin 5 (INPUT and HIGH, for the pull-up resistor) and emitter to GND.
The program is quiet simple :

const int emet1 = 2;
const int emet2 = 3;
const int recep1 = 5;
const int recep2 = 6;

void setup () {
  pinMode (emet1, OUTPUT);
  pinMode (emet2, OUTPUT);
  pinMode (recep1, INPUT);
  pinMode (recep2, INPUT);
  digitalWrite (emet1, LOW);
  digitalWrite (emet2, LOW);
  digitalWrite (recep1, HIGH);
  digitalWrite (recep2, HIGH);
  Serial.begin (9600);

void loop () {
  Serial.print (digitalRead (recep1));
  delay (500);

(there are 2 emitters (the pins for the anode) and 2 receptors (the inputs) because there’s two sensors in the final version)
But only “1” are displayed, except of course when I directly connect the input to the GND…

Thank you in advance :slight_smile:

You should put in a resistor to keep the LED current well below the 40 mA maximum. The LED forward voltage is 1.2 so the voltage drop across the resistor is (5-1.2) 3.8. To get 30 mA at 3.8V you need about 127 Ohms. Pick the next higher available size (130 or 150). It doesn't matter if you put the resistor on the Anode side or the Cathode side.

At 30 mA input to the LED you will get about 4.5 mA going through the phototransistor.

Oh, you're right I really need a resistor :sweat_smile:
But if the sensor was damaged, it would open the circuit ? But when I connect another normal LED between the photo-sensor and GND, the LED turn on.
Thanks for your answer