Interfacing Arduino With Matlab (First Book 1) A
Interfacing Arduino With Matlab (First Book 1) A
I T H M AT L AB
RAJESH DEY SUBHAJIT PAUL RAJKUMAR
MANDAL BIJOY PAL
Dedicated to RAMKRISHNA
MISSION & Dr. Achintya Das
Book Title Copyright © 2018 by Rajesh Dey & Co. All Rights Reserved.
All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical
means including information storage and retrieval systems, without permission in writing from the author.
The only exception is by a reviewer,
Limits of Liability/Disclaimer of Warranty: The publisher and the author make no representation or
warranties with respect to the accuracy or completeness of the contents of this work and specifically
disclaim all warranties, including without
limitation warranties of fitness for a particular purpose. No warranty may be created or extended by scales
and promotional materials . The advice and strategies contained here in may not be suitable for every
situation.
Author Name
Rajesh Dey
Subhajit Paul
Rajkumar Mandal
Bijoy Pal
Visit my website at www.electroinventors.com
ISBN-9781980284512
AUTHOR’S BIOGRAPHY
Raje sh Dey An Assistant Professor, Dept. of ECE, SDET-BGI, Kolkata, India,
under West Bengal University of Technology, India. He holds an M.Tech degree
in ECE from Kalyani Government Engineering College, Kalyani, Nadia, West
Bengal, India under West Bengal University of Technology, India. The Author
has 12 years of teaching experience along with 6 years of Industrial experience.
His research interests include control engineering, Adaptive signal processing,
sensor etc.
Sub hajitPaul(B.Tech.)
Dept. of ECE, SDET-BGI, Kolkata, India, under West Bengal University of
Technology, India. He has been the finalists of top National level competitions
like KSHITIJ (IIT Kharagpur) and SPARKLE (KPIT Technologies Ltd.). He is
presently working as an engineer in a reputed automation industry. His research
interests include Robotics, Arduino, Embedded System, Automation,Java, C,
C++, sensor etc.
Rajkumar Mandal M.Tech Dept. of ECE, SDET-BGI,
B ijoy Pal B.Tech Student Dept. of CSE, SDET-BGI, Kolkata, India, under West
Bengal University of Technology, India. His research interests include IOT,
Embedded System, Algorithm, Python, Java, DBMS, C, C++, sensor etc.
CONTENTS
Author’s Biography.....................................................................................................2
Preface .........................................................................................................................5
chapter 1 ...................................................................................................................... 7
chapter 2....................................................................................................................29
chapter 3 .................................................................................................................... 61
chapter 4....................................................................................................................89
PREFACE
This book has been written to have a knowledge regarding
MATLAB and Arduino based some projects. MATLAB (matrix
laboratory or grid research facility) is a multiworldview
numerical processing condition. An exclusive programming
dialect created by MathWorks, MATLAB permits grid controls,
plotting of capacities and information, usage of calculations,
formation of UIs, and interfacing with programs written in
different dialects, including C, C++, C#, Java, Fortran and
Python. A microcontroller is a single-chip computer. Before the
invention of the microcontrollers most intelligent systems were
premeditated using microprocessors. In this era Arduino is very
popular microcontroller, for its easy to access and the open source
activities and also the programming language to boot the
microcontroller is very easy. So that any person can build their
project through Arduino. In this book has been written to
interface the Arduino module with MATLAB programming
language Chapter 1 provides a basic idea based on MATLAB
programming language. This chapter is containing History,
Syntax, some projects using MATLAB
Chapter 2 provides an idea based on Arduino and their feature,
types, different units which there by helps us to implement
different projects based on Arduino and also contains some
projects regarding Arduino.
Chapter 3 provides an idea interfacing Arduino with MATLAB
and containing some project regarding Arduino with MATLAB
programming.
Chapter 4 provides an idea on Data Acquisition System
CHAPTER 1 MATLAB BASICS
1.1 INTRODUCTION:
1.2 HISTORY:
1.3 SYNTAX:
1.3.1 Variables:
(the init value), increments with each step from the previous value by 2 (the
increment value), and stops once it reaches (or to avoid exceeding) 9 (the
terminator value).
assigns to the variable named ari an array with the values 1, 2, 3, 4, and 5, since
the default value of 1 is used as the incrementer.
Matrices can be defined by separating the elements of a row with blank space or
comma and using a semicolon to terminate each row. The list of elements should
be surrounded by square brackets: []. Parentheses: () are used to access elements
and subarrays (they are also used to denote a function argument list).
A square identity matrix of size n can be generated using the function eye, and
matrices of any size with zeros or ones can be generated with the functions zeros
and ones, respectively.
Transposing a vector or a matrix is done either by the function transpose or by
adding prime to the matrix.
1.3.3 Structures:
MATLAB has structure information sorts. Since all factors in MATLAB are
exhibits, a more sufficient name is "structure cluster", where every component of
the exhibit has a similar field names. Furthermore, MATLAB underpins dynamic
field names (field look-ups by name, field controls, and so on.). Sadly,
MATLAB JIT does not bolster MATLAB structures, consequently only a basic
packaging of different factors into a structure will include some significant
downfalls.
1.3.4 Functions:
Method call behavior is different between value and reference classes. For
example, a call to a method
can alter any member of object only if object is an instance of a reference class.
An example of a simple class is provided below.
When put into a file named , this can be executed with the following
commands:
For instance of a basic intelligent count, simply sort the articulation you need to
assess. We should begin at the absolute starting point. For instance, how about
we assume you need to ascertain the articulation, 1 + 2 * 3. You write it at the
provoke summon (>>) as takes after,
>> 1+2*3 a = 7
You will have seen that on the off chance that you don't indicate a yield variable,
MATLAB utilizes a default variable a, short for reply, to store the after effects of
the present computation. Note that the variable an is
made (or overwritten, in the event that it is now existed). To stay away from this,
you may allot an incentive to a variable or yield contention name. For instance,
>> x = 1+2*3
x=7
Will bring about x being given the esteem 1 + 2 * 3 = 7. This variable name can
simply be utilized to allude to the consequences of the past calculations. In this
manner, registering 4x will bring about
>> 4*x
a = 28.0000
Functions in
Symbol Operation Example + Addition 2+3
- Subtraction 2-3 * Multiplication 2*3 / Division 2/3
A portion of the capacities in Matlab are inbuilt and some are client
characterized.
Ex:
X = ones (3, 3);
111
111
111
For more insights with respect to capacities utilize help alternative in summon
window.
Ex: >>help ones
Matlab Matrices:
Matlab regards all factors as grids. For our motivations a network can be thought
of as a cluster, indeed, that is the way it is put away. Vectors are extraordinary
types of frameworks and contain just a single line OR one section.
1)
>> x = [1 2 3 4 5 6];
>> y = [3 - 1 2 4 5 1];
>> plot(x,y)
Spare, Load,
Delete Workspace Variables:
The workspace isn't kept up crosswise over sessions of MATLAB. When you
quit MATLAB, the workspace clears. In any case, you can spare any or the
greater part of the factors in the present workspace to a MAT-record (.tangle).
You can stack MAT-records at a later time amid the current MATLAB session, or
amid another session, in the event that you need to reuse the workspace factors.
Linguistic structure for spare spare myfile VAR1 VAR2
Matlab will likewise plot a vector versus its own record. The file will be dealt
with as the abscissa vector. Given a vector ―timeǁ and a vector ―distǁ we could
state: >> plot (dist) % plotting versus file
Yield: is from a decent serial program.
At times, composing a decent serial code might be adequate for your transient
needs.In general, pre-allotment of clusters (as opposed to developing them
progressively) is likewise a critical piece of composing productive Matlab code.
The serial port session involves every one of the means you are probably going
to bring when speaking with a gadget associated with a serial port. These means
are: Create a serial port question — Create a serial port protest for a particular
serial port utilizing the serial creation work. Design properties amid protest
creation if important.
ans =9
ans =18
ans = 27
ans = 36
ans =45
ans =54
ans =63
ans =72
ans = 81
ans =90
ans =99.0000
ans =108
ans = 117
ans =126
ans = 135
ans = 144
ans =153
ans =162
ans = 171
90 3 ULA 120 60
2
150 30
1
180 0
210 330
240 300 270
0.2
0
-0.2
0.2 -0.20
-0.4 -0.2
-0.6-0.4
-0.8
-0.6
-0.8
y-axis
2D RADIATION PATTERN OF A HALF WAVE DIPOLE ANTENNA
NAME:POULAMI SAHA
OUTPUT:
ROLL NO.:BSSE/UT/EC/13/008
DATE:01-04-15
90 AT PHI=90
0.4
120 60
0.3
150 0.2 30
0.1
180 0
210 330
240 300 270
CHAPTER 2
ARDUINO BASICS
2.1INTRODUCTION:
The Arduino platform has become quite popular with people just starting out
with electronics, and for good reason. Unlike most programmable circuit boards,
the Arduino does not need a separate piece of hardware (called a programmer) in
order to load new code onto the board – we can simply use a USB cable.
Additionally, the Arduino IDE uses a simplified version of C++, making it easier
to learn to program. Finally, Arduino provides a standard form factor that breaks
out the functions of the micro-controller into a more accessible package.
Arduino also makes simpler the working process of
The list of Arduino boards includes the following such as Arduino Uno (R3)
LilyPad Arduino
Red Board
Arduino Mega (R3)
Arduino Leonardo
ARDUINO UNO (R3):
The Uno is an immense choice for your underlying Arduino. It comprises of 14-
advanced I/O pins, where 6-pins can be utilized as PWM(pulse width balance
yields), 6-simple information sources, a reset catch, a power jack, a USB
association and the sky is the limit from there. It incorporates everything
required to hold up the microcontroller; essentially append it to a PC with the
assistance of a USB link and give the supply to begin with an AC-to-DC
connector or battery.
The RedBoard Arduino board can be modified utilizing a Mini-B USB link
utilizing the Arduino IDE. It will take a shot at Windows 8 without modifying
your security settings. It is more consistent due to the USB or FTDI chip we
utilized and furthermore it is altogether level on the back. Making it is extremely
easy to use in the task outline. Simply plug the board, select the menu alternative
to pick an Arduino UNO and you are prepared to transfer the program. You can
control the RedBoard over USB link utilizing the barrel jack.
Fig.3: Redboard Arduino.
The Arduino Mega is like the UNO's huge sibling. It incorporates loads of
advanced I/O pins (from that, 14-pins can be utilized as PWM o/ps), 6-simple
sources of info, a reset catch, a power jack, a USB association and a reset catch.
It incorporates everything required to hold up the microcontroller; essentially
connect it to a PC with the assistance of a USB link and give the supply to begin
with an AC-to-DC connector or battery.The colossal number of pins make this
Arduino board extremely accommodating for planning the activities that need a
group of advanced I/ps or o/ps like parcels catches.
Fig.4: Arduino Mega (R3).
Also, Arduino shields are pre constructed circuit sheets used to associate with
various Arduino sheets. These shields fit on the highest point of the Arduino
perfect sheets to give an extra abilities like associating with the web, engine
controlling, giving remote correspondence, LCD screen controlling, etc..The
distinctive sorts of an Arduino shields are
Wireless Shields
The GSM Shield
The Ethernet Shield
The Proto Shields
Fig.6: Arduino Shields.
2.3 HARDWARE:
Now detailed analysis of pin configuration is as follows:
Power (USB / Barrel Jack):
The USB connection is also how you will load code onto your Arduino board.
NOTE: Do not use a power supply greater than 20 Volts as you will overpower
your Arduino so that it might be destroyed. The standard voltage for most
Arduino models is between 6 and 12 Volts.
Pins(5v,3.3v,GND,Analog,Digital,PMW,AREP)
The pins on your Arduino are the places where you connect wires to make a
circuit possibly in conjunction with a breadboard and some wire. They generally
have black plastic ‘headers’ that allow you to just plug a wire accurately into the
board. The Arduino has different kinds of pins, each of which is labelled on the
board and used for different utilities.
5V (4) & 3.3V (5): The 5V pin supplies 5 volts of power, and the 3.3V pin
supplies 3.3 volts of power. Most of the simple components used with the
Arduino run accurately in 5 or 3.3 volts.
GND (3): There are a number of GND pins on the Arduino, any of which can
be used to ground your circuit.
Analog (6): The pins under the ‘Analog In’ label (A0 through A5 on the
UNO) are Analog In pins. These pins can read the signal from an analog sensor
and convert it into a digital equivalent that we can read.
Digital (7): The digital pins are from 0 through 13 on the UNO. These pins
can be used for both digital input and digital output.
PWM (8): You may have observed the tilde (~) next to some of the digital
pins (3, 5, 6, 9, 10, and 11 on the UNO). These pins worked as normal digital
pins, but can also be used for a special purpose called Pulse-Width Modulation
(PWM).
AREF (9): It stands for Analog Reference. Most of the time you can leave this
pin unconnected. It is sometimes used to set an external reference voltage
between 0 and 5 Volts for the analog input pins.
Reset Button:
The Arduino has a reset button (10). Pushing it will momentarily connect the
reset pin to ground and restart any code that is loaded on the Arduino. This can
be very worthwhile if your code doesn’t repeat, but you want to test it a number
of times.
Just beneath and to the right of the word “UNO” on your circuit board, there’s a
small LED beside the word ‘ON’ (11). This LED should light up whenever your
Arduino is plugged into a power source. If this light doesn’t turn on, there’s a
definite chance that something is erroneous. Need to re-check your circuit once.
TX RX LEDs:
TX is short for transmit, RX is short for receive. These markings appear quite a
bit in electronics to specify the pins responsible for serial communication i.e. the
bit by bit communication. In our case, there are two particular places on the
Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a
second time next to the TX and RX indicator LEDs (12). These LEDs will give
us some wonderful visual indications whenever our Arduino is receiving or
transmitting data.
Main IC:
The black entity with all the metal legs is an IC, or Integrated Circuit (13).
Visualize it as the brains of our Arduino. The main IC on the Arduino is a little
different from board type to board type, but is typically from the ATmega line of
IC’s from the ATMEL company. This can be important, as you may need to
know the IC type along with your board type before loading up a new program
from the Arduino software. This information can generally be found in writing
on the top side of the IC. If you want to know more about the difference between
various IC’s, going through the datasheets is often a good idea.
Voltage Regulator:
The voltage regulator (14) is not essentially something you can interact with on
the Arduino. But it is hypothetically useful to know that it is there and what it’s
for. The voltage regulator does exactly what it says – it controls the amount of
voltage to maintain a constant value that is let into the Arduino board.
Eventually, it has its limits, so don’t plug in your Arduino to anything greater
than 20 volts.
The Arduino venture gives the Arduino improvement condition (IDE), which is
a application written in the programming dialect Java. It began from the IDE for
the dialects Processing and Wiring. It incorporates a code manager with
highlights, for example, content reordering, looking and supplanting content,
programmed indenting, support coordinating, and sentence structure featuring,
and gives straightforward a single tick components to aggregate and transfer
projects to an Arduino board. It additionally contains a message zone, a content
reassure, a toolbar with catches for normal capacities and a progression of
operation menus.
coordinated
cross-stage
Because of the organization's open source nature, there exist many free open
libraries for designers to use to increase their activities.
loop(): After setup() has been called, function loop() is executed repeatedly in
the main program. It controls the board until the board is powered off or is reset.
Most Arduino boards contain a light-emitting diode (LED) and a load resistor
connected between pin 13 and ground, which is a convenient feature for many
tests and program functions. A typical program for a beginning Arduino
programmer blinks a LED repeatedly.
/* Blink Turns on an LED on for one second, then off for one second,
repeatedly.*/
This program uses the functions pinMode(), digitalWrite(), and delay(), which
are provided by the internal libraries included in the IDE environment.
Fig.7: Arduino Software tool.
Fig.8: The Blink .
Working Methodology:
All the Remote Controls in our home that we use to control TV, Home Theatre,
AC etc work with the help of IR Blasters. An IR blaster is nothing but an IR
LED which could blaster a signal by repetitive pulsing; this signal will be read
by the receiver in the electronics appliance. For each different button on the
remote a unique signal will be blasted which after read by the receiver is used to
perform a particular pre-defined task. If we are able to read this signal coming
out from the Remote, we can then mimic the same signal using an IR LED when
ever required to perform that particular task. We have previously made a IR
Blaster circuit for Universal IR Remote and for Automatic AC Temperature
control.
A TSOP is an IR Receiver that could be used to decode the signal coming from
the Remotes. We will use this TSOP to decode all the information from our
Remote and store it on Arduino. Then using that information and an IR Led we
can re-create the IR signals from our Arduino whenever required.
3TSOP - Signal
4IRLed – Cathode Gnd
5IRLed – Anode 9
6HC-05 - Vcc 5V
7HC05 – Gnd Ground
8HC05 – Tx 10
9 HC05 – Rx 11
*/
#include <IRremote.h> //Lib for IT Blaster and TSOP #include
<SoftwareSerial.h>// import the serial library
SoftwareSerial BT_module(10, 11); // RX, TX IRsend irsend;
int khz = 38; // 38kHz carrier frequency for the NEC protocol char
BluetoothData; // the data read by Bluetooth Module int PevData;
//Decoded Remote Signals For my AC ##CHANGE IT FOR YOUR REMOTE
unsigned int ACoff[] = {2950,1750, 400,1100, 450,1050, 450,400, 400,400,
400,400, 450,1100, 400,400, 400,400, 450,1100, 400,1100, 450,350, 450,1100,
400,400, 400,400, 450,1100, 400,1100, 450,400, 400,1100, 400,1100, 450,400,
400,400, 400,1100, 450,350, 450,400, 400,1100, 450,400, 400,400, 400,400,
450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400,
450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350,
450,350, 450,1100, 400,400, 450,400, 400,1100, 450,1050, 450,400, 400,400,
400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,1100,
450,350, 450,400, 400,400, 400,400, 450,400, 400,1100, 450,350, 450,400,
400,400, 400,400, 400,1100, 450,400, 400,400, 450,350, 450,400, 400,400,
400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400,
400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400,
450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350,
450,350, 450,400, 450,350, 450,350, 450,400, 400,1100, 450,350, 450,350,
450,400, 450,350, 450,350, 450,1100, 450}; unsigned int ACon[] = {2950,1700,
450,1100, 400,1100, 450,350, 450,350, 450,400, 450,1050, 450,350, 450,400,
450,1050, 450,1100, 400,400, 450,1050, 450,350, 450,400, 400,1100, 450,1100,
450,350, 450,1050, 450,1100, 450,350, 450,350, 450,1100, 450,350, 400,400,
450,1100, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400,
400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400,
450,350, 450,350, 450,1100, 400,400, 450,350, 450,1100, 400,400, 450,350,
450,1100, 400,1100, 450,350, 450,400,
400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,1100,
450,350, 400,400, 450,350, 450,400, 450,350, 400,400, 450,400,
450,350, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400,
400,400, 400,400, 400,400, 450,350, 450,400, 450,350, 450,350,
450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400,
450,350, 450,400, 450,350, 400,400, 450,350, 450,400, 450,350,
450,350, 450,350, 450,400, 450,350, 450,1100, 400,400, 400,400,
450,350, 450,350, 450,1100, 400,400, 450}; unsigned int Temp23[] =
{3000,1650, 550,950, 550,1000, 500,300,
550,250, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,950,
550,300, 550,950, 550,250, 550,300, 500,1000, 500,1050, 500,300,
500,1000, 550,1000, 500,300, 500,300, 550,1000, 450,350, 500,300,
500,1050, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350,
450,400, 400,400, 450,350, 450,350, 450,350, 450,400, 400,400,
400,400, 450,400, 400,400, 400,400, 450,1100, 400,400, 400,400,
450,1050, 450,400, 400,400, 450,1100, 400,1100, 400,400, 450,350,
450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350,
450,1100, 400,400, 400,400, 450,350, 450,400, 400,400, 450,1100,
400,400, 400,1100, 450,1100, 400,1100, 450,350, 450,400, 400,400,
450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400,
400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400,
400,400, 450,350, 450,350, 450,400, 450,350, 400,400, 450,350,
450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350,
450,400, 400,400, 400,400, 450,350, 450,1100, 400,1100, 450,1100,
400,1100, 450,1100, 400,1100, 400,400, 450}; unsigned int Temp24[] =
{3000,1650, 500,1050, 500,1000, 500,300,
500,300, 500,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050,
500,300, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300,
500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300,
500,1050, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300,
500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300,
500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,300,
500,1050, 500,300, 500,300, 500,1050, 500,1000, 500,300, 500,350,
500,300, 500,300, 500,300, 500,350, 500,1000, 500,1050, 500,1000,
500,300, 500,350, 450,350, 500,300, 500,300, 500,350, 500,1000, 500,300,
500,300, 500,300, 500,300, 500,350, 500,300, 450,350, 500,350, 450,350,
450,350, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400,
400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 450,350, 450,350,
450,350, 450,400, 450,350, 450,350, 450,350, 500,350, 450,1050, 500,300,
500,1050, 500,1000, 500,1050, 500,1000, 500,1000, 500,350, 550}; unsigned int
Temp25[] = {3050,1650, 500,1000, 550,950, 550,300, 500,300, 500,300,
550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 500,300,
550,250, 550,1000, 500,1000, 550,300, 550,950, 550,950, 550,300, 500,300,
500,1000, 550,250, 550,300, 550,950, 550,300, 500,300, 500,300, 550,250,
550,300, 500,300, 550,250, 550,250, 600,250, 500,300, 550,250, 550,250,
550,300, 550,250, 500,300, 550,300, 500,300, 500,1000, 550,250, 550,300,
500,1000, 550,250, 550,300, 500,1000, 550,1000, 500,300, 500,300, 550,250,
550,300, 500,300, 500,300, 550,300, 500,1000, 550,950, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,1000,
500,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300,
550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 500,300,
550,250, 550,300, 500,300, 500,300, 500,350, 500,1000, 500,1000, 500,1050,
500,1000, 500,1050, 500,300, 550}; unsigned int Temp26[] = {3000,1650,
500,1000, 500,1050, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,350,
500,1000, 500,1050, 450,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050,
500,300, 500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300,
500,1050, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350,
500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350,
500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 450,350, 500,300,
500,1050, 500,1000, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350,
500,1000, 500,300, 500,1050, 500,300, 500,300, 500,300, 500,350, 500,300,
500,300, 500,1050, 500,300, 500,1050, 450,1050, 500,1000, 500,350, 500,300,
500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350, 500,300,
500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350,
500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350,
500,300, 500,300, 500,350, 450,1050, 500,1000, 500,350, 500,1000,
500,1000, 500,1050, 500,1000, 500,350, 500}; unsigned int Temp27[] =
{3050,1600, 550,1000, 500,1000, 550,300,
500,300, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,1000,
500,300, 550,1000, 550,250, 500,300, 550,1000, 500,1050, 500,300,
500,1000, 550,1000, 500,300, 550,250, 550,1000, 550,250, 550,300,
500,1000, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300,
550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300,
500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300,
550,1000, 500,300, 500,300, 550,1000, 550,1000, 500,300, 500,300,
550,250, 550,300, 500,300, 550,300, 500,300, 500,300, 550,1000,
500,300, 550,250, 550,300, 500,300, 500,300, 500,350, 500,300,
550,250, 550,1000, 500,1000, 550,1000, 500,300, 550,300, 500,300,
550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300,
550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 500,300,
550,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300,
500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300,
500,300, 500,350, 500,300, 500,350, 500,300, 500,300, 500,1050,
500,1000, 500,1050, 500,1000, 500,350, 500}; // PANASONIC C4D3:64800024
unsigned int Temp28[] = {3100,1600, 550,950, 550,1000, 550,250,
550,250, 550,250, 550,1000, 500,300, 500,300, 550,1000, 500,1000,
550,250, 550,1000, 500,300, 550,250, 550,1000, 550,950, 550,300,
500,1000, 550,950, 550,300, 550,250, 500,1000, 550,300, 500,300,
550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 550,250,
500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 600,250,
500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300,
500,1000, 550,250, 550,300, 500,1000, 550,1000, 550,250, 550,250,
550,250, 550,300, 500,300, 550,250, 550,1000, 500,1000, 550,250,
550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,1000,
500,300, 500,1000, 550,1000, 500,1000, 550,250, 550,300, 500,300,
550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300,
500,300, 550,250, 550,300, 550,250, 500,300, 550,250, 550,250, 550,300,
500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300,
500,300, 550,1000, 500,300, 500,300, 550,950, 550,1000, 500,1000, 550,1000,
500,300, 550}; unsigned int Temp29[] = {3100,1550, 600,950, 500,1000,
550,300, 500,300, 500,300, 550,950, 550,300, 550,250, 550,1000, 500,1000,
550,250, 550,1000, 500,300, 550,250, 550,950, 600,950, 550,250, 550,1000,
500,1000, 550,250, 600,250, 550,950, 550,250, 550,300, 550,950, 550,250,
550,300, 550,250, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300,
500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,250, 600,250,
550,950, 550,250, 550,300, 500,1000, 550,250, 550,300, 550,950, 550,1000,
500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,1000,
500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,1000,
550,250, 550,1000, 500,1000, 550,1000, 500,300, 500,300, 550,300, 500,300,
500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300,
550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300,
550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250,
550,250, 550,1000, 500,1000, 550,1000, 500,1000, 550,300, 500}; unsigned int
Temp30[] = {3000,1650, 500,1000, 550,1000, 500,300, 500,300, 550,250,
550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 550,250,
550,250, 550,1000, 550,950, 550,300, 500,1000, 550,950, 550,300, 500,300,
550,950, 550,300, 550,250, 550,1000, 500,300, 500,300, 550,250, 550,250,
550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300,
500,300, 500,300, 550,300, 500,300, 500,300, 550,950, 550,300, 500,300,
500,1000, 550,250, 550,300, 550,950, 550,1000, 500,300, 550,250, 550,250,
600,250, 500,300, 550,250, 550,1000, 500,300, 550,250, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,950,
550,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300,
500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300,
550,250, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300,
500,1000, 500,1000, 500,1050, 500,300, 500}; //Change it for your remote
void setup() {
BT_module.begin(9600); // BT works on 9600 Serial.begin(57600); // Serial
Monitor works on 57600
Void loop() {
While(BT_module.read()) // If data is coming {
BluetoothData=BT_module.read(); // read it and save it
Serial.println(BluetoothData); // print it on serial for testing purpose
}
if (BluetoothData != PevData)
{
if ( BluetoothData==’0’ )
{
irsend.sendRaw(ACon, sizeof (ACon) / sizeof(ACon[0], khz); delay(2000);
//Send signal to Turn On the AC
}
if ( BluetoothData==’1’ )
{
irsend.sendRaw(ACoff, sizeof (ACoff) / sizeof(ACoff[0], khz); delay(2000);
//Send signal to Turn Off the AC }
if(BluetoothData=='2')
{
irsend.sendRaw(Temp23,sizeof(Temp23)/sizeof(Temp23[0]),khz) ;
delay(2000);//Send signal to set Temperatue 23C if(BluetoothData=='3') {
irsend.sendRaw(Temp24,sizeof(Temp24)/sizeof(Temp24[0]),khz
);
delay(2000);//Send signal to set Temperatue 24C }
if(BluetoothData=='4') {
irsend.sendRaw(Temp25,sizeof(Temp25)/sizeof(Temp25[0]),kh
z);
delay(2000);//Send signal to set Temperatue 25C }
if(BluetoothData=='5')
{
irsend.sendRaw(Temp26,sizeof(Temp23)/sizeof(Temp26[0]),kh
z);
delay(2000);//Send signal to set Temperatue 26C }
if(BluetoothData=='6') {
irsend.sendRaw(Temp27,sizeof(Temp27)/sizeof(Temp27[0]),kh
z);
delay(2000);//Send signal to set Temperatue 27C }
if(BluetoothData=='7') {
irsend.sendRaw(Temp28,sizeof(Temp28)/sizeof(Temp28[0]),kh
z);
delay(2000);//Send signal to set Temperatue 28C }
if(BluetoothData=='8') {
irsend.sendRaw(Temp29,sizeof(Temp29)/sizeof(Temp29[0]),kh
z);
delay(2000);//Send signal to set Temperatue 29C if(BluetoothData=='9') {
irsend.sendRaw(Temp30,sizeof(Temp30)/sizeof(Temp30[0]),k hz);
delay(2000);//Send signal to set Temperatue 30C
}
}
PevData = BluetoothData;
delay(100);//prepare for next data ...
1. the first traffic light (TF1) has the red signal and the pedestrians ON; the
second one (TF2) has green ON.
2. TF1 has red and yellow ON; TF2 has yellow ON
3. TF1 is green now and TF2 is red and pedestrians ON
4. TF1 is yellow and TF2 is red and yellow
In this floating state, it’s possible that a false reading will occur as it fluctuates
with electrical interference. In other words, a floating switch is giving neither a
reliable high, nor low state reading. A pull down resistor keeps a small amount
of current flowing when the switch is closed, thereby ensuring an accurate low
state reading. In other logic circuits, you may find a pull-up resistor instead –
this works on the same principle, but in reverse, making sure that particular logic
gate defaults to high.
Now, in the loop part of the code, instead of changing the lights every 15
seconds, we’re going to read the state of the pushbutton switch instead, and only
change the lights when it’s activated.
Code:
Start by adding a new variable to the start of the program:
if (digitalRead(button) == HIGH){
delay(15); // software debounce
if (digitalRead(button) == HIGH) {
Code:
First, assign your new traffic light pins to variables, and configure them as
outputs, just like in the first example:
// light one
int red1 = 10;
int yellow1 = 9;
int green1 = 8;
// light two
int red2 = 13;
int yellow2 = 12;
int green2 = 11;
void setup(){
// light one
pinMode(red1, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(green1, OUTPUT);
// light two
pinMode(red2, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green2, OUTPUT);
}
Now, update your loop to use the code from the first example (instead
Once again, all the work is being carried out in the changeLights() function.
Rather than going red > red & yellow > green, this code will alternate the traffic
lights. When one is on green, the other will be on red. Here’s the code:
void changeLights(){
// turn both yellows on
digitalWrite(green1, LOW);
digitalWrite(yellow1, HIGH);
digitalWrite(yellow2, HIGH);
delay(5000);
}
CHAPTER 3
INTERFACING ARDUINO WITH MATLAB
3.1 INTRODUCTION:
MATLAB and Simulink let you assemble Arduino ventures utilizing abnormal
state programming and square outlines.
MATLAB Support Package for Arduino gives you a chance to impart over USB
to your Arduino and associated gadgets, for example, Adafruit engine shield,
I2C, and SPI gadgets. Since MATLAB is an abnormal state deciphered dialect
you can get comes about because of I/O directions promptly without
aggregating. MATLAB incorporates worked in math, designing, and plotting
capacities that you can use to break down and imagine information from your
Arduino. The natural dialect and capacity to effortlessly plot sensor information
attract numerous Arduino clients to MATLAB.
Simulink Support Package for Arduino gives you a chance to create calculations
that run independent on your Arduino. For those of you not comfortable with
Simulink, it is a square outline condition for displaying dynamic frameworks and
creating calculations. The help bundle broadens Simulink with obstructs for
designing Arduino sensors and perusing and composing information from them.
Subsequent to making your Simulink show, you can reproduce it, tune
calculation parameters, and download the finished calculation for independent
execution on the gadget. One especially helpful (and remarkable) capacity
offered by Simulink is the capacity to tune parameters live from your PC while
the calculation keeps running on the equipment.
Often used early in development -> can then convert to C (e.g.,) for speed.
Can be linked to C/C++, JAVA, SQL, etc.
Many algorithms and toolboxes freely available.
We're going to create simple MATLAB m-files to talk to our Arduino board. The
MATLAB Support Packages for Arduino Hardware lets you use MATLAB to
communicate with your board through USB cable. The support packages are
available for 32-bit and 64-bit Windows, 64-bit Mac OS and 64-bit Linux.
STEP 3: Select
Arduino on Support for. You should see two Arduino support packages. You can
select both. If done, click Next> button.
STEP 4: You will be asked to log on with your MATLAB account. You should
have MATLAB license. Click Log In button.
STEP
5: You will get the authentication dialog. Fill your account. After that, click Log
In button.
STEP 6: If successful, you should get a
software license agreement. Click on I accept and then click Next> button.
STEP 11: The program will check if your platform needs Arduino driver or not.
If you’re working on Linux and Mac, you don’t need a driver. You need to install
Arduino driver if you’re working on Windows platform. Click Next> button if
done.
3.3
CONNECTING ARDUINO BOARD TO COMPUTER:
Once the bundles are introduced, interface your Arduino board to your PC and
sort the accompanying charge in MATLAB order window,
>> a = arduino()
In the event that you have more than one Arduino associated with your PC, you
need to indicate the board sort you will communicate with:
>> a = arduino('com3', 'uno')
MATLAB will then endeavour to communicate with your board. On the off
chance that fruitful, MATLAB will show the properties of the Arduino board
associated with your PC as demonstrated as
This data shows the port on which your board is associated, the model of your
Arduino board, and accessible pins and libraries accessible for the board.
In your workspace, you will see a variable a, which is the MATLAB Arduino
question. Run the accompanying order to clear this protest. >> clear a
This order will expel the protest ‘a’ from your workspace.
Right off the bat, you set working envelope on MATLAB. You can transform it
on MATLAB IDE, see a red bolt.
Then, click New Script icon to create a new script file.
3.4.1 CODE:
board = arduino();
led = 'D13';
for k=1:10
end
disp('close Arduino board'); clear board;
3.4.2 OUTPUT:
MATLAB bolster for Arduino board gives three capacities which we can use on
computerized I/O preparing. The accompanying is the capacities:
Pushbutton is
connected to Arduino
digital pin 8.
3.5.2 CODE:
function [] = led_pushbutton()
pushbutton = 'D8';
led = 'D9';
board=arduino();
finishup = onCleanup(@() exitprogram(board));
configurePin(board,pushbutton,'DigitalInput');disp('press Ctr-C to exit');
while 1
state = readDigitalPin(board,pushbutton);
writeDigitalPin(board,led,state);
disp(state);
pause(0.5);
end
end
function exitprogram(b) clear b;
disp('program has exit'); end
We use onCleanup(), to catch CTRL+C for quiting the program. Save this
program into file, called led pushbutton.m.
Run the program and press puchbutton. Then, you should see lighting LED.
3.5.2 OUTPUT:
MATLAB bolster for Arduino board gives five capacities which we can use on
simple I/O preparing. The accompanying is the capacities:
advanced stick.
writePWMDutyCycle() is utilized to set PWM obligation cycle
on computerized stick.
readVoltage() to peruse simple contribution on Analog stick. In this section, we
endeavor to get to Arduino Analog I/O
utilizing MATLAB. There are three situations for our cases: Controlling RGB
LED
Controlling LED shine
Perusing Analog information utilizing Potentiometer
function [] = led_rgb()
board = arduino();
finishup=onCleanup(@()exitprogram(board));
configurePin(board,'D3','PWM');
configurePin(board,'D5','PWM');
configurePin(board,'D6','PWM');
disp('press Ctr-C to exit');
while 1
disp ('red');
write_rgb(board,0,1,1); % red pause(1);
disp('green');
write_rgb(board,1,0,1); % green pause(1);
disp('blue');
write_rgb(board,1,1,0); % blue pause(1);
disp('yellow');
write_rgb(board,0,0,1); % yellow pause(1);
disp('purple');
write_rgb(board,0.3,1,0.3);%purple pause(1);
disp('aqua');
write_rgb(board,1,0,0); % aqua pause(1);
end
end
end
function exitprogram(b)
clear b;
disp('program has exit');
end
Save this program as led_rgb.m.This program will generate six colors: red,
green, blue, yellow, purple, and aqua.
3.6.1.3 OUTPUT:
3.6.2 ANALOG OUTPUT VOLTAGE / LED BRIGHTNESS:
3.6.2.2 CODE:
function [] = led_brightness()
board = arduino();
finishup=onCleanup(@()exitprogram(board));
configurePin(board,'D3','PWM');
disp('press Ctr-C to exit'); while 1
for k = 0:5
writePWMVoltage(board,'D3',k);
pause(1);
end
for k = 5:-1:0
writePWMVoltage(board,'D3',k);
pause(1);
end
end
end
function exitprogram(b)
clear b;
disp('program has exit');
end
Save these scripts into a file, called led_brightness.m. This program will set
voltage value on PWM pin on digital pin 3 from 0 to 5 and then set a value from
5 to 0 too.
3.6.2.3 OUTPUT:
You can run the program by typing this command. >> led_brightness
On hardware side, you should see LED brightness changing gradually.
3.6.3 ANALOG INPUT / WORKING WITH
POTENTIOMETER:
In this area, we figure out how to peruse simple contribution on Arduino board.
For outline, I utilize Potentiometer as simple info source. Our situation is to
peruse simple incentive from
You can connect VCC to Arduino board on VCC +5V pin. Vout to Arduino
board Analog input A0. In addition, GND to Arduino board GND. The
following is hardware implementation. Use slide potentiometer.
3.6.3.2 CODE:
function [] = potentiometer()
board = arduino();
finishup=onCleanup(@()exitprogram(board));
3.6.3.3 OUTPUT:
To run the program, you can type this command. >> potentiometer
You should see analog value on Command Window.
Servo engine gives a pole development 360 degree. We can control this
development in view of its degree. In this situation, you can utilize any DC
engine (servo) that will be associated with Arduino. I utilized a little servo from
Arduino Sidekick Basic unit. The accompanying is a photo of my smaller than
expected servo engine.
function [] = servo_motor()
board = arduino();
finishup=onCleanup(@()exitprogram(board)); motor= servo(board,'D10');
3.7.2 OUTPUT:
You should see servo motor is running from degree 0 to 180 and then back again
from degree 180 to 0.
CHAPTER 4
DATA ACQUISITION SYSTEM (DAS)
4.1 INTRODUCTION:
Data acquisition is the way toward inspecting signals that measure genuine
physical conditions and changing over the subsequent specimens into advanced
numeric esteems that can be controlled by a PC. Information securing
frameworks, truncated by the acronyms DAS or DAQ, commonly change over
simple waveforms into advanced esteems for preparing. The parts of information
obtaining frameworks include:
Flag conditioned hardware, to change over sensor signals into a frame that
can be changed over to computerized values.
Simple to-computerized converters, to change over conditioned sensor signs
to advanced esteems.
There are likewise open-source programming bundles giving all the vital
instruments to procure information from various equipment hardware. These
instruments originate from mainstream researchers where complex analysis
requires quick, adaptable and versatile programming. Those bundles are
typically custom fit however more broad DAQ bundle like the Maximum
Integrated Data Acquisition System can be effortlessly custom-made and is
utilized as a part of a few material science tests around the world.
Signal conditioning circuitry to convert sensor signals into a form that can be
converted to digital values.
Analog-to-digital converters, which convert conditioned sensor signals to
digital values.
4.2.1 OBJECTIVE:
DAS must acquire the necessary data, at correct speed and at correct time.
It must monitor the complete plant operation to maintain on line and safe
operations.
It must be able to collect, summarise and store data for diagnosis of operation
and record purpose.
It must be flexible and capable of being expanded for future requirements.
It must be able to compute unit performance indices using online, real time
data.
It must be reliable, easy to operate and must be user friendly.
4.3 PHYSICAL SYSTEM / CONDITIONS:
4.3.1 TRANSDUCERS:
4.4 METHODOLOGY:
DAQ hardware interfaces the signal and a PC. It could be in the form
of modules that can be connected to the computer's ports or cards
connected to slots in the motherboard. Following are some hardware's:
CAMAC - Computer Automated Measurement and Control
Industrial Ethernet
LAN extensions for Instrumentation NIM
PowerLab
VME bus VXI
MERITS/ADVANTAGES:
1. Reduced data redundancy.
2. Reduced updating errors and increased consistency.
3. Greater data integrity and independence from applications
programs.
4. Improved data access to users through use of host and query
languages.
5. Improved data security.
6. Reduced data entry, storage, and retrieval costs.
7. Facilitated development of new applications program.
DEMERITS/DISADVANTAGES:
1. Database systems are complex, difficult, and time-consuming
to design.
2. Substantial hardware and software start-up costs Damage to
database affects virtually all applications programs.
3. Extensive conversion costs in moving form a file-based system
to a database system. 4. Initial training required for all programmers and users.
...'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465'); sendmail(toaddress, 'subject’, ‘Message’); %
function to send mail
4.10 SIMULINK:
that the cursor shape changes to double-lined cross hairs as it approaches the
Mux block. Drawing a branch line is slightly different from drawing the line you
just drew. To weld a connection to an existing line.Finish making block
connections
Now, open the Scope block to view the simulation output. Keeping the Scope
window open, set up Simulink to run the simulation for 10 seconds. First, set the
simulation parameters by choosing Simulation Parameters from the Simulation
menu. On the dialog box that appears, notice that the Stop time is set to 10.0 (its
default value).
Fig. 7: Output Waveform
The simulation stops when it reaches the stop time specified in the Simulation
Parameters dialog box or when you choose stop from the Simulation menu. To
save this model, choose Save from the File menu and enter a filename and
location. That file contains the
3. Tick the check box of which you want to download. Click on next for option.
4.Log into your Matlab account for downloading the package.
5. After login you can find the window as shown.
6.Next an install option will come click install to install the software
7. Give finish after you download the entire package.
8.Click on examples to get this window.
9.Now let’s see from scratch how to build Simulink model, just click Simulink
library then you will be appearing with many libraries there we can see our
Simulink arduino package library.
10. In
the left there will be option to open new model, open a new model
11.In this example we are going to use digital output block ,just drag and drop on
new model, just double click on this block you will appearing with in which pin
number you are going to show output, give it as 9 click ok.
12. Go to sources library drag and drop pulse generated block, double click on
that give sample time 0.1 and click ok, because it is going to generate the pulse
every one second. We can see that by using scope which is available in sinks
library.
13. Later connect the pulse generator and digital output.
14.Now we shall move on to code generation, save the model as tutorial1.
15.Click on tools and select run on target hardware and prepare to run, it opens
configuration parameters dialog there we have to select arduino uno as target
hardware and leave rest of parameters as default and click ok.
16. Now we have to download the code to hardware, just go to tools and select
run on target hardware and run.
17. In the bottom bar of model it is going to show status of download
18.After the download finishes, at that time LED has to blink for every second.
Fig. 8: Arduino Uno connected to LED via resistor.