pulsein is giving values that to me don't make sense.

i am trying to use an arduino uno as a frequency counter. it is connected to 555 timer. the 555 timer generates pulse that are on for 1.9 seconds and is off for 1.8 seconds. i get a different reading every time.
in the 2000's, 3000's, sometimes 4000's. shouldn't i get 1900000? these readings do not make any sense to me.

unsigned long hu;
unsigned long lu;
double fru;
double ju;
void setup() {
// put your setup code here, to run once:
pinMode( 4, INPUT);

hu = pulseIn(4, HIGH, 3000000);



void loop() {
// put your main code here, to run repeatedly:


this is my code.

Have you tried pulseInLong() instead? It is designed for better behavior when the pulse is long, like in your case.

Also, what does your circuit look like? A schematic would be helpful.

Wow, the pulseIn() timeout is WAY off. With a 3,000,000 microsecond timeout, it returns in 2075 (+/-1) milliseconds! That's almost 33% fast. The pulseInLong() function produces the expected timeout of 3000 milliseconds.

Editing "wiring_pulse.c" to change the approximate number of clock cycles per loop iteration from 16 to 11 results in a much more accurate timeout of about 3018 milliseconds.

	// convert the timeout from microseconds to a number of times through
	// the initial loop; it takes approximately 16 clock cycles per iteration
	unsigned long maxloops = microsecondsToClockCycles(timeout)/11;

My test code:

void setup()
  pinMode( 4, INPUT_PULLUP);

void loop()
  static unsigned long previousMillis = 0;
  Serial.println(pulseIn(4, HIGH, 3000000UL));
  unsigned long currentMillis = millis();
  Serial.println(currentMillis - previousMillis);
  previousMillis = currentMillis;