Control a dc motor with PID control

I'm doing a project on how to control a dc motor speed with PID control but my speed wont exceed 10 m/s. Can anyone help me point out whats wrong with my coding

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

The obvious first question…
Without PID, can your motor reach whatever speed it’s supposed to?

10 metres/second isn’t a rotational speed any more than 30 m/s is.

1 Like

I also don’t see why you are changing tuning parameters in the sketch .
Have a look at some PID examples - it looks like you have a miss understanding here on what PID does

1 Like

Two\\\Three issues:

  1. 10*m2s doesn't match any of your intervals -- the first condition is open before 10m2s and the second interval is closed and starts at 11m2s
  1. you cant code "between" like that -- it will convert one of the logical tests to a zero or one and then compare it numerically. Consider that "Serial.print(1<0<3);" prints "1". Instead, use two separate logical tests and join them logically with an "and":
   if( 11*m2s <= TIME and TIME < 20*m2s){
  1. Post code with code tags, not as images.

What is the meaning of m2s?

Try P control first. It should get you reasonably close.
Then add some I to get it on spec.
Some D might stabilize the control.
Correct values will depend on the characteristics of your system (weight, maximum torque of motor, motor revs, gearing, hill up or down)...
Can be quite tricky to get it right.

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