I am using a simple sketch to measure the length of the pulse for both HIGH and LOW. Some times the HIGH or LOW length is zero. Did anyone had a similar issue?
This is the sketch
int pin = 0;
unsigned long duration_H;
unsigned long duration_L;
unsigned long counter;
//unsigned long timeout = 1000;
void setup()
{
pinMode(pin, INPUT);
}
void loop()
{
duration_H = pulseIn(pin, HIGH);
duration_L = pulseIn(pin, LOW);
if(duration_H>100){
counter++;
}
Serial.print("Duration high: "); Serial.println(duration_H);
Serial.print("Duration low: "); Serial.println(duration_L);
Serial.print("Counter: "); Serial.println(counter);
}
Did you read the part about it returning 0 when it times out? Only you know what pulse train it is that you're measuring but are you certain that the pulses are so regular that it can never time out? You could always add prints of millis() before and after the pulseIn(pin, HIGH) to get some idea.