SRI RAMAKRISHNA ENGINEERING COLLEGE
[Educational Service : SNR Sons Charitable Trust]
[Autonomous Institution, Accredited by NAAC with ‘A’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001-2008 Certified and all eligible programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.
Data Acquisition and Control using
Arduino & MATLAB
Prepared by
Mr.S.Kaushik
AP/EIE
Microcontroller ?
SREC - EIE - 14/AUG/18 MATLAB BASICS 3
Microcontroller
• A microcontroller is a small computer on a single
integrated circuit.
• A microcontroller contains
– one or more processor
– memory and
– programmable input/output peripherals.
SREC - EIE - 14/AUG/18 MATLAB BASICS 4
Microcontroller
• Microcontrollers are "embedded" inside some other
device (often a consumer product)
• Microcontrollers are dedicated to one task and run
one specific program.
• Microcontrollers are often low-power devices.
• A microcontroller is often small and low cost.
SREC - EIE - 14/AUG/18 MATLAB BASICS 5
Computer Vs Microcontroller
SREC - EIE - 14/AUG/18 MATLAB BASICS 6
Computer parts
Figure 1 Computer parts
SREC - EIE - 14/AUG/18 MATLAB BASICS 7
CMOS & BIOS
Monitor
Hard Disk
Keyboard & Mouse
Mother Board
RAM
Printer & Speaker
CPU
Figure 2 Function of a computer
SREC - EIE - 14/AUG/18 MATLAB BASICS 8
Microcontroller
Figure 3 Function of a microcontroller
SREC - EIE - 14/AUG/18 MATLAB BASICS 9
Microprocessor and Microcontroller
SREC - EIE - 14/AUG/18 MATLAB BASICS 10
VS
Figure 4 Comparison between Microprocessor and Microcontroller
SREC - EIE - 14/AUG/18 MATLAB BASICS 11
Microcontroller in a Control System
SREC - EIE - 14/AUG/18 MATLAB BASICS 12
Simple feed back control
(Velocity control of flight jet)
Figure 5 F16 Flight jet
SREC - EIE - 14/AUG/18 MATLAB BASICS 13
Open loop System
Pilot
Input : Output
Fuel flow rate for jet engine Velocity
Flight
Actuator
Engine
Figure 6 Open loop system for velocity control of flight jet
Velocity of flight is varied by adjusting thrust force
Thrust force may be varied by adjusting the fuel flow rate
SREC - EIE - 14/AUG/18 MATLAB BASICS 14
Closed loop system
Input : Fuel flow rate
Flight Engine
Actuator
Set point : Velocity
Error
Controller
Output : Velocity
PV
Velocity :
Sensor
Figure 7 Closed loop system for velocity control of flight jet
SREC - EIE - 14/AUG/18 MATLAB BASICS 15
Microcontroller
Input : Fuel flow rate
Flight Engine
Actuator
Set point : Velocity
Controller
Output : Velocity
Measured Velocity
Velocity :
Sensor
Figure 8 Function of a microcontroller in a closed loop system
SREC - EIE - 14/AUG/18 MATLAB BASICS 16
Microcontroller : Arduino UNO
SREC - EIE - 14/AUG/18 MATLAB BASICS 17
Arduino : PIN Diagram
Figure 9 Arduino pin diagram
SREC - EIE - 14/AUG/18 MATLAB BASICS 18
Arduino : Specification
Table 1 Specification of Arduino UNO
SREC - EIE - 14/AUG/18 MATLAB BASICS 19
Interfacing MATLAB & Arduino
SREC - EIE - 14/AUG/18 MATLAB BASICS 20
Install Arduino support package
Figure 10 Install Arduino support package
SREC - EIE - 14/AUG/18 MATLAB BASICS 21
UPLOAD ADIOES.PDE TO THE ARDUINO BOARD
1. Connect the Arduino, make sure that the
right board and serial port are selected in the
IDE, (Tools/Board and Tool/Serial Port) then
select
2. File -> Upload to I/O Board and wait for the
"Done Uploading" message
SREC - EIE - 14/AUG/18 MATLAB BASICS 22
Step 1 :From the Arduino IDE, go to
File -> Open, locate the file adioes.pde
Figure 11 Open file adioes.pde in Arduino IDE
SREC - EIE - 14/AUG/18 MATLAB BASICS 23
Step 2: Connect the Arduino, make sure that the right
board and serial port are selected in the IDE
Figure 12 Install adioes.pde using Arduino IDE
SREC - EIE - 14/AUG/18 MATLAB BASICS 24
Matlab Command Window
• a=arduino('COM4')
SREC - EIE - 14/AUG/18 MATLAB BASICS 25
Arduino UNO programming
in MATLAB
SREC - EIE - 14/AUG/18 MATLAB BASICS 26
Connecting MATLAB & Board
a=arduino('COM4') // type in matab command window
Figure 13 Connecting Arduino IDE with MATLAB in COM4 port
SREC - EIE - 14/AUG/18 MATLAB BASICS 27
Defining PIN mode : Input / Output
• Configure a pin no 13 as output
– pinMode(a,13,'output');
Figure 14 Configuring PinMode 13 of Arduino UNO to output
SREC - EIE - 14/AUG/18 MATLAB BASICS 28
Turning on LED
• output the digital value (0 or 1) to pin 13
– digitalWrite(a,13,1);
Figure 15 Turning LED in 13th pin
SREC - EIE - 14/AUG/18 MATLAB BASICS 29
Program procedure in MATLAB
% connect the board
% specify pin mode for selected pins
% read digital input
% output the digital value (0 or 1) to the
selected pin
SREC - EIE - 14/AUG/18 MATLAB BASICS 30
MATLAB GUI
SREC - EIE - 14/AUG/18 MATLAB BASICS 31
SREC - EIE - 14/AUG/18 MATLAB BASICS 32
SREC - EIE - 14/AUG/18 MATLAB BASICS 33
SREC - EIE - 14/AUG/18 MATLAB BASICS 34
LED control using IR sensor
a=arduino('COM4');
pinMode(a,8,'input');
pinMode(a,13,'output');
interv= 1000; % Maximum time in seconds for data acquisition
passo=1; % Increment time
t=1; % initialize time
while(t<interv)
STATUS=digitalRead(a,8);
digitalWrite(a,13,STATUS);
t=t+passo;
end
SREC - EIE - 14/AUG/18 MATLAB BASICS 35
Analog input
SREC - EIE - 14/AUG/18 MATLAB BASICS 36
Connecting a potentiometer with
Arduino
Potentiometer PIN 1 : 5 V
Potentiometer PIN 2 : Analog
pin 2
Potentiometer PIN 3 : GND
Figure 16 Connecting potentiometer to Arduino UNO board
SREC - EIE - 14/AUG/18 MATLAB BASICS 37
R1
Figure 17 Voltage divider
R2
Vout = R2 / (R1 + R2) * Vin
R2 = R1 * (1 / ((Vin / Vout) - 1))
Figure 16 Pin diagram for connecting potentiometer
SREC - EIE - 14/AUG/18 MATLAB BASICS 38
Analog to Digital converter
• 10 bit ADC
• 210 = 1024
• To find the voltage for every sensed value
– 𝑉𝑜𝑢𝑡 = 𝑆𝑒𝑛𝑠𝑒𝑑
2𝑛
𝑣𝑎𝑙𝑢𝑒
∗𝑉𝑖𝑛
– Eg: V = 681 / 1024.0 * 5.0 = 3.325V
SREC - EIE - 14/AUG/18 MATLAB BASICS 39
Program
clear all;
clc;
a=arduino('COM4'); % Connecting Arduino Uno board
pinMode(a,2,'input'); % defining 2 pin as analog input
interv= 1000; % Maximum time in seconds for data acquisition
passo=1; % Increment time
t=1; % initialize time
x=0;
while(t<interv)
Rref = 10000;
Vin = 5;
av=analogRead(a,2); % Reading the analog value at pin 2
Vout = (Vin * av) / 1023; % Converting to voltage value
R = (Rref * (1 / ((Vin / Vout)-1)))/1000;
x=[x,R];
plot(x);
axis([0,interv,0,10]);
grid
t=t+passo; % increment seconds
drawnow;
end
SREC - EIE - 14/AUG/18 MATLAB BASICS 40
Analog Value
Value of the resistance in Ω
Time in sec
Figure 18 Output of the potentiometer plot with respective time in MATLAB
SREC - EIE - 14/AUG/18 MATLAB BASICS 41
Thank you
SREC - EIE - 14/AUG/18 MATLAB BASICS 42