how to control motor with wheel encoder and photo sensor

guys i need to know how the photos sensor is used along with arduino to position control a motor !! can someone explain me with a example code !!

for you to understand my exact requirement ! just get the perspective of a working printer with photo sensors and wheel encoder !! i want this type !! but have no idea of how to interface the photo sensor and wheel encoder with arduino to control the motor ! im using arduino uno and nano

thank you

download (1).jpg

Which photo sensor?

Is your ! key broken?

the photo interrupter sensors which is used in printers !

Basically there are three parts:

1) reading the sensor and maintaining a variable with the current count. 2) code that drive the motor forwards or backwards in proportion to a signed error signal 3) a feedback loop (such as PID controller) mapping error in position to motor drive signal

Here’s the OP’s pic inline!!!


MarkT yes i can understand the algorithm ! but im not okay with the code !! can some one explain me this with an example code

but im not okay with the code !!

What code?

The interrupter will read as a HIGH or a LOW on a digital on, depending on how it is wired. How you treat that HIGH or LOW depends on you.

(Please, turn your keyboard over and give it a shake - that sticking ! key is starting to get irritating)