Code for counting pulses of a photoelectric sensor

I need a code for counting pulses of a photoelectric sensor. I put this code in arduino and not worked. Anyone know where I am going wrong?

int pulsos;
boolean pulso;
void setup()

{
  Serial.begin(9600);
  Serial.println("Iniciando...");
  pulso=HIGH;
  pinMode(2,INPUT);
}

void loop() 
{
 Serial.println(pulsos);
  if(digitalRead(2)==HIGH)
  {

    if(pulso==HIGH)
    {
      pulsos = pulsos + 1;
    }

    pulso=LOW;

  }
  
  else{
    pulso=HIGH;
  }


}

If you want a thread deleting, just ask - don't just delete your part of the dialogue, leaving orphan, pointless posts.

I put this code in arduino and not worked

Don't just keep saying it doesn't work - say what it does.

it has infinitely many times, the digital port is disconnected sensor (low)

, the digital port is disconnected sensor

You have a pull-down resistor on the input, or you've tied it to ground?

connected to ground.

I get a stream of zeroes.

In this code it tells nonstop even calling the digital port 0 in GND

#define PIN 0

int conta=0;
void setup()
{
  Serial.begin(9600);
  pinMode (PIN,INPUT);
  Serial.println("Iniciando...");
}


void loop()

{
  

  if (digitalRead(PIN)==HIGH);
  
  {
  conta++;
  Serial.println(conta);
  
 
  }
}
if (digitalRead(PIN)==HIGH);

I'm really bored with this game now - I've already pointed out the problem with this in your other thread.
That line is ONE character too long.

The other problem is that PIN has the value zero.
Look at your Uno or whatever, and see what else pin zero is used for.

I switched to

if(digitalRead(0)==HIGH)

and continues with the problem

And pin zero..?

int conta=0;
void setup()
{
  Serial.begin(9600);
  pinMode (0,INPUT);
  Serial.println("Iniciando...");
}


void loop()

{
  

  if (digitalRead(0)==HIGH);
  
  {
  conta++;
  Serial.println(conta);
  
 
  }

I give up.