Speed Control of Motor - RKMS Project
Speed Control of Motor - RKMS Project
Department of
ELECTRONICS & TELE-COMMUNICATION ENGINEERING
6TH SEMESTER
Display
Load
keypad
Voltage
Bridge
Transformer Regulator L293D
Rectifier
COMPONENTS REQUIRED
components Specification Quantity Cost
Transformer 6-0-6 V 1
Diode 1N4007 4
Capacitor 3
Voltage Regulator IC7806 1
H-Bridge L293D 1
DC Motor with Rotary Encoder 5v,2400rpm 1
Arduino Nano Atmega328 1
Keypad 4*3 1
Display 20*4,LCD 1
Switches DPDT, push to on
LED
Resistor
Connecting wires
Set up box 1
Total
COMPONENTS DESCRIPTION
1.LIQUID CRYSTAL DISPLAY
.
Model LCD2004
Characters 20
Interface Type I2C
I2C Address 0x27
Character Color White
Backlight Blue
Input Voltage (V) 5
Length (mm) 60
Width (mm) 98
Height (mm) 14
Weight (gm) 76
Shipment Weight 0 .175 kg
Shipment Dimensions1 1 × 7 × 4 cm
12C INTERFACE DISPLAY
Features :
Arduino IIC/I2C interface was developed to
reduce the IO port usage on Arduino board
I2C adapter allows flexibility in connections
I2C Reduces the overall wirings.
20 characters wide, 4 rows
White text on the Blue background
Single LED backlight included can be dimmed
easily with a resistor or PWM.
Operating Voltage 5V
Recommended Input 7-12V
Voltage for Vin pin
Analog Input Pins 6 (A0 – A5)
Digital I/O Pins 14 (Out of which 6
provide PWM output)
DC Current on I/O 40 mA
Pins
DC Current on 3.3V 50 mA
Pin
Flash Memory 32 KB (2 KB is used
for Bootloader)
SRAM 2 KB
EEPROM 1 KB
Frequency (Clock 16 MHz
Speed)
Communication IIC, SPI, USART
ARDUIO NANO
Features
—• High Performance, Low Power AVR® 8-Bit Microcontroller
—• Advanced RISC Architecture – 131 Powerful Instructions – Most Single Clock Cycle Execution – 32 x 8
General Purpose Working Registers – Fully Static Operation – Up to 20 MIPS Throughput at 20 MHz – On-
chip 2-cycle Multiplier
—• High Endurance Non-volatile Memory Segments – 4/8/16/32K Bytes of In-System Self-Programmable Flash
program memory – 256/512/512/1K Bytes EEPROM – 512/1K/1K/2K Bytes Internal SRAM – Write/Erase
Cycles: 10,000 Flash/100,000 EEPROM – Data retention: 20 years at 85°C/100 years at 25°C(1) – Optional
Boot Code Section with Independent Lock Bits In-System Programming by On-chip Boot Program True Read-
While-Write Operation – Programming Lock for Software Security
• Peripheral Features – Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode – One 16-bit
Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode – Real Time Counter with
Separate Oscillator – Six PWM Channels – 8-channel 10-bit ADC in TQFP and QFN/MLF package
Temperature Measurement – 6-channel 10-bit ADC in PDIP Package Temperature Measurement –
Programmable Serial USART – Master/Slave SPI Serial Interface – Byte-oriented 2-wire Serial Interface
(Philips I2 C compatible) – Programmable Watchdog Timer with Separate On-chip Oscillator – On-chip Analog
Comparator – Interrupt and Wake-up on Pin Change
—• Special Microcontroller Features – Power-on Reset and Programmable Brown-out Detection – Internal
Calibrated Oscillator – External and Internal Interrupt Sources – Six Sleep Modes: Idle, ADC Noise Reduction,
Power-save, Power-down, Standby, and Extended Standby
—• I/O and Packages – 23 Programmable I/O Lines – 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-
pad QFN/MLF
—• Operating Voltage: – 1.8 - 5.5V
—• Temperature Range: – -40°C to 85°C
• Speed Grade: – 0 - 4 [email protected] - 5.5V, 0 - 10 [email protected] - 5.5.V, 0 - 20 MHz @ 4.5 - 5.5V
• Power Consumption at 1 MHz, 1.8V, 25°C – Active Mode: 0.2 mA – Power-down Mode: 0.1 µA – Power-
save Mode: 0.75 µA (Including 32 kHz RTC)
MMaximum
ximu
ainimum Lo
LL
moineine
adS SeR ries
Operating
Unit u
sat:
Weight:Te ilat
on: ::perat
om
n u
Height: P
ioon:p9Li
5MIC
nm dB
10n
ear
Operating
00 Rerieul
Regulati
eg
-STMicroelectronics
e:Pow
erature Voltage
9.
er
115
0
4
.4
Mana
Temperatur
.6mRegula
gement tors ICr
9.15 mm 1C25 C 1 m 2.300
0mm
mV20
m78VgL s
4.Voltage regulator
+0 125 C 12 120 m L78
Manufacturer:STMicroelectronics
Product Category:Linear Voltage Regulators
Mounting Style:Through Hole
Package/Case:TO-220
Number of Outputs:1 Output
Polarity:Positive
Output Voltage:6 V
Output Current:1.5 A
Output Type:Fixed
Input Voltage MAX:35 V
Input Voltage MIN:8 V
Minimum Operating Temperature:0 C
Maximum Operating Temperature:+ 125 C
Load Regulation:120 mV
Line Regulation:120 mV
Series:L78
Height:9.15 mm
Length10.4 mm
Width:4.6 mm
Product Type:Linear Voltage Regulators
Unit Weight:2.300 g
5. ROTARY ENCODER
—12mm digital rotary positioning encoder
—Operating Temperature-20°C~+70°
—CShaft Rotation Force20gf.cm~200gf.cm
—Soldering Heat260 ,3~5sec
—Push-pull Strength10 Kgf.cm
—Total Rotation Angle360°
—Insulation resistanceMore than 100MΩ(AT 50V DC)
—Contact resistance1Ω
—MaxSwitch Travel0.5±0.3mm
—Switch Operating Force610±306gf.cm
—Switch Power RatingDC 12V 10mA
6. DC MOTOR
Specifications
—Voltage-5v
—Speed-2400rpm
7. KEYPAD 4*3
Specifications:
Pad Size : 52 x 40 x 0.8mm
Transparent cable length : 50mm
Connector : 7 pins (Pitch 2.54mm)
Mounted: Adherence
PID CONTROLLER
—A proportional–integral–derivative controller (PID
controller or three-term controller) is a control loop
mechanism employing feedback that is widely used
in industrial control systems and a variety of other
applications requiring continuously modulated
control. A PID controller continuously calculates
an error value {\displaystyle e(t)} as the difference
between a desired setpoint (SP) and a measured
process variable (PV) and applies a correction based
on proportional, integral, and derivative terms
(denoted P, I, and D respectively), hence the name.
CIRCUIT DIAGRAM
PROGRAMMING CODE
#define LCDWIDTH 20
#define LCDHEIGHT 4
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <PID_v1.h>
int keypad_sw= 2; //external interrupt int motor_led= 8; //motor running indicator
int PIN_OUTPUT= 11; //pwm output
int sensor= 10; //encoder input
int keypad_led= 3; //keypad active or inactive indicator
int pid_sw= 12; //pid or without pid
int button1= 9; //if low displays torque and speed when high or....
double Setpoint, Input, Output;
double Kp=0.03, Ki=0.3, Kd=0; //tuning parameters PID
myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
LiquidCrystal_I2C lcd(0x27, 20, 4); //display pin(A4~DATA,A5~CLK)
volatile bool y = false;
unsigned long start_time = 0;
unsigned long end_time = 0;
—
int steps= 0;
int steps_old= 0;
int temp= 0;
int rpm= 0;
float trq= 0;
float vol= 0;
float vi= 0;
float current= 0;
int x= 0;
int val=0;
int k=0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'.','0','#'} };
byte rowPins[ROWS] = {7, A0, A1, A2}; //connect to the row of the keypad(R1~r4)
byte colPins[COLS] = {A3, 4, 6}; //connect to the column of the keypad(c1~c3)
//Create an object of keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );
void setup(){
//myPID.SetMode(AUTOMATIC); //turn the PID on
lcd.begin();
lcd.backlight();
pinMode(pid_sw,INPUT_PULLUP);
pinMode(button1,INPUT_PULLUP);
pinMode(PIN_OUTPUT,OUTPUT);
pinMode(motor_led,OUTPUT);
pinMode(keypad_led,OUTPUT);
attachInterrupt(digitalPinToInterrupt(keypad_sw), service, FALLING); lcd.setCursor(0,0);
lcd.print("Speed Controller By");
lcd.setCursor(8,1);
lcd.print("PID");
char * pinnedString = (char *) F("-:Submitted By:-");
char * scrollingString = (char *) F("Nilay Manna, Pintu Karak, Sawrup Sardar, Sourav Swain, Amit Bar"
int pinnedRow = 2;
int scrollingRow = 3;
int scrollingSpeed = 200;
pinAndScro
llText(pinnedString, pinnedRow, scrollingString, scrollingRow, scrollingSpeed); l
cd.clear();
}
void loop(){
if(x==0){
lcd.setCursor(1,0);
lcd.print("-:PID Controller:-");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(3,2);
lcd.print("press ENTER to");
lcd.setCursor(5,3);
lcd.print("set values"); }
if( y == true){
lcd.clear();
val=0;
k=0;
Kp=0;
Ki=0;
Kd=0; }
while( y == true ){
digitalWrite(keypad_led,HIGH);
char key = keypad.getKey();
if( key != NO_KEY ){
digitalWrite(keypad_led,LOW); I
f( key == '#'){
k++;
}
if(k == 0){
if((key>='0')&&(key>=9)){
if(k == 2){
if((key>='0')&&(key>=9)){
Ki = Ki*10;
Ki = Ki + key - '0';
}}
if(k == 3){
if((key>='0')&&(key>=9)){
Kd = Kd*10;
Kd = Kd + key - '0';
}}
}
lcd.setCursor(0,0);
lcd.print("SPEED:");
lcd.print(val);
lcd.print("RPM");
lcd.setCursor(0,1);
lcd.print("Kp:");
lcd.print(Kp);
lcd.setCursor(0,2);
lcd.print("Ki:"); l
cd.print(Ki);
lcd.setCursor(0,3);
lcd.print("Kd:");
lcd.print(Kd);
digitalWrite(keypad_led,LOW);
x=1;
while((digitalRead(pid_sw) == LOW)&&(x == 1)&&(y == false)){
//PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
myPID.SetMode(AUTOMATIC); digitalWrite(motor_led,HIGH);
Setpoint = val;
Measure();
Input = rpm;
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
vol = Output*0.02353; //(6/255)*Output, for getting voltage
current = 0.0009090*vol*1000; //current here(mA)
vi = current*vol; //power here
trq = 0.159*vi*(1/rpm)*100000; //power(vi) to added here
Display();
digitalWrite(motor_led,LOW);
}
while((digitalRead(pid_sw) == HIGH)&&(x == 1)&&(y == false)){
digitalWrite(motor_led,HIGH); analogWrite(PIN_OUTPUT, val*0.0923); //val*(255/2700)
Measure();
vol = val*0.0923*0.02353; //val*(255/2700), for getting voltage
current = 0.0009090*vol*1000; //current here(mA)
vi = current*vol; //power here
trq = 0.16*
vi*(1/rpm)*100000; //power(vi) to added here Display();
digitalWrite(motor_led,LOW);
}
}
void Measure(){
start_time=millis();
end_time=start_time+1000;
while(millis()<end_time)
{
if(digitalRead(sensor))
{
steps=steps+1;
while(digitalRead(sensor));
}
}
temp=steps-steps_old; steps_old=steps;
rpm=(temp/100)*60;
}
void Display(){
if(digitalRead(button1) == HIGH){ lcd.setCursor(0,0);
lcd.print("Desired rpm:");
lcd.print(val);
lcd.setCursor(0,1);
lcd.print("Actual rpm:"); lcd.print(rpm);
lcd.print(" "); lcd.setCursor(0,2);
lcd.print("current:");
lcd.print(current); lcd.print("mA "); lcd.setCursor(0,3); l
cd.print("voltage:");
lcd.print(vol); lcd.print("Volt ");
}
if(digitalRead(button1) == LOW){
lcd.setCursor(0,0); lcd.print("Desired rpm:"); lcd.print(val);
lcd.setCursor(0,1); lcd.print("Actual rpm:"); lcd.print(rpm); lcd.print(" ");
lcd.setCursor(0,2);
lcd.print("power:"); lcd.print(vi); lcd.print("mWatt ");
lcd.setCursor(0,3); lcd.print("torque:"); lcd.print(trq); lcd.print("N-m ");
}
} void service() {
y = !y;
void pinAndScrollText(char * pinnedText, int pinnedRow, char *
scrollingText, int scrollingRow, int v) {
if (pinnedRow == scrollingRow || pinnedRow < 0 || scrollingRow < 0 ||
pinnedRow >= LCDHEIGHT || scrollingRow >= LCDHEIGHT ||
strlen(pinnedText) > LCDWIDTH || v < 0) {
lcd.clear();
lcd.print(F("Error"));
while (1);
}
int l = strlen(pinnedText);
int ls = strlen(scrollingText);
int x = LCDWIDTH; int n = ls + x; int i = 0; int j = 0;
char c[ls + 1];
flashCharSubstring(pinnedText, c, 0, l);
lcd.setCursor(l % 2 == 0 ? LCDWIDTH / 2 - (l / 2) : LCDWIDTH / 2 - (l / 2)
- 1, pinnedRow);
lcd.print(c)
; while (n > 0) {
if (x > 0) {
x--;
lcd.setCursor(x, scrollingRow);
if (n > LCDWIDTH) {
j++;
i = (j > LCDWIDTH) ? i + 1 : 0; flashCharSubstring(scrollingText, c, i, j); lcd.print(c);
} else {
i = i > 0 ? i + 1 : 0;
if (n == ls) {
i++;
}
flashCharSubstring(scrollingText, c, i, j);
lcd.print(c);
lcd.setCursor(n - 1, scrollingRow);
lcd.print(' ');
} n--;
if (n > 0) {
delay(v);
}
}
}
void flashCharSubstring(const char *str, char *buf, int inf, int sup) {
int l = sup - inf;
for (int i = 0; i < l; i++) {
buf[i] = pgm_read_byte_near(&str[i + inf]); } buf[l] = '\0';
}
WORKING PRINCIPLE
—At fisrt,the power source is given via a step down
transformer where the 220 AC voltage is converted into low
voltage DC,follwed by a flter and rectifier circuit which
include diodes and capacitor which are giving us required
DC voltage.
—The Arduino microcontroller board is used for PID
controlling purpose.After powering the system ,we enter
the desire speed and indvidual PID gain in values through
the key-board,which then goes to the controlling unit and
parallely we observe a input values on the display.
—Then the controller sends the signal to L293D motor driver
IC which then fuels the motor.
—Now the PID controller requires a feedback circuit to
maintain the desired value for that we have used a rotary
encoder which counts the speed of the motor by uisng a
pair of IR transmitter and receiver.
—After that the information get back to the controller where it
sences the difference between desired soeed and actual
speed and sends a ADJUSTING signal.
—The close loop process is continued untill the motor
speed is adjusted with the desire speed.The whole
process can be observed on the display.
—We can see the motor speed is gradually adjusted with
our desire speed.
APPLICATION
Lathe Machine
Centrifugal Pump