# PulseIn function to measure frequency

Hello, As I understand pulseIn function is used in measuring time for high or low pulses,
but iam using color sensor and to get the color frequency PulseIn(pin,LOW); is used
How could we get the frequency by measuring the low pulse time?

T = Tlow + Thigh

F = 1/T

So should i measure the high time and low time?
In this code and almost all codes i find they measure only the low time
and this is what i don't understand why only low :"D
like here:

``````digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
red = pulseIn(outPin, LOW); // Reading RED component of color

digitalWrite(s2, HIGH);
digitalWrite(s3, HIGH);
grn = pulseIn(outPin, LOW); // Reading GREEN component of color

digitalWrite(s2, LOW);
digitalWrite(s3, HIGH);
blu = pulseIn(outPin, LOW); // Reading BLUE component of color
``````

tastefulcone5:
Hello, As I understand pulseIn function is used in measuring time for high or low pulses,
but iam using color sensor and to get the color frequency PulseIn(pin,LOW); is used
How could we get the frequency by measuring the low pulse time?

This is true only when the positive time is equal to the negative time. Frequency itself is the based on the time between one transition to the next identical transition. Transition can be either low to high or high to low. What you are getting is just the time of either the high voltage or the time of the low voltage. This could be 5 minutes, followed by a 1 microsecond transition to the opposite voltage.

Well, the pulse length function will time out long before that happens.

Paul

tastefulcone5:
In this code and almost all codes i find they measure only the low time
and this is what i don't understand why only low :"D

Because a lot of code is written and then promoted on the internet by beginners that don't have any science or engineering background.

It could be that the HIGH part of the cycle is either fixed length or in a fixed proportion to the LOW part of the cycle. In either case, the LOW part of the cycle is proportional to the frequency. You would have to look at the specification of the sensor to see if either of those conditions is true.

The safe way is to measure both HIGH and LOW pulses, and add them to get the signal period. My first post offers that hint.

@astefulcone5

Why did you start two topics on the same subject ?

The other one, which had no replies, has been deleted