EEE Unit 2 Peripheral Interface NOTES No
EEE Unit 2 Peripheral Interface NOTES No
Prepared By,
Mr. Chinmay V. Deshpande
M.E. (Power System)
Department of Electrical Engineering
Interfacing of LED with Atmega 328P
LEDs are small, powerful lights that are used in many different applications
In Loop function
1) Turn LED ON by using digitalWrite () function.
2) Call the delay
3) Turn LED OFF by using digitalWrite () function.
4) Call the delay
Sketch (Program)
void setup( ) // the setup function runs only once
{
void loop( ) // the loop function runs over and over again
{ forever
digitalWrite(13, LOW); // Pin 13= LED. Turn LED LOW i.e. OFF
lcd.setCursor (4,1)
lcd.Print (“Z”)
Denotes Denotes
Column Row
As our columns starts from 0, 5th Column will be column number 4 and 2nd row is
denoted as 1. Hence we have used (4,1) here
Functions used in LCD
LiquidCrystal()
Description: This library allows an Arduino board to control Liquid Crystal displays
(LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most
text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data
lines in addition to the rs, enable, and, optionally, the rw control lines).
Syntax: #include<LiquidCrystal.h>
Functions used in LCD
begin()
Description: Initializes the interface to the LCD screen, and specifies the dimensions
(width and height) of the display. begin() needs to be called before any other LCD library
commands.
lcd.begin(16,2)
Functions used in LCD
clear()
Description: Clears the LCD screen and positions the LCD cursor in upper left corner
Syntax: lcd.clear()
Syntax: lcd.setCursor(col,row)
Ex: lcd.setCursor(5,1) i.e. Setting the cursor at 6th Column and 2nd row
Functions used in LCD
print()
Description: Print text to LCD.
Syntax: lcd.print(data)
A variable of type Liquid Crystal Data to print, like char, byte, int,
long, or string)
Syntax: lcd.display()
Syntax: lcd.nodisplay()
In Loop function
1. Set the cursor to respective column and row
2. Call the delay
Sketch (Program)
#include<LiquidCrystal.h> // Include LCD library
Serial communication occurs between Arduino and computer/serial devices at a same baud rate like
4800, 9600, 115200, 34800, etc. It is bits per second (bps).
Syntax: Serial.begin(baud_rate);
The units of baud rate is bits per second (bps) and the common values of baud rate are 9600 bps,
19200 bps, 115200 bps etc.
The preferred baud rate in most devices is 9600 bps and the default value in Arduino’s serial terminal
is also the same.
In the sketch, we will initialize the serial communication by writing Serial.begin (9600); in the setup
function.
1. Serial.write();
2. Serial.print();
3. Serial.println();
Serial.write() function
Description: This is the simplest output command. It is used to write some data on the Serial Port
and it send data in binary form. It sends only one byte of data at a time. A single value of 0-255. The
input to the function can be defined with a numerical value or with a character in single quotes.
This function writes binary data to the serial port.
void setup() {
Serial.begin (9600); //initiate serial communication with 9600
baud rate
}
void loop() {
Serial.println("hello"); //send data to computer
delay(1000);
}
int a = 5;
int b = 15;
int c = 20;
Serial.print("a = ");
Serial.println(a); Here is some math
Serial.print("b = ");
a=5
Serial.println(b);
1. Serial.read();
2. Serial.available();
Serial.read() function
Description: Reads incoming serial data received on RX pin of arduino.
Syntax: Serial.read()
Serial.available() function
Description: This function is used to Get the number of bytes (characters) available for
reading from the serial port. This is data that’s already arrived and stored in the serial
receive buffer
Syntax: Serial.available()
Serial.end() function
Description: Disables serial communication, allowing the RX and TX pins to be used for
general input and output. To re-enable serial communication, call Serial.begin().
Syntax: Serial.end()
Algorithm
In Setup function
1) Initialize the serial port with desired baud rate (eg.: 9600).
2) Transmit the initial message
In Loop function
1) Declare the variable with data type integer to hold the received data.
2) Check for any data received for serial port.
3) If YES, read the data into variable and retransmit the data on serial port.
Sketch (Program)
Serial.println(“Please Send data”); //It will print sentence and cursor will go to
next line.
}
void loop( ) // the loop function runs over and over again forever
{
if(Serial.available( ) ) // Check for any data is received on serial port.
}
}
Concept of ADC Used in Arduino328P with Functions
Microcontroller are called devices which deals with digital information. They only
understand “0” and “1”.
An ADC is very useful feature that converts analog voltage on a pin to digital no. By
converting from analog world to digital world, we can begin to use electronics to
interface to analog world around us.
analogRead() function
There are few sensors which will sense only analog values like
temperature, pressure , gas sensor etc.
Why
0 to 1023????
Note:
Pin numbers with ~ symbol indicates
that it is used for PWM purpose.
E.g.: ~3 ~5 indicates that these pins
can be used for PWM.
~ = tilde symbol
analogWrite() function
In analogWrite() syntax, duty cycle scale is from 0 (always OFF) to 255 (always ON)
And so on……..
The LM35, LM335 and LM34 are linear temperature sensors that output a voltage proportional to the
temperature value. They can be powered by the Arduino 5V pin, and to read the voltage, you use an
analog pin.
Interfacing Diagram
A0
Algorithm
1) Start
2) Declare variables for storing the temperature values. Here we will use:
3) Configure arduino A0 pin as an analog input to read LM35 sensor output. Use syntax as
pinMode(A0,INPUT)
Algorithm
5) Read temperature sensor (LM35) value and convert it into degree Celsius.
Vout=analogRead(A0); //It reads the value of specified analog pin (Here A0) and
stores in Vout variable.
Vout= (Vout*5*100)/1023;
7) END
Arduino analog pins can measure upto +5 volts OR the voltage on
which it is working normally +5 volts.
WHY
Vout= Arduino analog pin resolution is 1023 starting from 0 as it works on
(Vout*5*100)/1023; 10 bit binary resolution (i.e. 2^10=1024). On +5 volts input it counts
to 1023.
Suppose value read by analogRead function is “65” and it is stored in Vout variable.
This value “65” is decimal value because analogRead value reads analog input voltage
between 0 to 5 volt and it gets converted into decimal value that will range from 0 to
1023.
}
https://youtu.be/9czGfmporjs
LVDT
LVDT is an acronym for Linear Variable Differential Transformer.
A linear variable differential transformer (LVDT) is an absolute measuring device that converts linear
displacement into an electrical signal through the principle of mutual induction. LVDT is used to calculate
displacement.
The main components of an LVDT are a transformer and a core.
LVDT is a transformer consisting of one primary winding P and two secondary winding S1 & S2 mounted
on a cylindrical former. The two secondary winding have equal number of turns and placed identically on
either side of the primary winding as shown in figure
A movable soft iron core is placed inside the former. Actually the movable core is made of nickel iron with
hydrogen annealed. Hydrogen annealing is done to eliminate harmonics, residual voltage of core and thus
provides high sensitivity.
Construction of LVDT
The movable core also is laminated in order to reduce eddy current loss. The assembly of laminated core is
placed in a cylindrical steel housing and end lids are provided for electromagnetic and electrostatic
shielding. The displacement to be measured is attached to this movable soft iron core.
LVDT: Working Principal
Since the primary winding of Linear Variable
Differential Transformer (LVDT) is supplied with
AC supply, it produces an alternating magnetic
flux in the core which in turn link with the
secondary winding S1 and S2 to produce emf due
to transformer action.
The magnitude of Es1 and Es2 will depend upon the magnitude of
rate of change of flux (dØ / dt) as per the Faraday’s Law.
The lower the value of ‘dt’, the more will be the emf induced. But lower value of ‘dt’
means that core is moving faster. Thus we can say that the faster the movement of
core, the greater will be the magnitude of emf induced in secondary windings.
LVDT: Working Principal
E0 = Es1 – Es2
The direction of movement of a physical quantity can be identified by the output voltage of LVDT. If the
output voltage E0 is positive, this means the physical quantity is moving toward left.
If the output voltage E0 is negative, this will mean that the physical quantity is moving in the right
direction from the NULL position.
The amount / magnitude of displacement is proportional to the magnitude of output voltage. The more
the output voltage, the more will be displacement. But we can’t take core out of the former; otherwise the
output voltage will become zero.
https://youtu.be/anCnrtjNLQM
LVDT: Working Principal_(In Short)
Sr. No. Core Position Emf induced in winding 2 (S1, S2) output voltage E0
1. At centre (Null Position) Es2 = Es1 E0 = Es1 – Es2=0
NULL position of Linear Variable
Differential Transformer is the
normal position of movable core
where the net output voltage is
zero.
2. Core is moved left to the Es1 > Es2 E0 = (Es1 – Es2) = Positive.
NULL position This means that the output
voltage E0 will be in phase with
the primary voltage.
3. Core is moved right to Es2 > Es1 E0 = (Es1 – Es2) = negative.
the NULL position This means that the output
voltage of LVDT will be in phase
opposition (180 degree out of
phase) with the primary voltage.
Advantages of LVDT
• No Physical Contact Between the Core and the Coils
• Long Operating Life
• Theoretically Infinite Resolution
• Easy Modification
• Low Power Consumption
• High Accuracy
• Fast Response
The distinct advantage of using an LVDT displacement transducer is that the moving core does not
make contact with other electrical components of the assembly, as with resistive types, as so
offers high reliability and long life.
Applications of LVDT
• LVDT is used to measure displacement ranging from fraction millimeter to centimeter.
• Acting as a secondary transducer, LVDT can be used as a device to measure force, weight and pressure,
etc..
LVDT Interfacing
In electronics system, LVDT is used generally with rectifier and signal conditioning device. The rectified
output is given to the signal conditioning circuit and the output of signal conditioning circuit is applied to
the analog input pin of Arduino which has build in ADC.
The displacement in core of LVDT generates analog output voltage. The analog output voltage is in the
range of 0 to 10 V.
The ATMEGA 328P is able to sense the voltage from 0 to 5V. Hence, in order to downgrade the voltage of
LVDT to 0-5V, we have to use voltage divider circuit. The output voltage is then read by analogRead()
function of Arduino. Here we are converting analog input voltage value to appropriate digital value by the
internal ADC of Atmega 328P.
The value measured here is then send to serial monitor window of Arduino IDE through USB to serial
cable. The FT232R is a USB to serial UART interface.
LVDT Interfacing Diagram
Voltage Divider Arrangement
𝟏
𝑽𝒐𝒖𝒕 = ∗ 𝟏𝟎 = 𝟓 𝑽
𝟏+𝟏
Sketch (Program)
void setup( ) // the setup function runs only once
{
}
Sketch (Program)
void loop( ) // the loop function runs over and over again
{ forever
When an external force is applied on an object, due to which there is a deformation occurs in the shape of
the object. This deformation in the shape is both compressive or tensile is called strain, and it is measured
by the strain gauge.
Stress is defined as the object's internal resisting forces, and strain is defined as the displacement and
deformation that occur.
A strain gauge is a long length of conductor arranged in a zigzag pattern on a membrane. When it is
stretched, its resistance increases and Vice Versa.
https://youtu.be/BH8hAWRDTkA
https://youtu.be/s1WiMFQPFFo
Strain Gauge-Working
A strain gauge works on the principle of electrical conductance and its dependence on the conductor’s
geometry. Whenever a conductor is stretched within the limits of its elasticity, it doesn’t break but, gets
narrower and longer. Similarly, when it is compressed, it gets shorter and broader, ultimately changing its
resistance.
We know, resistance is directly dependent on the length and the cross-sectional area of the conductor
given by:
R= L/A
L1 is the original length of wire L2 is the new length after an external force is applied on it
ε = (L2-L1)/L1
Where ε =strain
Whenever an external force changes the physical parameters of an object, its electrical resistivity also
changes. A strain gauge measures this deformity by using the Gauge Factor formula.
strain ε is proportional to
change in resistance.
change in resistance is
proportional to change in
output voltage VD which in
turns proportional to
analog output voltage Vo.
Based on this, we get value
of corresponding digital
output in decimal.
Sketch (Program)
void setup( ) // the setup function runs only once
{
Serial.println(“Strain Gauge Interface”); //advances to the next line after printing what
you give it.
}
Sketch (Program)
void loop( ) // the loop function runs over and over again
{ forever