EEE 6a
EEE 6a
Arduino 0 1 2 3 4 5
Analog
Input Pin
Sketch(Program)
• The accelerometer connections are defined as
constants at the beginning of the sketch, using the two
Analog pins 4 and 5 as source of power.
• This is accomplished using them as Digital I/O pins 18
and 19.
• const int groundpin = 18;
• const int powerpin = 19;
• Setting pin 19 (A5) as HIGH and pin 18 (A4) as LOW
provides the 5V with few milliamps needed by the
accelerometer to work.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
Program
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
• void setup() {
Serial.begin(9600); // initialize the serial communication
// provide ground and power by using the analog inputs as
//normal digital pins
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
// delay before next reading:
delay(100);
}
LVDT
• Linear variable differential transformer.
• It converts linear motion into electrical signals.
• Output across secondary of transformer is differential, so the
name is differential transformer.
• The LVDT is highly reliable sensor because the magnetic core
can move without friction and do not touch the inside of tube.
• Applications:
-Flight control feedback system
-Automated measurements in machine tools
-Position feedback in servo motors
-Many industrial and scientific eletromechanical
applications
LVDT
LVDT operation
• LVDT transformer consists of primary winding P and
two secondary winding S1 and S2 wound on a
cylindrical former.
• Both secondary winding have equal number of turns
and are identically placed on the either side of primary
winding.
• Primary winding is connected to AC source which
produced flux in air gap so voltages are produced in the
secondary of LVDT.
• The resultant output i9s the difference between the
voltages of two winding.
Block diagram of LVDT interface
Strain Gauge
• A strain gauge is a sensor whose resistance varies with the
applied force.
• It converts force, pressure, tension, weight, etc., into a change
in electrical resistance which can then be measured.
Description
• When an external force is applied on an object, due to which
there is a deformation occur in the shape of the object.
• The deformation in the shape is either compressive or tensile is
called as strain, and it is measured by strain gauge.
• Because of the deformation in the shape of the object there is a
change in the resistance end to end.
• The strain gauge is sensitive to the small changes occurs in the
geometry of the object.
• By measuring the resistance of the object, the amount of
induced stress can be measured.
• Strain gauge has a long thin metallic strips arranged in a zig-zag
pattern on a non conducting material called as carrier.
Strain gauge bridge circuit
• R1 and R3 are the ratio arms equals to each other and R2 is the
rheostat arm has value equal to strain gauge resistor.
• When gauge is unstrained, the bridge is balanced and voltmeter
shows zero voltage.
• As there is a change in a resistance of gauge, bridge is unbalanced
and voltmeter shows reading.
• The output voltage of the bridge is amplified with differential
amplifier.
• The output of the amplifier can read through the analog input
of the Arduino board and output is displayed on the serial monitor
or LCD display.
Concept of PWM
• Pulse width modulation(PWM) is technique for getting analog
results with digital means.
• Pulse Width Modulation or PWM is a common technique used to
vary the width of the pulses in a pulse-train. PWM has many
applications such as controlling servos and speed controllers,
limiting the effective power of motors and LEDs.
• Pulse width modulation is basically, a square wave with a varying
high and low time. A basic PWM signal is shown in the following
figure.
There are various terms associated with PWM −
On-Time − Duration of time signal is high.
Off-Time − Duration of time signal is low.
Period − It is represented as the sum of on-time and off-time of
PWM signal.
Duty Cycle − It is represented as the percentage of time signal that
remains on during the period of the PWM signal.
Period
As shown in the figure, Ton denotes the on-time and Toff denotes the
off-time of signal. Period is the sum of both on and off times and is
calculated as shown in the following equation −
Ttotal=Ton+Toff
Duty Cycle
Duty cycle is calculated as the on-time of the period of time. duty
cycle is calculated as −
D=Ton/(Ton+Toff)=Ton/Ttotal
Arduino’s PWM
• analogWrite() function generates a square wave that can be
varied in the function.
• The two things the function needs to run are a pin/variable and a
value to set the duty cycle.
• The value that gets input for this function has to be between 0
and 255.
• A duty cycle of 100% occurs if the value is set at 255 and a
value of 0 gives a duty cycle of 0%.
• To get a specific duty cycle a value for analogWrite() needs to be
calculated. This is shown below.
• Duty cycle x 255=analogWrite value
• For example, a duty cycle of 20% would need to be set at a value
of 51.
Generating PWM signals on Arduino board
Timers/Counters
Features
• Channel Counter
• Clear Timer on Compare Match (Auto Reload)
• Glitch-free, Phase Correct Pulse Width Modulator (PWM)
• Frequency Generator
• 10-bit Clock Prescaler
• Overflow and Compare Match Interrupt Sources (TOV2, OCF2A,
and OCF2B)
• Allows Clocking from External 32kHz.
Registers
• The Timer/Counter (TCNT2) and Output Compare Register
(OCR2A and OCR2B) are 8-bit registers.
• Interrupt request signals are all visible in the Timer Interrupt
Flag Register (TIFR2). All interrupts are individually masked
with the Timer Interrupt Mask Register (TIMSK2).
• The Timer/Counter can be clocked internally, via the prescaler,
or asynchronously clocked from the TOSC1/2 pins.The
asynchronous operation is controlled by the Asynchronous
Status Register (ASSR).
• The double buffered Output Compare Register (OCR2A and
OCR2B) are compared with the Timer/ Counter value at all
times. The result of the compare can be used by the Waveform
Generator to generate a PWM or variable frequency output on
the Output Compare pins (OC2A and OC2B).