digitalRead() make random values if the pin is not connected to something

Hi, Like I said: digitalRead() make random values if the pin is not connected to something

but I want to know how long it took to read from "1", until the next "1"

Explain: I have a electric motor, and i want to know how much time it cost to make a Lap..

when the motor make a lap, touch a wire, and it send the signal "1", when it make another Lap, send another "1", i want to know THAT time.

But when I play code, make Random values (1100010001011010101000)

¿HOW I CHANGE THAT?
Thanks.

look at input_pullup under learning references or install a 10k resistor between the digital input pin and negative to keep the pin pull down.

The instruction pinMode(pinNumber, INPUT_PULLUP); connects the pin to 5v through an internal resistor. That means that the unconnected pin reads HIGH and your switch should be arranged to connect the pin to GND.

...R

Lupax7:
Hi, Like I said: digitalRead() make random values if the pin is not connected to something

Exactly what you would expect.

when the motor make a lap, touch a wire, and it send the signal "1", when it make another Lap, send another "1", i want to know THAT time.

Don't cross-post. Your other thread deleted.