63
PID CONTROLLER USING ARDUINOA Project report submitted in partial fulfillment of the requirements for the Award of the Degree of BACHELOR OF TECHNOLOGY IN ELECTRICAL AND ELECTRONICS ENGINEERING BY S.V.D.REYVANTH 09241A0233 G.SHIRISH 09241A0241 D.SIVA VARMA 09241A0243 M.RAMU 10245A0210 Department of Electrical and Electronics Engineering GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING & TECHNOLOGY BACHUPALLY, HYDERABAD-72 2009-2013

CD-24-Main Doc Pid Using Arduino

Embed Size (px)

DESCRIPTION

aaaa

Citation preview

Page 1: CD-24-Main Doc Pid Using Arduino

“PID CONTROLLER USING ARDUINO”

A Project report submitted in partial fulfillment of the requirements

for the Award of the Degree of

BACHELOR OF TECHNOLOGY

IN

ELECTRICAL AND ELECTRONICS ENGINEERING

BY

S.V.D.REYVANTH 09241A0233

G.SHIRISH 09241A0241

D.SIVA VARMA 09241A0243

M.RAMU 10245A0210

Department of Electrical and Electronics Engineering

GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING

& TECHNOLOGY

BACHUPALLY, HYDERABAD-72

2009-2013

Page 2: CD-24-Main Doc Pid Using Arduino

GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING

& TECHNOLOGY

BACHUPALLY, HYDERABAD-72

2009-2013

Department of Electrical and Electronics Engineering

CERTIFICATE

This is to certify that the mini project report entitled “PID CONTROLLER USING

ARDUINO” that is being submitted by S.V.D.REYVANTH,G.SHIRISH,D.SIVA

VARMA,M.RAMU in partial fulfillment for the award of the Degree of Bachelor of

Technology in Electrical and Electronics Engineering to the Jawaharlal Nehru Technological

University is a record of bonafide work carried out by them under my guidance and supervision.

The results embodied in this project report have not been submitted to any other University or

Institute for the award of any Graduation degree.

Prof. P.M.SHARMA Mrs. D. RAMYA

HOD, EEE Project Guide

GRIET, Hyderabad GRIET, Hyderabad

Page 3: CD-24-Main Doc Pid Using Arduino

ACKNOWLEDGEMENT

This is to place on record our appreciation and deep gratitude to the faculty members without

whose support this project would have not ever seen the light of day.

We wish to express our profound sense of gratitude to Prof. P. S. RAJU, DIRECTOR,

G.R.I.E.T for his guidance, encouragement, and for all facilities to complete this project.

We also express our sincere thanks to Prof. P.M.SHARMA, Head of the Department,

G.R.I.E.T.

We have immense pleasure in expressing our gratitude to our guide Mrs. D. RAMYA, Assistant

Professor, Department of Electrical and Electronics Engineering, G.R.I.E.T for her

guidance throughout this project.

We also wish our profound thanks to Mr. VASANTH KUMAR, Assistant professor,

G.R.I.E.T without whose support, completion of this project would have not been possible.

S.V.D.REYVANTH (09241A0233)

G.SHIRISH(09241A0241)

D.SIVA VARMA(09241A0243)

M.RAMU(10245A0210)

Page 4: CD-24-Main Doc Pid Using Arduino

ABSTRACT

The objective of our project is to control the speed of a motor using PID controller. The PID

controller is generated by an arduino program and used in the speed control of motor.

Arduino is an open-source electronic prototyping platform based on flexible easy to use

hardware and software. It is intended for artists, designers, hobbyists and anyone interested in

creating interactive objects or environments.

Ardino can sense the environment by receiving input from a variety of sensors and can affect its

surroundings by controlling lights, motors, and other actuators. The microcontroller on the board

is programmed using the arduino programming language (based on wiring) and the arduino

development (based on processing). Arduino projects can be stand alone or they can

communicate with software running on the computer. The arduino language program is dumped

into the microcontroller and it is given to the analog input of microcontroller and the analog

outputs are connected to thyristor controller. The speed of the motor will be controlled based on

the firing angle obtained from the thyristor controller and the speed sensed through proximity

sensor would be compared with the reference value and obtained error is projected over PID

controller and the process continues till we get minimum error.

The effectiveness of controlling the speed of motor by using the software is, we are open to

change the Kp, Kd and Ki constants. Based upon the error occurred and by changing the values

suitably the required output from the system can be obtained

Prof. P.M.Sharma Mrs. D. Ramya

HOD, EEE Asst. Prof.

GRIET, Hyderabad. GRIET, Hyderabad.

Page 5: CD-24-Main Doc Pid Using Arduino

Abbreviations:

DC: Direct Current

AC: Alternate Current

PID: Proportionate Integrate Derivative

M/G: Motor/Generator

PI: Proportional Plus Integral

Page 6: CD-24-Main Doc Pid Using Arduino

CONTENTS

1. Introduction 1

1.1 Introduction to project 1

1.1.1 Objective 1

1.1.1.1 Project objective 1

1.2 Control system 2

1.2.1 The control system 2

1.2.2 Open loop control 2

1.2.2.1 Open loop characteristics 2

1.2.3 Closed loop control system 3

1.2.3.1 Closed loop characteristics 3

1.2.4 Difference between open loop & closed loop operation of DC motor 3

1.3 DC Motor 4

1.3.1 Introduction 4

1.3.2 Factors controlling motor speed 4

1.3.2.1 Applied voltage control 5

1.3.2.2 Rheostat control 5

1.3.2.3 Field control 5

1.3.3 Characteristics 5

1.3.4 Application of DC motors 6

1.3.4.1 Shunt motor 6

1.3.4.2 Series motor 6

1.3.4.3 Compound motor 6

2. Proximity sensor 7

2.1 Introduction 7

2.2 Description & operation 7

2.3 Various types of sensors 9

3. PID Controller 10

3.1 Introduction 10

3.2 The three elements of PID 11

Page 7: CD-24-Main Doc Pid Using Arduino

3.2.1 Proportion controller(Kp) 12

3.2.2 Integral controller(Ki) 13

3.2.3 Derivative controller(Kd) 14

3.3 Closed loop system with proportionate, integral and derivative control 15

3.4 Implementation of PID control 16

3.4.1 Choosing the structure of a PID controller 16

3.4.2 Tuning the PID controller 17

3.5 PID controller for DC motor 21

4. Arduino 26

4.1 Introduction 26

4.2 Hardware 27

4.3 Software 28

4.4 Applications 30

4.5 Types of Arduino 31

4.6 Types of Arduino 32

4.7 Open hardware and open source 33

5. Speed control of DC motor by PID using Arduino 34

5.1 Closed loop PID speed control 34

5.2 Hardware components 34

5.2.1 Motor-Generator set 35

5.2.2 Thyristor control drive 35

5.2.3 Proximity sensor 36

5.2.3.1 Methods of determining RPM 36

5.2.3.2 Low PPR solutions using the period measurement method 37

5.3 Program for PID controller 38

5.4 conclusion 45

Appendix – A 46

Page 8: CD-24-Main Doc Pid Using Arduino

List of figures:

Fig 1.1: General Block Diagram of open-loop system 2

Fig 1.2: General Block Diagram of closed-loop system 3

Fig 1.3: Dc motor working principle 4

Fig 2.1: Proximity sensor sensing metal target 7

Fig 2.2: Proximity sensor functioning 8

Fig 2.3: Circuit of proximity sensor 8

Fig 2.4: Types of proximity sensors 9

Fig 3.1: PID control diagram 11

Fig 3.2: Proportional Control Response 13

Fig 3.3: System variation with change in integral control 14

Fig 3.4: Proportional-Derivative Control Response 15

Fig 3.5: Closed loop system with proportional, integral, and derivative control 16

Fig 3.6: Time period graph 20

Fig 3.7: Closed Loop Control of DC Motor 21

Fig 3.8: Step response given with only proportional controller 22

Fig 3.9: Step response with integrate and derivative controller 23

Fig 3.10: Step response for different gain values 24

Fig 3.11: Controlled step response 25

Page 9: CD-24-Main Doc Pid Using Arduino

Fig 4.1: Arduino hardware 27

Fig 5.1: Functional block diagram of closed loop speed control system of DC motor

34

Fig 5.2: Hardware Equipment 35

Fig 5.3: Basic block diagram 36

Fig 5.4.1: Arduino program - i 42

Fig 5.4.2: Arduino program - ii 43

Fig 5.4.3: Arduino program – iii 44

Page 10: CD-24-Main Doc Pid Using Arduino

List of tables:

Table 3.1 Choosing structure of a PID controller 17

Table 3.2 Methods of Tuning 18

Table 3.3 Gain values of different controllers 20

Page 11: CD-24-Main Doc Pid Using Arduino

CHAPTER-1

INTRODUCTION

1.1 Introduction to project:

DC Motor plays a crucial role in research and laboratory experiments because of their

simplicity and low cost. The speed of the motor can be controlled by three methods

namely terminal voltage control, armature rheostat control method and flux control

method. Here in this project terminal voltage control method is employed.

A control system is an interconnection of components forming a system configuration

that will provide a desired system response. A controlled DC-motor was developed

allowing Arduino a hardware acts as the interface between the computer and the outside

world. It primarily functions as a device that digitizes incoming analog signals so that the

computer can interpret them. The user interface was developed in a Arduino

environment.

In this project, the aim is to explore the capability of the Arduino by developing PID -

an application of DC motor speed control.

1.1.1 Objectives:

1.1.1.1 Project objective:

The objective of this project to setup a DC motor controlled with Arduino kit.

Modeling of the DC motor system and simulate with Arduino.

The project will include:

1. Developing the PID controller using Arduino and interfacing the arduino

hardware by dumping the program.

2. Knowledge of Arduino kit. Familiar with this program and test with DC motor.

Page 12: CD-24-Main Doc Pid Using Arduino

1.2 CONTROL SYSTEM

1.2.1 The Control System:

The control system is that means by which any quantity of interest in a machine,

mechanism or other equipment is maintained or altered in accordance with a desired

manner.

1.2.2 Open loop control:

Any physical system which does not automatically correct for variation in its output is

called an open-loop system. In these systems the output remains constant for a constant input

signal provided the external conditions remain unaltered. The output may be changed to any

desired value by approximately changing the input signal but variations in external

conditions may cause the output to vary from the desired value in an uncontrollable fashion.

Fig 1.1: General Block Diagram of open-loop system

1.2.2.1 Open-loop characteristics:

Shows an open-loop action (controlled chain);

Can only counteract against disturbances, for which it has been designed; other

disturbances cannot be removed;

Cannot become unstable - as long as the controlled object is stable.

Page 13: CD-24-Main Doc Pid Using Arduino

1.2.3 Closed loop control:

A closed-loop control system is one in which an input forcing function is determined in

part by the system response. The measured response of a physical system is compared with a

desired response. The difference between these two responses initiates actions that will result in

the actual response of the system to approach the desired response. This in turn drives the

difference signal towards zero. Typically the difference signal is processed by another physical

system, which is called a compensator, a controller, or a filter for real-time control system

applications.

Fig 1.2 General Block Diagram of closed-loop system

1.2.3.1 Closed-loop characteristics:

Shows a closed-loop action (closed control loop);

Can counteract against disturbances (negative feedback);

Can become unstable, i.e. the controlled variable does not fade away, but grows

(theoretically) to an infinite value.

1.2.4 Difference between open loop and closed loop operation of DC Motor:

In open loop control of DC Motor the output (speed of the motor) cannot be maintained at a

desired value due to external disturbances and system variables, whereas in closed loop

operation the output can maintained due to the presence of feedback circuit. Feedback circuit

Page 14: CD-24-Main Doc Pid Using Arduino

samples the output and gives signals to the error detector which compares the feedback signal

with the specified value and produces a modified signal according to the output.

1.3 DC MOTOR:

1.3.1 Introduction:

An Electric motor is a machine which converts electric energy into mechanical energy.

Its action is based on the principle of that when a current carrying conductor is placed in a

magnetic field experiences a mechanical force whose direction is given by Fleming’s Left-Hand

Rule.

Fig 1.3 dc motor working principle.

1.3.2 Factors Controlling Motor Speed:

The speed of the motor is given by the relation

𝑁 =𝑉 − 𝐼𝑎Ra

𝑍𝜙. 𝐴

𝑃 = 𝐾

𝑉 − 𝐼𝑎𝑅𝑎

𝑍𝜙𝑟. 𝑝. 𝑠

Where, Ra = armature resistance

Page 15: CD-24-Main Doc Pid Using Arduino

1.3.2.1 Applied voltage control:

This type of speed control can be used in separately excited dc motors, where the field

supply is connected permanently to a fixed exciting voltage. The armature speed will be

approximately proportional to these different voltages.

This method is one of the simplest methods of speed control. The armature voltage is

varied using knob through PC which is explained in later chapter.

1.3.2.2 Rheostat control:

This type of speed control can be used in series, shunt and compound motors. As the supply

voltage is kept constant, the voltage across the armature is varied by inserting a variable rheostat

in series with the armature circuit.

1.3.2.3 Field control:

This type of speed control can be used in shunt and compound motors. In this method, speed

is controlled by varying the field current. Flux is directly proportional to field current. By

decreasing the flux, the speed can be increased and vice-verse.

1.3.3 Characteristics:

Nearly constant speed

Torque varies nearly as the current

Medium starting torque (twice full load torque with twice full load current at

start)

Continuous speed range 4:1 maximum

Medium maintenance cost

Page 16: CD-24-Main Doc Pid Using Arduino

1.3.4 Applications of D. C. Motors:

1.3.4.1 Shunt Motors: There are three kinds of characteristics for a motor viz. Speed-

Torque, Speed-Current and Torque-Current characteristics. After analyzing all three

characteristics for DC Shunt Motor it is observed that it is an approximately constant speed

motor. It is therefore, used where

The speed is required to remain almost constant from no-load condition to full load-

condition.

The load has to be driven at a number of prefer and any one of which is required to

remain nearly constant.

Industrial Use:Lathes, Drills, Boring Mills, Shapers, Spinning and Weaving Machines etc.

1.3.4.2 Series Motors: D C Series Motor is a variable speed motor. It means speed it low at

high torque and vice-versa. However, at light or no-load, the motor tends to attain dangerously

high speed. The motor has a high starting torque. It is therefore, used where

Large starting torque is required like in Elevators and Electric Traction.

The load is subjected to heavy fluctuations and the speed is automatically required on

sewing machines etc.

Industrial Use : - Electric traction, brands, elevators, air compressors, vacuum cleaners,

hair drier, sewing machines etc.

1.3.4.3 Compound Motors: D. C. Compound Motor is of two types. It is therefore, used

where, specification required for particular motor

Differential-compound motors are rarely used because of their poor torque characteristics

Cumulative-compound motors are used where a fairly constant speed is required with

irregular loads or suddenly applied heavy load.

Page 17: CD-24-Main Doc Pid Using Arduino

CHAPTER 2

PROXIMITY SENSOR

2.1 Introduction:

Proximity sensors provide medium- or low-resolution sensing, depending on the number

of pulses measured per revolution. The best method of using a proximity sensor is to sense the

teeth on a gear. This type of sensing typically has options for 60, 120, or 240 PPR, and the pulses

are relatively clearly defined and symmetrical. If a gear is not available, a proximity sensor can

be used to sense the head of a bolt attached to the shaft. The drawback of this method is the low

PPR (low resolution). If more than one bolt head is used, resolution improves, but pulses are

often inconsistent and not symmetrical.

2.2 Description and operation:

Inductive Proximity Sensors detect the presence of metal objects which come within

range of their oscillating field and provide target detection to “zero speed”. Internally, an

oscillator creates a high frequency electromagnetic field (RF) which is radiated from the coil and

out from the sensor faces (See Figure4.1). When a metal object enters this field, eddy currents

are induced into the object. As the metal moves closer to the sensor, these eddy currents increase

and result in absorption of energy from the coil which dampens the oscillator amplitude until it

finally stops.

Fig 2.1 proximity sensor sensing metal target

Page 18: CD-24-Main Doc Pid Using Arduino

Fig 2.2 proximity sensor functioning

The 3-wire Models PSA-6B, 7B, and 8B each contain a Detector Circuit and NPN

Transistor Output. In these units, the Detector Circuit senses when the oscillator stops, and turns

on the Output transistor which controls the load. The Detector Circuit also turns on an integrally

case mounted L.E.D., visually indicating when a metal object is sensed.

Fig 2.3 Circuit of proximity sensor

Page 19: CD-24-Main Doc Pid Using Arduino

2.3 Various types of proximity sensors:

Fig 2.4 types of proximity sensors

Proximity sensors provide medium- or low-resolution sensing, depending on the number

of pulses measured per revolution. The best method of using a proximity sensor is to sense the

teeth on a gear. This type of sensing typically has options for 60, 120, or 240 PPR (pulse per

revolution), and the pulses are relatively clearly defined and symmetrical. If a gear is not

available, a proximity sensor can be used to sense the head of a bolt attached to the shaft. The

drawback of this method is the low PPR (low resolution). If more than one bolt head is used,

resolution improves, but pulses are often inconsistent and not symmetrical.

Page 20: CD-24-Main Doc Pid Using Arduino

CHAPTER 3

PID CONTROLLER

3.1 Introduction:

A proportional–integral–derivative controller (PID controller) is a generic control loop

feedback mechanism (controller) widely used in industrial control systems– a PID is the

most commonly used feedback controller. A PID controller calculates an "error" value as

the difference between a measured process variable and a desired set point. The controller

attempts to minimize the error by adjusting the process control inputs. In the absence of

knowledge of the underlying process, a PID controller is the best controller. However, for

best performance, the PID parameters used in the calculation must be tuned according to

the nature of the system – while the design is generic, the parameters depend on the

specific system.

For this project, the PID control method will be used. PID, meaning Proportional-

Integral-Derivative, is one of the most used feedback control method. A PID controller

consists of a Proportional element, an Integral element and a Derivative element, all three

connected in parallel. All of them take the error as input. Kp, Ki, Kd are the gains of P, I

and D elements respectively, as seen in Figure 2.3. Where u(t) is the control signal sent

to the system, y(t) is the measured output and r(t) is the desired output, and tracking error

e(t) = r(t) − y(t), thus a PID controller can be expressed as in Figure 2.3.

Page 21: CD-24-Main Doc Pid Using Arduino

Figure 3.1 PID control diagram

In this project we will use closed loop system with PID system to control the DC motor.

The PID controller calculation involves three separate parameters, and is accordingly

sometimes called three-term control: the proportional, the integral and derivative values,

denoted as P,I, and D. The proportional value determines the reaction to the current error,

the integral value determines the reaction based on the sum of recent errors, and the

derivative value determines the reaction based on the rate at which the error has been

changing. The weighted sum of these three actions is used to adjust the process via a

control element such as the position of a control valve or the power supply of a heating

element. Heuristically, these values can be interpreted in terms of time: P depends on the

present error, I on the accumulation of past errors, and D is a prediction of future errors,

based on current rate of change.

3.2 The Three Elements of PID:

In simple terms, the each serves a purpose in the control mechanism.

3.2.1 Proportional Controller (KP):

Page 22: CD-24-Main Doc Pid Using Arduino

As the name suggests, a proportional controller applies power to the heater in proportion

to the difference in temperature between the output and the reference. Thus, the P term is

referred to as the proportional gain of the controller. On its own, the characteristic of the

resulting output temperature will be such that it will typically stabilize just below the

desired reference temperature. This is so because; as its gain is increased, the system

responds by applying more power to the output, and as a result the temperature rises

quickly and approaches closer to the set-point. But as this happens, the system will react

by lowering the gain since the gap to the reference is now getting smaller. This causes

the response to become progressively under-damped as the output temperature gets closer

to the set-point. This difference between the stabilized output and the reference is called

the Steady State Error. However, if the P gain is set too high, there will be excessive

initial overshoot, after which the output will oscillate near the reference level, and

eventually becomes unstable. On the other hand, a gain set too low will never enable the

output to even reach near the reference level. The responses can be seen in Figure 8.6

below. While the proportional gain method will perform better than the unavoidable

oscillation in a simple on-off control system, on its own, it will never stabilize on the set-

point. The reason is, acting alone, if temperature equals set-point, then there is no error,

subsequently, the gain will be zero, and thus the output will also be zero.

Page 23: CD-24-Main Doc Pid Using Arduino

Fig 3.2 Proportional Control Response

3.2.2 Integral Controller (KI)

To resolve the issue of the steady state error with Kp alone, the integral term, Ki, has to

be used. The characteristic of the integral control is that it performs an integration of the

past error values and applies a gain to minimize this error. The effect of this action is that

it changes the heater power continuously based on past performance until the time-

averaged value of the temperature error is zero. The downside to this is that the initial

overshoot may be increased since during the initial moments of heating, the difference

between actual temperature and set-point is usually greater. And since the integral

Page 24: CD-24-Main Doc Pid Using Arduino

term is responding to accumulated errors from the past, it can cause the present value to

overshoot the set-point value. As such, settling time may also take longer due to this

temperature oscillation, and as past averaged error values will take time to decrease as the

error gets smaller over a period of time. However, together with Kp, a PI controlled

system is able to achieve the temperature requested by the set-point by eliminating the

steady state error, and also have a shorter rise time.

Fig 3.3 system variation with change in integral control

3.2.3 Derivative Controller (Kd) – The derivative term comes into play when the

overshoot and oscillation need to be addressed. The rate of change of the error is

calculated by determining the slope of the error over time and multiplying this rate of

change by the derivative gain Kd. The magnitude derivative term introduces damping to

Page 25: CD-24-Main Doc Pid Using Arduino

the overall system output by slowing down the rate of change of the controller output

such that the overshoot and oscillation can be reduced. But one side effect is that is that

the damping may also increase the rise time slightly. Together with P and I control

terms, the derivative term can help to improve the process stability of the system. But

according to some studies, differentiation of a signal amplifies noise and can cause a

system to become unstable, so if the system is susceptible to a lot of noise or is sensitive

to noise, then it may be necessary to leave out the derivative control. Figure 8.7

illustrates the effects of a PD controlled response.

Fig 3.4 Proportional-Derivative Control Response

3.3 CLOSED LOOP SYSTEM WITH PROPORTIONATE, INTEGRAL

AND DERIVATIVE CONTROL:

To summarize all three controls, proportional control causes an input signal to change as

a direct ratio of the error signal variation. It responds immediately to the current tracking

error but it cannot achieve the desired set-point accuracy without an unacceptably large gain.

Thus, proportional term usually needs the other terms. Integral control causes an output

signal to change as a function of the integral of the error signal over time duration. Integral

term yields zero steady-state error in tracking a constant set-point. It also rejects constant

disturbances. Derivative action reduces transient errors and causes an output signal to change

as a function of the rate of change of the error signal. The contributions of the three terms

will yield the control output, or the control variable:

Page 26: CD-24-Main Doc Pid Using Arduino

Control Variable = Pout + Iout + Dout

Fig 3.5 Closed loop system with proportional, integral, and derivative control.

In practice, most PID controllers can be run in two modes: manual or automatic. In manual

mode, the controller output is manipulated directly by the operator, typically by pushing

buttons that increase or decrease the controller output. A controller may also operate in

combination with other controllers, such as in a cascade or ratio connection, or with nonlinear

elements, such as multipliers and selectors. In automatic mode, the PID parameters can be

adjusted during operation. When there are changes of modes and parameters, it is important

to avoid switching transients.

3.4 IMPLEMENTATION OF PID CONTROL:

As suggested earlier, to implement a PID control, engineer must first choose the structure of

the PID controller. Secondly, engineer must choose numerical values for the PID coefficients

to tune the controller.

3.4.1 CHOOSING THE STRUCTURE OF A PID CONTROLLER:

For choosing the structure of a controller, refer to the following table for tuning effects of the

PID controller terms. This table is a look-up table in which each term of the controller can be

selected to accomplish a particular closed-loop system effect of specification.

Page 27: CD-24-Main Doc Pid Using Arduino

Table 3.1 Choosing structure of a PID controller

3.4.2 TUNING THE PID CONTROLLER:

The second part of setting up a PID controller is to tune or choose numerical values for the

PID parameters. PID controllers are tuned in terms of their P, I, and D terms. Tuning the

control gains can result in the following improvement of responses:

Proportional gain (Kp):

Larger proportional gain typically means faster response, since the larger the error,

the larger the proportional term compensation. However, an excessively large

proportional gain may result in process instability and oscillation.

Integral gain (Ki):

Larger integral gain implies steady-state errors are eliminated faster. However, the

trade off may be a larger overshoot, since any negative error integrated during

transient response must be integrated away by positive error before steady state can be

reached.

Page 28: CD-24-Main Doc Pid Using Arduino

Derivative gain (Kd):

Larger derivative gain decreases overshoot but slow down transient response and may

lead to instability due to signal noise amplification in the differentiation of the error.

The following table lists some common tuning methods and their advantages and

disadvantages. The choice of method will mostly depend on whether or not the loop can be

taken offline for tuning, and the response time of the system. If the system can be taken

offline, the best tuning method often involve s subjecting the system to a step change in input,

measuring the output as a function of time, and using this response to determine the control

parameters. Manual tuning methods can be quite inefficient, especially if the loops have

response times on the order of minutes or longer.

Table 3.2 Methods of Tuning

Many manufacturing and industrial process companies have in-house guidelines for tuning of

PID controllers in particular process plant units. Therefore, it is often possible to provide

rules and empirical formulas for the PI D controller tuning procedure. Some of these

guidelines base their procedures on the routines of the commonly used Ziegler-Nichols

methods. The two Ziegler-Nichols methods use an online process experiment followed by the

set of rules to calculate the numerical values of the PID parameters. Numerous improvements

Page 29: CD-24-Main Doc Pid Using Arduino

and extensions of the associated rules have been achieved since their introduction. Ziegler-

Nichols is a type of continuous cycling method for controller tuning. The term continuous

cycling refers to a continuous oscillation with constant amplitude and is based on trial-and-

error procedure. The following are the steps to implement the method:

1. Allow the process to reach steady state as much as possible, then turn off the integral

mode (or set time to zero) and turn off the derivative mode.

2. Assign a small value to proportional-only controller gain K (e.g. 0.5) and place the

controller in automatic mode.

3. Make a small set-point change so that the control variable moves away from the set-

point.

4. Increase the gain slightly.

5. Repeat steps 3 and 4 until continuous oscillation is achieved which is known as the

ultimate gain.

6. Calculate the PID controller settings using the Ziegler-Nichols tuning relations in the

table below.

7. Evaluate the Ziegler-Nichols controller settings by introducing a small set-point

change and observing the closed-loop response. Fine tune the settings, if necessary.

Page 30: CD-24-Main Doc Pid Using Arduino

Table 3.3 Gain values of different controllers

Figure 3.6 Time period graph

Note: K is the ultimate gain. T is the time or period in minutes measured in the gain

calibration above.

By tuning the three parameters in the PID controller algorithm, the controller can provide

control action designed for specific process requirements. The response of the controller can

be described in terms of the responsiveness of the controller to an error , the degree to which

the controller overshoots the set-point and the degree of system oscillation. Note that the use

of the PID algorithm for control does not guarantee optimal control of the system or system

stability. Some applications may require using only one or two modes to provide the

appropriate system control. A PID controller will be called a P, I, PI, or PD controller in the

absence of the respective control actions. If the PID controller parameters are improperly

chosen, the controlled process input can become unstable. Instability is often caused by

excess gain, particularly in the presence of significant time delay. In most applications,

Page 31: CD-24-Main Doc Pid Using Arduino

stability of response is required and the process must not oscillate for any combination of

process conditions.

3.5 PID CONTROLLER FOR DC MOTOR:

In this the desired target speed of the motor is set by the user. This value is then fed into the

speed controller to change the motor speed. The loop is closed by a tachometer. The

controller constantly adjusts the value of the DC voltage applied to the motor to maintain the

desired speed. The control loop is shown in the following figure:

Figure 3.7 Closed Loop Control of DC Motor

The transfer function for DC motor's speed is expressed as:

Where:

Page 32: CD-24-Main Doc Pid Using Arduino

K: Electromotive force control = 0.01 Nm/Amp

R: Electrical resistance = 1 O

L: Electrical inductance = 0.5H

J : Moment of inertia of rotor = 0.01 kgm^2/s^2

b: Damping ratio of mechanical system = 0.1 Nms

V: Source voltage

tita: Rotating speed

Therefore, the rotating speed of the motor is directly proportional to the input voltage. First,

let’s try a proportional- only control with a gain (Kp) of 100 and step input of 1 rad/sec. A

step response is received as follows:

Figure 3.8 Step response given with only proportional controller

From the figure above, we see that both the steady-state error and overshoot are too large.

Since adding an integral term will eliminate the steady state error and a derivative term will

Page 33: CD-24-Main Doc Pid Using Arduino

reduce the overshoot, next we try a PID controller with small Ki = 1 and Kd = 1. After that,

the step response curve looks like this:

Figure 3.9 Step response with integrate and derivative controller

However, now the settling time is too long. So we increase Ki to 200 in order to reduce the

settling time. After that, the step response curve looks like:

Page 34: CD-24-Main Doc Pid Using Arduino

Fig 3.10 Step response for different gain values

Now we see that the response is much faster than before; however, the large Ki has worsened

the transient response (big overshoot). So we increase Kd to 10 in order to reduce the

overshoot. After that, the step response curve looks like:

Page 35: CD-24-Main Doc Pid Using Arduino

Fig 3.11 Controlled step response

As a result, we can now use a PID controller with the following parameters to adjust the

value of the DC voltage applied to the motor to maintain the desired speed.

Kp = 100

Ki = 200

Kd = 10

The response from the PID controller is controlled in this way.

Page 36: CD-24-Main Doc Pid Using Arduino

CHAPTER 4

ARDUINO

4.1 Introduction:

An Arduino board with a RS-232 serial interface (upper left) and an Atmel ATmega8

microcontroller chip (black, lower right). The 14 digital I/O pins are located at the top and the 6

analog input pins at the lower right.

Arduino is an open-source single-board microcontroller, descendant of the open-source Wiring

platform, designed to make the process of using electronics in multidisciplinary projects more

accessible. The hardware consists of a simple open hardware design for the Arduino board with

an Atmel AVR processor and on-board input/output support. The software consists of a standard

programming language compiler and the boot loader that runs on the board.

Arduino hardware is programmed using a Wiring-based language (syntax and libraries), similar

to C++ with some slight simplifications and modifications, and a Processing-based integrated

development environment.

The Arduino project received an honorary mention in the Digital Communities category at the

2006 Prix Ars Electronics.

Page 37: CD-24-Main Doc Pid Using Arduino

4.2 HARDWARE:

Fig 4.1 Arduino hardware.

An Arduino board consists of an 8-bit Atmel AVR microcontroller with complementary

components to facilitate programming and incorporation into other circuits. An important aspect

of the Arduino is the standard way that connectors are exposed, allowing the CPU board to be

connected to a variety of interchangeable add-on modules known as shields. Some shields

communicate with the Arduino board directly over various pins, but many shields are

individually addressable via an I²C serial bus, allowing many shields to be stacked and used in

parallel. Official Arduinos have used the megaAVR series of chips, specifically the ATmega8,

ATmega168, ATmega328, ATmega1280, and ATmega2560. A handful of other processors have

been used by Arduino compatibles. Most boards include a 5 volt linear regulator and a 16 MHz

crystal oscillator (or ceramic resonator in some variants), although some designs such as the

LilyPad run at 8 MHz and dispense with the onboard voltage regulator due to specific form-

factor restrictions. An Arduino's microcontroller is also pre-programmed with a boot loader that

simplifies uploading of programs to the on-chip flash memory, compared with other devices that

typically need an external programmer.

At a conceptual level, when using the Arduino software stack, all boards are programmed over

an RS-232 serial connection, but the way this is implemented varies by hardware version. Serial

Arduino boards contain a simple inverter circuit to convert between RS-232-level and TTL-level

signals. Current Arduino boards are programmed via USB, implemented using USB-to-serial

Page 38: CD-24-Main Doc Pid Using Arduino

adapter chips such as the FTDI FT232. Some variants, such as the Arduino Mini and the

unofficial Boarduino, use a detachable USB-to-serial adapter board or cable, Bluetooth or other

methods. (When used with traditional microcontroller tools instead of the Arduino IDE, standard

AVR ISP programming is used.)

The Arduino board exposes most of the microcontroller's I/O pins for use by other circuits. The

Diecimila, Duemilanove, and current Uno provide 14 digital I/O pins, six of which can produce

pulse-width modulated signals, and six analog inputs. These pins are on the top of the board, via

female 0.1 inch headers. Several plug-in application shields are also commercially available.

The Arduino Nano, and Arduino-compatible Bare Bones Board and Boarduino boards may

provide male header pins on the underside of the board to be plugged into solderless

breadboards.

4.3 SOFTWARE:

The Arduino IDE is a cross-platform application written in Java, and is derived from the IDE for

the Processing programming language and the Wiring project. It is designed to introduce

programming to artists and other newcomers unfamiliar with software development. It includes a

code editor with features such as syntax highlighting, brace matching, and automatic indentation,

and is also capable of compiling and uploading programs to the board with a single click. There

is typically no need to edit makefiles or run programs on a command-line interface. Although

building on command-line is possible if required with some third-party tools such as Ino.

The Arduino IDE comes with a C/C++ library called "Wiring" (from the project of the same

name), which makes many common input/output operations much easier. Arduino programs are

written in C/C++, although users only need define two functions to make a runnable program:

* setup() – a function run once at the start of a program that can initialize settings

* loop() – a function called repeatedly until the board powers off

The integrated pin 13 LED

Page 39: CD-24-Main Doc Pid Using Arduino

A typical first program for a microcontroller simply blinks an LED on and off. In the Arduino

environment, the user might write a program like this

Program:

#define LED_PIN 13

void setup () {

pinMode (LED_PIN, OUTPUT); // enable pin 13 for digital output

}

void loop () {

digitalWrite (LED_PIN, HIGH); // turn on the LED

delay (1000); // wait one second (1000 milliseconds)

digitalWrite (LED_PIN, LOW); // turn off the LED

delay (1000); // wait one second

}

It is a feature of most Arduino boards that they have an LED and load resistor connected

between pin 13 and ground, a convenient feature for many simple tests.[29] The above code

would not be seen by a standard C++ compiler as a valid program, so when the user clicks the

"Upload to I/O board" button in the IDE, a copy of the code is written to a temporary file with an

extra include header at the top and a very simple main() function at the bottom, to make it a valid

C++ program. See Cyclic executive

The Arduino IDE uses the GNU toolchain and AVR Libc to compile programs, and uses avrdude

to upload programs to the board.As the Arduino platform uses Atmel microcontrollers Atmel’s

development environment, AVR Studio or the newer Atmel Studio, may also be used to develop

Page 40: CD-24-Main Doc Pid Using Arduino

software for the Arduino. For educational purposes there is third party graphical development

environment called Minibloq available under a different open source license.

4.4 Language Reference

Arduino programs can be divided in three main parts: structure, values (variables and constants),

and functions.

Structure

setup()

loop()

Contro l S truc tures

if

if...else

for

switch case

while

do... while

break

continue

return

goto

Further Syntax

; (semicolon)

{} (curly braces)

// (single line comment)

/* */ (multi-line comment)

#define

#include

Ari thmet ic Opera tors

= (assignment operator)

Variables

Constants

HIGH | LOW

INPUT | OUTPUT|INPUT_PULLUP

true | false

integer constants

floating point constants

Data Types

void

boolean

char

unsigned char

byte

int

unsigned int

word

long

unsigned long

short

float

double

string - char array

String - object

array

Functions

Digi ta l I /O

pinMode()

digitalWrite()

digitalRead()

Analog I /O

analogReference()

analogRead()

analogWrite() - PWM

Due only

analogReadResolution()

analogWriteResolution()

Advanced I /O

tone()

noTone()

shiftOut()

shiftIn()

pulseIn()

Time

millis()

Page 41: CD-24-Main Doc Pid Using Arduino

+ (addition)

- (subtraction)

* (multiplication)

/ (division)

% (modulo)

Comparison Opera tors

== (equal to)

!= (not equal to)

< (less than)

> (greater than)

<= (less than or equal to)

>= (greater than or equal to)

Boolean Opera tors

&& (and)

|| (or)

! (not)

Pointer Access Opera tors

* dereference operator

& reference operator

Bitwise Opera tors

& (bitwise and)| (bitwise or)

Convers ion

char()

byte()

int()

word()

long()

float()

Variab le Scope & Qual i f iers

variable scope

static

volatile

const

Random Numbers

randomSeed()

random()

Bits and Bytes

lowByte()

highByte()

bitRead()

bitWrite()

bitSet()

micros()

delay()

delayMicroseconds()

Math

min()

max()

abs()

constrain()

map()

pow()

sqrt()

Trigonometry

sin()

cos()

tan()

bitClear()

bit()

External In terrupts

attachInterrupt()

detachInterrupt()

noInterrupts()

4.5 Applications:

* Xoscillo - open-source oscilloscope

* Open-source hardware for scientific equipment.

The original Arduino hardware is manufactured by the Italian company Smart Projects. Some

Arduino-branded boards have been designed by the American company SparkFun Electronics.

Page 42: CD-24-Main Doc Pid Using Arduino

4.6 Types of Arduino:

Fifteen versions of the Arduino hardware have been commercially produced to date

1. The Serial Arduino, programmed with a DE-9 serial connection and using an ATmega8

2. The Arduino Extreme, with a USB interface for programming and using an ATmega8

3. The Arduino Mini, a miniature version of the Arduino using a surface-mounted ATmega168

4. The Arduino Nano, an even smaller, USB powered version of the Arduino using a surface-

mounted ATmega168 (ATmega328 for newer version)

5. The LilyPad Arduino, a minimalist design for wearable application using a surface-mounted

ATmega168

6. The Arduino NG, with a USB interface for programming and using an ATmega8

7. The Arduino NG plus, with a USB interface for programming and using an ATmega168

8. The Arduino Bluetooth, with a Bluetooth interface for programming using an ATmega168

9. The Arduino Diecimila, with a USB interface and utilizes an ATmega168 in a DIL28

package (pictured)

10. The Arduino Duemilanove ("2009"), using the ATmega168 (ATmega328 for newer

version) and powered via USB/DC power, switching automatically

11. The Arduino Mega, using a surface-mounted ATmega1280 for additional I/O and memory.

12. The Arduino Uno, uses the same ATmega328 as late-model Duemilanove, but whereas the

Duemilanove used an FTDI chipset for USB, the Uno uses an ATmega8U2 programmed as a

serial converter.

13. The Arduino Mega2560, uses a surface-mounted ATmega2560, bringing the total memory

to 256 kB. It also incorporates the new ATmega8U2 (ATmega16U2 in revision 3) USB chipset.

Page 43: CD-24-Main Doc Pid Using Arduino

14. The Arduino Leonardo, with an ATmega32U4 chip that eliminates the need for USB

connection and can be used as a virtual keyboard or mouse. It was released at the Maker Faire

Bay Area 2012.

15. The Arduino Esplora, resembling a video game controller, with a joystick and built-in

sensors for sound, light, temperature, and acceleration.

4.7 Open hardware and open source:

The Arduino hardware reference designs are distributed under a Creative Commons Attribution

Share-Alike 2.5 license and are available on the Arduino Web site. Layout and production files

for some versions of the Arduino hardware are also available. The source code for the IDE and

the on-board library are available and released under the GPLv2 license.

Arduino and Arduino-compatible boards make use of shields, which are printed circuit boards

that sit atop an Arduino, and plug into the normally supplied pin-headers. These are expansions

to the base Arduino. There are many functions of shields, from motor controls, to breadboarding

A list of Arduino-compatible shields is maintained at the Arduino Shield List website. A number

of shields can also be made DIY.

Page 44: CD-24-Main Doc Pid Using Arduino

CHAPTER 5

SPEED CONTROL OF DC MOTOR BY PID USING ARDUINO

5.1 Closed Loop PID Speed Control: The desired speed is obtained from the

user and the actual speed of the motor is received through the proximity sensor from the

speed measurement circuitry. The desired speed, the actual speed and the PID gains

calculated from the ultimate gain method are given as inputs to the PID controller which

in turn produces the controller output in the range of 0-5V through the 1:1 buffer. The set

up for controlling the speed of the motor is done as shown in functional block diagram of

closed loop system in Figure

Fig 5.1 Functional block diagram of closed loop speed control system of dc motor

5.2 Hardware Components:

Motor-Generator set

Thyristor Control Drive

Proximity Sensor

Arduino

Page 45: CD-24-Main Doc Pid Using Arduino

Fig 5.2: Hardware Equipment

5.2.1: Motor-Generator set:

The motor used is a separately excited dc motor whose field is kept constant and the

armature voltage is varied using Thyristor drive. Here the generator acts as a load.

5.2.2: Thyristor Control Drive:

The thyristor dc drive remains an important speed-controlled industrial drive, especially

where the higher maintenance cost associated with the DC. A motor brush (c.f. induction motor)

is tolerable. The controlled (thyristor) rectifier provides a low-impedance adjustable 'DC'.

Voltage for the motor armature, thereby providing speed control.

DC supply is given to armature circuit and field circuit through thyristor drive. The drive

is so connected that if the knob is varied from 0-5v it supplies 0-230v to armature. It also helps in

smooth speed control of motor.

Page 46: CD-24-Main Doc Pid Using Arduino

Fig 5.3 basic block diagram

The main power circuit consists of a six-thyristor bridge circuit, which rectifies the

incoming AC. supply to produce a dc. Supply to the motor armature. The assembly of thyristors,

mounted on a heatsink, is usually referred to as the 'stack'. By altering the firing angle of the

thyristors the mean value of the rectified voltage can be varied, thereby allowing the motor speed

to be controlled.

5.2.3 Proximity Sensor:

The best method of using a proximity sensor is to sense the teeth on a gear. This

type of sensing typically has options for 60, 120, or 240 PPR (pulse per revolution), and the

pulses are relatively clearly defined and symmetrical. If a gear is not available, a proximity

sensor can be used to sense the head of a bolt attached to the shaft. The drawback of this method

is the low PPR (low resolution). Hence to improve resolution 6 bolts are attached to the shaft.

5.2.3.1Methods of Determining RPM:

There are two methods for determining RPM:

I. The Frequency measurement method.

II. The period measurement method.

Page 47: CD-24-Main Doc Pid Using Arduino

Frequency measurement is better for fast-moving devices such as motors and turbines

that typically turn in thousands of revolutions per minute.

Period measurement is better for devices that move more slowly, such as shafts that turn

in less than 10 RPM.

High PPR Solutions Using the Frequency Measurement Method:

For this discussion, high PPR is considered to be at least 60 PPR. When using high PPR

sensors, such as shaft encoders or proximity sensors sensing gear teeth, the easiest way to

determine RPM is to monitor the pulse frequency from the sensor using a digital input module

and the Get Frequency command in PAC Control Professional. Then calculate the RPM using

this equation:

5.2.3.2 Low PPR Solutions Using the Period Measurement Method:

For this discussion, low PPR is considered to be anything less than 60 PPR. Because it can be

measured with higher resolution (0.1 ms), measuring the pulse period is the best method of

measuring RPM when using low PPR sensors, such as proximity sensors sensing a bolt head or

photoelectric sensors. Period is the time from the start of one pulse to the start of the next pulse.

This equation shows the relationship between frequency and period:

Frequency=1/ period

When using period measurement to monitor RPM, calculate the RPM using this equation:

RPM = 60/ (Pulse Period x PPR)

The main issue when using Period measurements occurs when the PPR is greater than 1

and the pulses are not symmetrical. For example, when shaft speed is constant and you are

sensing two bolt heads per revolution, if the bolts are not exactly evenly spaced, the periods will

be different, causing the RPM indication to be erratic.

Page 48: CD-24-Main Doc Pid Using Arduino

5.3 Program for PID controller:

//library which contain data pertaining count of frequency//

#include <FreqCount.h>

//working variables description//

float Kp = A2; // A2 pin is adopted for Kp//

float Ki = A3; //A3 pin is adopted for Ki//

float Kd = A5; //A5 pin is adopted for Kd//

float out=0;

float gatepulse = 8;

int setsped = 1200;

float sped1 =0;

float error =0;

float err1 =0;

float y0 =0;

float yn =0;

float yout =0;

float integ_yout = 0;

float diff=0,diff1=0,diff2 =0,diff_yout;

void setup()

{

pinMode(Kp, INPUT);

pinMode(Ki, INPUT);

Page 49: CD-24-Main Doc Pid Using Arduino

pinMode(Kd, INPUT);

//initializes the analog pins as inputs//

pinMode(gatepulse, OUTPUT);

//initializes the digital pin as output//

Serial.begin(9600);

FreqCount.begin(10);

}

void loop()

{

unsigned long count =0;

if (FreqCount.available())

{

count = FreqCount.read();

//FreqCount.read is a command from the library of frequency count included at the top of

program//

//the command reads the frequency count of pulses from proximity sensor//

}

sped1 =count*(10);

Serial.println(sped1);

y0 = setsped-sped1;

delay(10);

for(int i=0;i<5;i++)

{

Page 50: CD-24-Main Doc Pid Using Arduino

count =0;

if (FreqCount.available())

{

count = FreqCount.read();

}

sped1 =count*(10);

error = setsped-sped1;

//block for differentiation//

diff = (error-y0)/0.01;

diff1=diff1+diff;

err1 =err1+2*error;

delay(10);

}

count =0;

if (FreqCount.available())

{

count = FreqCount.read();

}

sped1 =count*(10);

yn = setsped-sped1;

diff2 = (yn-diff)/0.01;

diff_yout = (diff1+diff2)/6;

//diff_yout gives the output from differentiation block//

Page 51: CD-24-Main Doc Pid Using Arduino

integ_yout =(0.005)*(y0+yn+err1);

//integ_yout gives the output for the integration//

out = analogRead(Kp)*yn+analogRead(Ki)*integ_yout+analogRead(Kd)*diff_yout;

if(out>200)

{

analogWrite(gatepulse,200);

}

else if(out<=0)

{

analogWrite(gatepulse,127);

}

else

{

analogWrite(gatepulse,out);

}

}

The screen shots of the program in Arduino programming are shown below:

Page 52: CD-24-Main Doc Pid Using Arduino

Fig 5.4.1 Arduino program - i

Page 53: CD-24-Main Doc Pid Using Arduino

Fig 5.4.2 Arduino program - ii

Page 54: CD-24-Main Doc Pid Using Arduino

Fig 5.4.3 Arduino program – iii

Page 55: CD-24-Main Doc Pid Using Arduino

5.4 Conclusion:

Hence, we conclude our project by stating that we made an attempt to design PID controller

operation using arduino though there are various types of other processes which can execute the

function of PID controller like lab view software, hardware circuit, microprocessor etc.,

Reason for doing this project is to show that this method of PID operation decreases labour

when compared to other methods but what we felt during processing our project is there is lot of

possibility to short circuit as it includes large number of connections and there is also the

possibility of arduino failure as it could be overloaded when buffer fails.

But while doing project we came to know about eminence of arduino software and the struggle

put by the manufacturers in designing such a versatile kit which can access both analog as well

as digital signals and also preview the values it is receiving at every instant based on delay given.

Page 56: CD-24-Main Doc Pid Using Arduino

Appendix - A

Arduino – Data sheet

Arduino Uno

Arduino Uno R3 Front

Arduino Uno R3 Back

Page 57: CD-24-Main Doc Pid Using Arduino

Arduino Uno R2 Front Arduino Uno SMD Arduino Uno Front Arduino Uno Back

Overview:

The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14

digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a

16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.

It contains everything needed to support the microcontroller; simply connect it to a computer

with a USB cable or power it with a AC-to-DC adapter or battery to get started.

The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver

chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a

USB-to-serial converter.

Revision 2 of the Uno board has a resistor pulling the 8U2 HWB line to ground, making it easier

to put into DFU mode.

Revision 3 of the board has the following new features:

1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins

placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided

from the board. In future, shields will be compatible both with the board that use the AVR,

Page 58: CD-24-Main Doc Pid Using Arduino

which operate with 5V and with the Arduino Due that operate with 3.3V. The second one is a not

connected pin, that is reserved for future purposes.

Stronger RESET circuit.

Atmega 16U2 replace the 8U2.

"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Uno

and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is the latest

in a series of USB Arduino boards, and the reference model for the Arduino platform; for a

comparison with previous versions, see the index of Arduino boards.

Summary:

Microcontroller ATmega328

Operating Voltage 5V

Input Voltage (recommended) 7-12V

Input Voltage (limits) 6-20V

Digital I/O Pins 14 (of which 6 provide PWM output)

Analog Input Pins 6

DC Current per I/O Pin 40 mA

DC Current for 3.3V Pin 50 mA

Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader

SRAM 2 KB (ATmega328)

EEPROM 1 KB (ATmega328)

Clock Speed 16 MHz

Schematic and reference design:

EAGLE files: arduino-uno-Rev3-reference-design.zip (NOTE: works with Eagle 6.0 and newer)

Schematic: arduino-uno-Rev3-schematic.pdf

Note: The Arduino reference design can use an Atmega8, 168, or 328, Current models use

an ATmega328, but an Atmega8 is shown in the schematic for reference. The pin configuration

is identical on all three processors.

Page 59: CD-24-Main Doc Pid Using Arduino

Power:

The Arduino Uno can be powered via the USB connection or with an external power supply. The

power source is selected automatically.

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.

The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power

jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER

connector.

The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,

however, the 5V pin may supply less than five volts and the board may be unstable. If using

more than 12V, the voltage regulator may overheat and damage the board. The recommended

range is 7 to 12 volts.

The power pins are as follows:

VIN. The input voltage to the Arduino board when it's using an external power source (as

opposed to 5 volts from the USB connection or other regulated power source). You can supply

voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.

5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied

with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of

the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can

damage your board. We don't advise it.

3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.

GND. Ground pins.

IOREF. This pin on the Arduino board provides the voltage reference with which the

microcontroller operates. A properly configured shield can read the IOREF pin voltage and

select the appropriate power source or enable voltage translators on the outputs for working with

the 5V or 3.3V.

Memory:

The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of SRAM

and 1 KB of EEPROM (which can be read and written with the EEPROM library).

Page 60: CD-24-Main Doc Pid Using Arduino

Input and Output:

Each of the 14 digital pins on the Uno can be used as an input or output,

using pinMode(), digitalWrite(), and digitalRead()functions. They operate at 5 volts. Each pin

can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected

by default) of 20-50 kOhms. In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins

are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.

External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low

value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using

the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the

LED is on, when the pin is LOW, it's off.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution

(i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible

to change the upper end of their range using the AREF pin and the analogReference() function.

Additionally, some pins have specialized functionality:

TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library.

There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogReference().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to

shields which block the one on the board.

See also the mapping between Arduino pins and ATmega328 ports. The mapping for the

Atmega8, 168, and 328 is identical.

Communication:

Page 61: CD-24-Main Doc Pid Using Arduino

The Arduino Uno has a number of facilities for communicating with a computer, another

Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial

communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on the

board channels this serial communication over USB and appears as a virtual com port to

software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no

external driver is needed. However, on Windows, a .inf file is required. The Arduino software

includes a serial monitor which allows simple textual data to be sent to and from the Arduino

board. The RX and TX LEDs on the board will flash when data is being transmitted via the

USB-to-serial chip and USB connection to the computer (but not for serial communication on

pins 0 and 1).

A SoftwareSerial library allows for serial communication on any of the Uno's digital pins.

The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software

includes a Wire library to simplify use of the I2C bus; see the documentation for details. For SPI

communication, use the SPI library.

Programming:

The Arduino Uno can be programmed with the Arduino software (download). Select "Arduino

Uno from the Tools > Board menu (according to the microcontroller on your board). For details,

see the reference and tutorials.

The ATmega328 on the Arduino Uno comes preburned with a bootloader that allows you to

upload new code to it without the use of an external hardware programmer. It communicates

using the original STK500 protocol (reference, C header files).

You can also bypass the bootloader and program the microcontroller through the ICSP (In-

Circuit Serial Programming) header; see these instructions for details.

The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is available .

The ATmega16U2/8U2 is loaded with a DFU bootloader, which can be activated by:

On Rev1 boards: connecting the solder jumper on the back of the board (near the map of Italy)

and then resetting the 8U2.

On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to ground,

making it easier to put into DFU mode.

Page 62: CD-24-Main Doc Pid Using Arduino

You can then use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X and

Linux) to load a new firmware. Or you can use the ISP header with an external programmer

(overwriting the DFU bootloader). See this user-contributed tutorial for more information.

Automatic(software) reset:

Rather than requiring a physical press of the reset button before an upload, the Arduino Uno is

designed in a way that allows it to be reset by software running on a connected computer. One of

the hardware flow control lines (DTR) of theATmega8U2/16U2 is connected to the reset line of

the ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset

line drops long enough to reset the chip. The Arduino software uses this capability to allow you

to upload code by simply pressing the upload button in the Arduino environment. This means

that the bootloader can have a shorter timeout, as the lowering of DTR can be well-coordinated

with the start of the upload.

This setup has other implications. When the Uno is connected to either a computer running Mac

OS X or Linux, it resets each time a connection is made to it from software (via USB). For the

following half-second or so, the bootloader is running on the Uno. While it is programmed to

ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first

few bytes of data sent to the board after a connection is opened. If a sketch running on the board

receives one-time configuration or other data when it first starts, make sure that the software with

which it communicates waits a second after opening the connection and before sending this data.

The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side of the

trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to

disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum

thread for details.

USB overcurrent protection:

The Arduino Uno has a resettable polyfuse that protects your computer's USB ports from shorts

and overcurrent. Although most computers provide their own internal protection, the fuse

provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse

will automatically break the connection until the short or overload is removed.

Page 63: CD-24-Main Doc Pid Using Arduino

Physical characteristics:

The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively, with the

USB connector and power jack extending beyond the former dimension. Four screw holes allow

the board to be attached to a surface or case. Note that the distance between digital pins 7 and 8

is 160 mil (0.16"), not an even multiple of the 100 mil spacing of the other pins.