PID Arduino Coding

i am trying to control a DC motor with encoder through PID algorithm. i have L298n motor driver. now, i am confused in writing its program. can anybody help me

You need to read the encoder to get the actual position (input), maintain a desired position variable for the set point, and then the (signed) output value is used to drive the motor direction and PWM value.

Can you help me in writing code

You need to post in the Gigs and Collaborations area if you want coding done for you.

see Adding Encoder to Older Walthers Turntable

My SmartCar library (at https://github.com/MajicDesigns/MD_SmartCar or the IDE library manager) has a class to run a motor like you want and a separate PID controller class used to control the motor speed using encoder feedback. These are 'connected' in the main code.

All the code is there but you will need to understand implement any changes for what you want to do. The library is documented (look at the docs folder) and the series of blog posts starting with this one details the whole SmartCar project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.