• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Recording number of dig input state changes with Arduino


New Member
Hello, looking to connect a rotary encoder (TTL output) directly to arduino, monitoring one channel.

As motor turns 360 degrees, the state changes for one channel will be 1-0-0, or essentially 1 state change per turn.

How can i record how many state changes have been completed? Does anyone have any sample code i can use?

for example if i want to rotate the motor 50 turns, i will enable the motor, and after 50 turns, another digital output will be triggered which will communicate to a servo controller to STOP the motor.



Active Member
To me, what you are describing is a tachometer. There are many tutorials on using a magnet and a hall effect sensor to accomplish such a task. Here is one.
Searching will produce many more.

If you really want to use a rotary encoder like this one, there are also many such tutorials. Here is one.

Latest threads

EE World Online Articles