Pulse counter using Arduino

Hello all, I’m making pulse counter(high pulses) generated by one arduino and counting it on another. It works but not the way I want. Suppose I’m sending 5 pulses (high and low of 1ms each), then output should be 5 right… but I get: 1 2 3 4 5…like this on the Serial monitor. Here’s the code I’m using.

void loop()
{
  ton=pulseIn(in_pin,HIGH);
  if (ton > 900 && ton < 1100)
  {
    pulse_data++;
  }
  else
  {
    pulse_data = 0;
  }
  
  Serial.println(pulse_data);
}

Can anyone please help me modify the code so that it prints 5. I can’t use interrupt pins as I’m using them for another task.

  • Solved it myself....just had to wait for the timeout.

kzkhan98:

  • Solved it myself....just had to wait for the timeout.

Well, ok, if your program does not need to do anything else during that time period.
Paul

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.