Pid control dc motor with encoder

Iam working on control speed and postion of dc motor
with measurment speed sensor encoder in one direction
So, i want to know some information or any one have an code about this to help me because is the first work on pid.... Thanks alot

PID is fun but too complex for most projects. Start from the basics:

  1. Can you read the encoder and get a reliable position readout? (Turn the motor by hand if necessary.)

  2. Can you drive the motor back and forth at different speeds?

  3. Do you have a target position?

  4. Can you drive towards that position using more speed when further away?

I've deleted your other cross post/hijack @Bassam_mahrous22.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

You can refer to a project on Arduino Project Hub