Heaven’s light is our guide
Rajshahi University of Engineering & Technology
PROJECT REPORT
Course No : EEE 3100
Course Title : Electronic Shop Practice
Project No : 02
Project Name : DC Motor Speed Control with PID Controller
Submitted By:
Roll : 1801049 1801050
1801051 1801052
1801053 1801054
Section :A
Department : Electrical and Electronic Engineering
Date of Submission : 9/8/22
Submitted To:
Md. Mahmudul Hasan
Lecturer,
Department of Electrical and Electronic Engineering, RUET
Project no. 02
2.1 Name of the Project
DC Motor Speed Control with PID Controller
2.2 Objectives
To know the working of PID Controller
To control the speed of the DC Motor with PID Controller
2.3 Theory
2.3.1 DC Motor speed control and PID Controller: A motor convert electrical energy into
mechanical energy. A simple DC motor use electricity and magnetic field for producing torque
which rotate the motor. The DC motor speed control refers to intentional speed variation carried
out manually or automatically.
The Proportional Integral Derivative (PID) controller is the most common form of feedback used
in the control systems. The PID controllers are preferred mostly for their wide range of operating
conditions and functional simplicity. The basic idea behind a PID controller is to read a sensor,
then compute the desired actuator output by calculating proportional, integral, and derivative
responses and summing those three components to compute the output to get optimal response. It
is capable of manipulating the process inputs based on the history and rate of change of the signal
providing a more accurate and stable control method. The general PID controller formula is
𝑑𝑒(𝑡)
𝑢(𝑡) = 𝐾𝑝 𝑒(𝑡) + 𝐾𝑖 ∫ 𝑒(𝑡)𝑑𝑡 + 𝐾𝑑
𝑑𝑡
Here,
u(t)= PID control variable
Kp = Proportional Gain
e(t) = Error value
Ki = Integral Gain
Kd = Differential Gain
de = Change in error value
dt = Change in time
Effects of increasing the PID Parameter Independently:
Control Response Rise Time Settling Time Overshoot Steady State Error
Kp Decrease Small Change Increase Decrease
Kd Small Change Decrease Decrease No Change
Ki Decrease Increase Increase Eliminate
2.3.2 Basic idea of the project and flow chart:
The speed of the DC Motor is controlled with the help of the PID Controller through the Arduino
program. The IR Sensors measure the speed and gives feedback to the motor for speed control.
The motor driver acts as the interface between the DC Motor and the control circuits which is the
Arduino program in this case. It basically drives the motor according to the instruction resulting
from PID controller calculation.
Fig.2.1 Block diagram of DC Motor Speed Control with PID Controller
Fig.2.2 DC Motor Speed Control with PID Controller
2.3.3 Flow Chart:
Fig.2.2 Flowchart of the DC Motor Speed Control with PID Controller
2.4 Required Apparatus:
Power Supply (220V AC - 12V DC)
Arduino Uno
PID Controller
DC Motor
Motor driver (L298M)
IR module
Connecting Wires
2.5 Arduino Code
The arduino code for the DC Motor speed control is given below
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <PID_v1.h>
int sensorvalue;
int state1 = HIGH;
int state2;
float rps;
float rpm;
long prevMillis = 0;
long interval = 200;
long currentTime;
long prevTime = 1;
long diffTime;
int sensorthreshold = 30;
int IN1 = 7; // DC motor pin
int IN2 = 8; // DC motor pin
int ENA = 9; // PWM DC motor pin
double Setpoint, Input, Output;
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
void setup()
{
Serial.begin(9600);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
pinMode (ENA, OUTPUT);
Input = analogRead(rpm);
Setpoint = 100;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
analogWrite(ENA,150);
digitalWrite(IN1, HIGH);
digitalWrite(IN2,LOW);
sensorvalue = analogRead(0); // read from pin 0
if(sensorvalue < sensorthreshold)
state1 = HIGH;
else
state1 = LOW;
if(state2!=state1
if (state2>state1){
currentTime = micros();
diffTime = currentTime - prevTime;
rps = 1000000/diffTime;
rpm = 60000000/diffTime;
unsigned long currentMillis = millis();
if(currentMillis - prevMillis > interval){
prevMillis = currentMillis;
Serial.print(rps); Serial.print(" rps "); Serial.print(rpm); Serial.println(" rpm");
}
prevTime = currentTime;
}
state2 = state1;
}
{
Input = analogRead(rpm);
myPID.Compute();
analogWrite(9, Output);
}
}
2.6 OUTPUT
We got the output from the serial monitor of Arduino IDE:
We got the output from the serial plotter of Arduino IDE:
We got the output when the motor was stopped:
2.7 Analysis of the Output:
The speed of the motor was set at 65 rpm. From the serial plotter of the Arduino IDE, it can
be observed that the motor ran at around 60 rpm.
During the initial stage, the overshoot reached about 82 rpm, but due to the PID controller,
the overshoot was minimized eventually, and the motor ran with a steady state error with
some oscillation.
When the motor was stopped, the power surged in the motor, and a large overshooting the
negative direction was observed, but it quickly became 0. Thus, the motor eventually came to
a stop.
2.8 Discussion
The project was carried out well. Due to the damaged built-in hall sensor of the DC Motor with
magnetic encoder, the speed control was done with the speed added as feedback with the help of
IR sensors through Arduino program. The feedback result had errors in measurement as IR sensors
are not very reliable. This error caused the PID controller to trigger at unwanted values. But the
primary objective of the project was achieved with this setup.