pulse length in microseconds

Hello, I need help for my problem with measurement of pulse length in microseconds. I need to count microseconds until I have output logic 1. I was try with millis(), but it did not work properly. Please if you know help me I will very grateful.

use pulseIn()

There’s also the “micros()” micro which works the same as “millis()” but with microseconds. Of course “micros()” can’t be any more precise than the loop in which it is used. “pulseIn()” would likely produce better results than trying to use “micros()”.

What is the length/duration (approx) of the pulse you want to measure?

It will for alternator for measure of frequency. I think 20 ms.

20ms is value for 50Hz, but sometimes can be more or less. But I suppose about 20 ms. And pulseIn I tried but dont returns good time. I dont know why, can be that I dont try good, I try some code from google too but this dont work too. I will read 0 or 1 from IR transistor every turn.

Please post a clear picture of a hand drawn (not Fritzing) schematic diagram of your circuitry.

Can you tell us what you're trying to do?

Wanting to measure pulses at 50Hz has got me wondering if you want to capture signals from a RC receiver.

I have IR led and IR transistor. IR led light to shaft (is there a small mirror) and every turn reflect IR signal to transistor. When transistor receive signal will logic 0. I count turn per second.

This is my schematic diagram for led and transistor http://letsmakerobots.com/files/userpics/u559/ir.jpg

But now my code work good. Tomorrow I will try with motor, if it return 50Hz so it will ok.

Measuring freq of an alternator... I've done this using pulseIn() and it works fine... but

1/ You probably need a litttle signal conditioning to get a clean rail - to - rail input to the input pin.
A single capacitor of 1uF to a single transistor is OK.

2/ The signal may not be symmetrical, so use pulseIn(pin,LOW) , then pulseIn (pin.HIGH)
to get the asymmetrical halves, then add them for total pulselength. 1e6/this gives frequency.

REGARDS

aLLAN.