[go: up one dir, main page]

0% found this document useful (0 votes)
64 views37 pages

6 - Arduino IO Interfacing

The document provides an overview of interfacing microcontrollers, specifically Arduino, with various output drive circuits, including NPN and PNP transistors, MOSFETs, and opto-isolators. It explains the concepts of sink and source modes, the use of transistors for controlling loads, and the importance of current limits and protection against back EMF. Additionally, it covers configurations for H-Bridge motor control and the implications of using different types of transistors and MOSFETs in circuit designs.

Uploaded by

Sandiswa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views37 pages

6 - Arduino IO Interfacing

The document provides an overview of interfacing microcontrollers, specifically Arduino, with various output drive circuits, including NPN and PNP transistors, MOSFETs, and opto-isolators. It explains the concepts of sink and source modes, the use of transistors for controlling loads, and the importance of current limits and protection against back EMF. Additionally, it covers configurations for H-Bridge motor control and the implications of using different types of transistors and MOSFETs in circuit designs.

Uploaded by

Sandiswa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Arduino

Arduino Uno ATmega328 Arduino Mega ATmega2560

INPUT AND OUTPUT INTERFACING


Created by: Dr. Daniel van Niekerk
Microcontroller Output Drive Interfacing
VDC VDC
In SINK mode In SOURCE
the switch is mode the switch
Lamp
connected to is connected to
Load
the ground or SW Vdc or “Live”
“Neutral” side. side.
Lamp
SW Load

SINK SOURCE

• Introduction
̶ The output drive of a microcontrollers is only five volts at most, with a few milli-amps.
̶ However, most electrical and electronic devices require voltages and currents that are
greater and therefore, output drive circuits are required.
̶ Also, electrical input and electronic sensing devices can operate at higher voltages and
therefore, input interfacing circuits are also required.
• Concept of sink and source
̶ When a switch is connected to ground or the Neutral side, the switch "sinks" voltage.
̶ When a switch is connected to VDC or the Live side, the switch "sources" voltage.
Basic NPN Transistor Switch
̶ The most common drive circuit consists of P2N2222A:VCEmax = 40V, ICmax = 600mA, but with
an NPN bipolar transistor controlling a IC = 150mA, VBE=0.6V, VCEsat = 0.3V & hfe = 100
load connected to a high power supply.
150mA Lamp
̶ The high power supply’s ground must be +5V +9V
Load @ 12V
12VDC
tied to Arduino’s microcontroller ground. Or Supply
5V Vin
̶ When a digital pin is configured as an input Arduino RB
its state is known as floating because the 1K5
P2N2222A
pin is connected to nothing. Digital Pin
Pdmax = 625mW
̶ When a digital pin is configured as an GND
output, a HIGH digital pin switches to 5V
and a LOW digital pin switches to 0V.
̶ A digital "HIGH" sources a current to the IB = IC/hfe = 150mA/100 = 1,5mA
base-emitter of the transistor, which must But to ensure transistor saturation let IBsat = 2xIB = 3mA
be limited by resistor RB. RB = (5V-0.6V)/3mA = 1466R ≈ 1K5 (E24)
Note: Pd = (VCEsat x IC) = (0.3V x 150mA) = 45mW
̶ This causes a larger current to flow in the
collector-emitter circuit and the load.
̶ The maximum current that an Arduino
digital pin can source is 40mA, but the
total current for Arduino chip is only
200mA.
̶ Therefore, the recommended output
current limit for each digital pin is:
(200mA/20 digital pins) = 10mA.
NPN Power Darlington Transistor Switch
̶ A Darlington NPN transistor has a much TIP120: VCEmax = 60V, ICmax = 5A, but with IC = 3A,
higher gain and therefore requires little VBE = 2.5V, VCEsat = 2V and hfe = 1000
base current to sink a larger load current.
+5V +9V 12VDC
̶ Darlington arrangement is two transistors Or IN4007 M Supply
with common collectors and the emitter 5V Vin
RB
3A @10V
Arduino
of one is tied to the other's base. 390Ω
Motor Load

Digital Pin TIP120


̶ If each transistor has a gain of 30, then the Pdmax = 65W
total hfe gain would be (30 X 30) = 900. GND

̶ The freewheeling diode (IN4007) is use to


prevent Motor Back EMF from destroying
IB = IC/hfe = 3A/1000 = 3mA
the transistor when it is switched off. But to ensure transistor saturation let IB = 2x3mA = 6mA
RB = (5V-2.5V)/6mA = 416Ω ≈ 390Ω (E24)
̶ When switched off, the current in the Note: Pd = (VCEsat x IC) = 2V x 3A = 6W
motor inductive winding continues to flow (Requires heat sink because ambient Pd ≤ 2W)
in the same direction because of the
winding collapsing magnetic field.
̶ The voltage at the collector then increases
when the current has nowhere to flow.
̶ Eventually the VCEmax is reached thereby
destroying the transistor, but with a
freewheeling diode the current can flow
back to the supply or motor load.
PNP Power Darlington Transistor Switch
̶ A Darlington PNP transistor switch can be TIP125: VCEmax = 60V, ICmax = 5A, but with IC = 3A,
used to “source” current to a load. VBE=2.5V, VCEsat = 2V and hfe = 1000
BC107: VCEmax = 45V, ICmax = 100mA, but with
̶ When Q1 is switched on, current flows IC≤10mA, VBE=0.7V, VCEsat = 0.25V and hfe = 110
through RC and then switches Q2 on. 12Vdc
̶ Both TIP120 and TIP125 are known as a Q2
complimentary pair, because they have TIP125
+5V +9V
Pdmax = 65W
the same electrical specifications but Or RC
5V Vin
opposite semiconductor polarity. Arduino RB
2K7

̶ The internal diode is used to protect the 75K


Q1
Digital Pin M IN4007
transistor, by diverting inductive load back BC107
EMF spikes to the supply, when transistors GND 3A @10V
Motor Load
are used in an H-Bridge configuration.

IBQ2 = ICQ2/hfeQ2 = 3A/1000 = 3mA


RC = (12V-2.5V-0.25V)/3mA = 3083Ω ≈ 2K7Ω (E24)
IBQ1 = ICQ1/hfeQ1 = 3mA/110 = 0.027mA
But to ensure saturation let IBQ1 = 2x0.027mA = 0.054mA
RB = (5V-0.7V)/0.054mA = 79630Ω ≈ 75KΩ (E24)
Power Darlington Transistor H-Bridge Motor Control
̶ The rotation direction of a permanent 12V
magnet DC motor, is dependent upon Q3 Q4
TIP125 TIP125
the polarity of the applied voltage. 2K7 2K7

̶ With D7 pin set high and PWM applied Q1 Q1


to D6 pin, the DC motor speed can be BC107
3A @ 10V
BC107
75K 75K
controlled in the forward direction. M
D7 Motor Load D8
̶ With D8 pin set high and PWM applied 390Ω 390Ω
~D5 D6~
to D5 pin, the DC motor speed can be
Q1 Q2
controlled in the reverse direction. TIP120 TIP120

̶ With all pins set low, the DC motor is


left in floating mode because no voltage
applied to the DC motor.
̶ When switching between the forward
and the reverse direction, wait a few
microseconds in the float mode, to
avoid high shoot-through currents in
Q3 and Q1 or Q4 and Q2.
̶ The transistor internal suppression
diodes divert the motor inductive back
EMF spikes to the supply, when the
transistors are switched off.
Basic N-Channel MOSFET Switch
̶ Here is a basic N-channel power MOSFET IRF630: VDSmax = 200V, IDmax = 9A, VGSmax = ±20V,
switch driver, that can "sink" load current. VGS(th) = 4V, RDS(on) = 0.4Ω
̶ Unlike a bipolar transistor which is a Pdmax = 74W
5A Lamp
current controlled device, a MOSFET is +5V +9V Load @ 10V 12VDC
considered a voltage controlled device. Or Supply
5V Vin D
̶ An electrical positive voltage or charge on Arduino
the gate (G) relative to the source (S) will IRF630
switch the MOSFET on. G
Digital Pin
S
̶ The only purpose of RG (5 k to 10 K) is to GND RG
bleed off any remaining charge on the 10K
gate (G) terminal when voltage is removed
in order to switch the MOSFET off.
Note: VDS = 5A x 0.4Ω = 2V
̶ When the VGS(th) voltage is reached the And: Pd = ID2xRDS(on) = (5A)2x0.4Ω = 10W
MOSFET starts to switch on.
̶ Make sure that VGSmax voltage is not
exceeded to avoid damaging the MOSFET.
̶ The internal parasitic suppression diode is
used to protect the MOSFET by diverting
generated inductive load back EMF spikes
in an H-bridge configuration, back to the
supply.
Basic P-Channel MOSFET Switch
̶ With a P-channel power MOSFET, the IRF9630: VGS(th) = -4V, RDS(on) = 0.8Ω, Pdmax = 74W,
source terminal (S) is connected to the VDSmax = -200V, IDmax = -6.5A, VGSmax = ±20V,
positive terminal of the power supply. 2N2222A: VCEmax = 40V, ICmax = 800mA,
12Vdc
with IC ≤ 150mA, VBE=0.6V,
̶ When Q1 is switched off (no 5 V applied) VCEsat = 0.4V and hfe = 100
there is 12 Volts on the collector of Q1 and RG
on the gate of Q2 . 10K
S
̶ When Q1 is switch on (5 V applied) it will G
drop the collector voltage of Q1 and the +5V +9V
Or Q2
gate of Q2 to 0 Volts. 5V Vin IRF9630 D
Arduino RB
̶ Q2 will then switch on and sources current 18K
to the load (RG should be 5 K to 10 K). Digital Pin
Q1
2N2222A
̶ A bipolar transistor and a MOSFET driver
GND
circuit both require a common connection 5A Lamp
to the Arduino microcontroller ground. Load @ 8V

̶ The -12V difference between the gate and ICQ1 = (12V-0.4V)/10K = 11.6mA
source when the MOSFET is conducting, IBQ1 = ICQ1/hfe = (11.6mA/100) = 0.116mA
But to ensure saturation let IBQ1 = 2x0.116mA = 0.232mA
ensures operation in the saturation mode RB = (5V-0.6V)/0.232mA = 18965Ω ≈ 18KΩ (E24)
with a fast, hard turn on. Note: VDS = 5A x 0.8Ω = 4V
And: PdQ2 = ID2xRDS(on) = (5A)2x0.8Ω = 20W
Basic P-Channel MOSFET Switch at Higher Voltages
̶ The gate to source breakdown voltage 24Vdc
(VGSmax = ±20 V) must not be exceeded.

D
S
̶ With the supply voltage set to 24 V, a 10 V

IRF9630
RG

G
Zener diode in series with the transistors

Q2
10K
collector, will keep VGS voltage below 20 V.
̶ This is often referred to as a “series pass” +5V +9V
Or 10V
configuration. 5V Vin Zener
Arduino RB
18K
Q1
Digital Pin
2N2222A
GND
5A Lamp
Load @ 8V
Power MOSFET H-Bridge Motor Control
̶ A permanent magnet DC motor 24V
rotation direction is dependent upon
the polarity of the applied voltage. 10K 10K
S S
̶ With D7 pin set high and PWM RB RB
G G
applied to D6 pin, the DC motor 18K Q3
IRF9630
Q4
IRF9630
18K
D7 D8
speed can be controlled in the Q5 D D Q6
forward direction. 2N2222A M 2N2222A

̶ With D8 pin set high and PWM D D

applied to D5 pin, the DC motor G


Q1 Q2
G
IRF630 IRF630
speed can be controlled in the ~D5
S S
D6~

reverse direction. 10K 10K

̶ With all pins set low, the DC motor is


left in floating mode with no voltage
applied.
̶ When switching between the forward
and the reverse direction, wait a few
microseconds in the float mode, to
avoid high shoot-through currents in
Q3 and Q1 or Q4 and Q2.
̶ The internal parasitic suppression
diodes divert the motor inductive
back EMF spikes to the supply, when
the MOSFETS are switched off.
Basic Optically-Isolated Transistor Switch
̶ By using opto-couplers or opto-isolators, 4N25: VCEmax = 70V, ICmax = 50mA, VCEsat = 0.5V
the higher-voltage power supply can be Ifmax = 60mA, Vf = 1.3V and CTRDC = 50%
R2
totally disconnected from the Arduino 2K2Ω
microcontroller ground, when required.
+5V +9V
̶ In this way an input or output circuit has no Or 5mm
electrical connection to the Arduino circuit, 5V Vin Red LED
with several thousand volts of isolation Arduino R1
4N25
180Ω
(for 4N25, VISO ≥ 5000V). Digital Pin
1 6
24V
̶ The 4N25, 4N26, 4N27 and 4N28 devices 2 5 Supply
GND
consist of a gallium arsenide infrared
emitting diode optically coupled to a 3 4
NC
monolithic silicon photo-transistor
detector. R1 = (5V-Vf)/If >> let If = 20mA
R1 = (5V-1.3V)/20mA = 185Ω ≈ 180Ω (E24)
̶ The 4N25 output transistor is a low power IC = (If x CTRDC) = (20mA x 50%) = 10mA
R2 = (24V-VLEDred-VCEsat)/IC
device, therefore it is used to drive higher R2 = (24V-2V-0.5V)/10mA = 2150Ω ≈ 2K2 (E24)
power bi-polar transistors or MOSFETs.
̶ The 4N29, 4N30, 4N31, 4N32 and 4N33
devices are optically coupled to a photo-
Darlington detector.
̶ This series is designed for applications
requiring higher collector output currents
with lower input currents.
Optically-Isolated NPN Darlington Transistor Switch
̶ A NPN Darlington power transistor with a 4N25: VCEmax = 70V, ICmax = 50mA, VCEsat = 0.5V,
gain of 1000 will require very little base Ifmax = 60mA, Vf = 1.3V and CTRDC = 50%
current from a 4N25 Opto-coupler, in TIP120: VCEmax=60V, ICmax = 5A, with IC = 3A,
VBE = 2.5V, VCEsat = 2V, hfe = 1000, Pdmax = 65W
order to be switched on. and Motor Load is 3A @ 24V
̶ Note that the 4N25 device current transfer +5V +9V
ratio (CTR) is only 50% and therefore, only Or 24V
half of the applied emitting diode current 5V Vin
Arduino
can flow through the photo-transistor 4N25
3A
collector to emitter. Digital Pin
1 6
Motor M
̶ The NPN Darlington power transistor is 2 5 Load
GND IN4007
switched on in order to "sink" the load.
3 4
NC
̶ Opto-couplers can be use for: RB
5V R1
> General purpose switching circuits GND 270Ω
3K6 TIP120
> Interfacing and coupling systems of 24V
different potentials and impedances IB = IC/hfe = 3A/1000 = 3mA
GND
But to ensure saturation let IB = 2x3mA = 6mA
> Input or output Interfacing RB = (24V-2.5V-0.5V)/6mA = 3500Ω ≈ 3.6K (E24)
> Switching power supply regulators If = (IC4N25/CTRDC) = 6mA/50% = 12mA
R1 = (5V-Vf)/If = (5V-1.3V)/12mA = 308Ω ≈ 270Ω (E24)
> Digital logic and microcontroller inputs
Optically-Isolated PNP Darlington Transistor Switch
̶ A PNP Darlington power transistor can 4N25: VCEmax = 70V, ICmax = 50mA, VCEsat = 0.5V,
also be optically controlled but in this case Ifmax = 60mA, Vf = 1.3V and CTRDC = 50%
the base must be switched to ground in TIP125: VCEmax=60V, ICmax = 5A, with IC = 3A,
VBE = 2.5V, VCEsat = 2V, hfe = 1000, Pdmax = 65W
order to turn on.
and Motor Load is 3A @ 24V
24V
̶ The PNP Darlington power transistor is
+5V +9V TIP125
switched on in order to "source" the load. Or
̶ The 24 V supply is electrically isolated 5V Vin RB
from the Arduino microcontroller 5 V Arduino 3K6
4N25
supply. Digital Pin
1 6
3A
2 5 Motor
GND Load M
3 4 IN4007
NC
5V
R1
GND 24V
270Ω
GND
IB = IC/hfe = 3A/1000 = 3mA
But to ensure saturation let IB = 2x3mA = 6mA
RB = (24V-2.5V-0.5V)/6mA = 3500Ω ≈ 3.6K (E24)
If = (IC4N25/CTRDC) = 6mA/50% = 12mA
R1 = (5V-Vf)/If = (5V-1.3V)/12mA = 308Ω ≈ 270Ω (E24)
Optically-Isolated N-Channel MOSFET Switch
̶ A N-channel power MOSFET can also be IRF630: VDSmax = 200V, IDmax = 9A, VGSmax = ±20V,
optically switched on in order to "sink" VGS(th) = 4V, RDS(on) = 0.4Ω and Pdmax = 74W
the load. +5V +9V 12V
Or
̶ Ensure that the supply voltage of 12 V 5V Vin
5A
does not exceed VGSmax (±20 V). Arduino
Lamp
4N25
̶ The only purpose of RG (5 K to 10 K) is to Digital Pin
1 6
bleed off any remaining charge on the D
2 5 IRF630
gate (G) terminal in order to switch the GND
MOSFET off. 3 4 G
NC
5V S
R1 RG
GND
180Ω 10K

Let If = 20mA, then R1 = (5V-Vf)/If 12V


R1 = (5V-1.3V)/20mA = 185Ω ≈ 180Ω (E24) GND
Pd = ID2xRDS(on) = (5A)2x0.4Ω = 10W
Optically-Isolated P-Channel MOSFET Switch
̶ A P-channel power MOSFET can also be IRF9630: VDSmax = -200V, IDmax = -6.5A,
12Vdc
optically switched on in order to "source" VGSmax = ± 20V, VGS(th) = -4V,
the load. RDS(on) = 0.8Ω and Pdmax = 74W

̶ Ensure that the supply voltage of 12 V RG


10K
does not exceed VGSmax (±20 V). +5V +9V S
Or
5V Vin G
Arduino
4N25
1 6 IRF9630 D
Digital Pin
2 5
GND
3 4
NC 3A
5V Lamp
R1
GND
180Ω 12V
GND
Pd = ID2xRDS(on) = (3A)2x0.8Ω = 7.2W
Optically-Isolated Resistive Triac Switch
̶ The MOC302XM series are optically MOC3022: Vfmax = 1.5V, Ifmax = 60mA, VISO = 7500 and LED
isolated triac driver devices. trigger current: 10mA ≤ If ≤ 60mA
BTA06-600C: IT(RMS) = 6A, VDRM = 600V, IGT = 25mA, VGT = 1.3V
̶ These devices contain a GaAs infrared Live
+5V +9V
emitting diode and a light activated Or 220V, 60W 220 to
silicon bilateral switch, which functions 5V Vin Lamp Load 240VAC
like a triac. Arduino R1
MOC3022
330Ω 180Ω
1 6
̶ They are designed to interface between Digital Pin
A2
electronic controls and power triacs in GND
2 5 BTA06-600C
order to control resistive and inductive 3 4 G
NC A1
loads for 240 VAC operations. Neutral
R1 = (5V-Vfmax)/If >> let If = 10mA for MOC3022
̶ The optically isolated triac drivers can not R1 = (5V-1.5V)/10mA = 350Ω ≈ 330Ω (E24)
drive an AC load directly because it is
only intended to be a trigger device.
̶ The opto-coupler isolates the low
voltage DC control of a microcontroller,
from the high AC voltage.
̶ The circuit configuration shown, is only
used to drive resistive loads and uses a
non-sensitive gate triac (IGT>15mA).
Optically-Isolated Inductive Sensitive Triac Switch
̶ This circuit configuration is used MOC3021: Vfmax = 1.5V, Ifmax = 60mA, VISO = 7500 and LED trigger
to drive an inductive load using a current: 15mA ≤ If ≤ 60mA
BTA06-600SW: IT(RMS) = 6A, VDRM = 600V, IGT = 10mA, VGT = 1.3V
sensitive gate triac (IGT<=15mA).
Live
+5V +9V
̶ Optically isolated triac device Or 3A @ 220VAC
applications: 5V Vin Magnetic Contactor
> Industrial controls Arduino R1
MOC3021 220VAC
220Ω 180Ω 2.4KΩ
1 6 50Hz
> Solenoid/valve controls Digital Pin
A2
> Traffic lights GND
2 5
BTA06-600
> Static AC power switch 3 4
0.1uf
G
SW
NC A1
> Vending machines Neutral
R1 = (5V-Vfmax)/If >> let If = 15mA for MOC3021
> Incandescent lamp dimmers R1 = (5V-1.5V)/15mA = 233Ω ≈ 220Ω (E24)
> Solid-state relay
> Motor controls
> Lamp ballasts
> Interfacing microcontroller for
AC voltage control
Optically-Isolated Inductive Non-sensitive Triac Switch
̶ This circuit configuration is used MOC3023: Vfmax = 1.5V, Ifmax = 60mA, VISO = 7500 and LED trigger
to drive an inductive load using current: 5mA ≤ If ≤ 60mA
BTA06-600B: IT(RMS) = 6A, VDRM = 600V, IGT = 50mA, VGT = 1.3V
a non-sensitive gate triac
(15mA ≤ IGT ≤ 50mA). Live
+5V +9V
Or 4A @ 230VAC
5V Vin Magnetic Contactor
Arduino R1
MOC3023 230VAC
680Ω 180Ω 1.2KΩ
1 6 50Hz
Digital Pin
A2
2 5
GND BTA06-600
0.2uf B
3 4 G
NC A1
Neutral
R1 = (5V-Vfmax)/If >> let If = 5mA for MOC3023
R1 = (5V-1.5V)/5mA = 700Ω ≈ 680Ω (E24)
Optically-Isolated Triac Live Side Switch
̶ Using this circuit the “Live” side of MOC3020: Vfmax = 1.5V, Ifmax = 60mA, VISO = 7500 and LED trigger
the line is switched and the load is current: 30mA ≤ If ≤ 60mA and
BTA06-600C: IT(RMS) = 6A, VDRM = 600V, IGT = 25mA, VGT = 1.3V
connected to the “Neutral” side.
Live
̶ The 39 ohm resistor and 0.01μF R1
MOC3020
capacitor is used for snubbing of 110Ω
1 6
360Ω 470Ω 39Ω
D9
the triac. A2
2 5
̶ The 470 ohm resistor and 0.05μF GND
0.05uf 0.01uf
capacitor is used for snubbing the 3
NC
4 G
A1
opto-coupler.
̶ These components may or may not

LOAD
240VAC
be necessary depending upon the 50Hz
R1 = (5V-Vfmax)/If >> let If = 30mA for MOC3020
particular load used. R1 = (5V-1.5V)/30mA = 117Ω ≈ 110Ω (E24) Neutral
Input Voltage Signal Correction Interface
̶ A digital Arduino input pin reads a logic 1 SN74HC14: Hex Schmitt Trigger Inverter
when the input voltage is above 3 V and 2V < Vcc < 6V and 0V < Vin < Vcc,
reads a logic 0 when the input voltage is but Vout = 0V or Vout = Vcc
below 1.5 V. +9V +5V
Or
̶ When the input voltage is just above 3 V or Vin 5V
just below 2.2 V, a Schmitt-trigger inverter
SN74HC14 Arduino
can be used to correct the input voltage to
corresponding 5 V (high) and 0 V (low). Any CMOS Digital pin
Compatible
̶ Also, if the input voltage is changing slowly Input Voltage GND
the Schmitt trigger will ensure that input
voltage transitions will be fast.
̶ This is because the propagation delay of a
SN74HC14 hex Schmitt-trigger inverter is
only 11 ns and the maximum output rise
and fall time is only 7 ns.
̶ These hex Schmitt-trigger inverter devices
contain six independent inverters, which
perform the Boolean logic function of:
Output = NOT(Input).
High Input Voltage Interfacing Using a Voltage Divider
̶ If the output voltage of a sensor is higher 1N4625: Silicon Zener Diode
than the supply voltage of the Arduino, VZ = 5.1V @ IZT = 250uA, IZmax = 55mA, Pd = 250mW
voltage dividing resisters can be used to +24V
interface the sensor to the Arduino. Sensor +9V +5V
Input R1
̶ A voltage divider provides the appropriate Or
18K
Vin 5V
voltage level into the Arduino configured
digital input pin. Digital pin

̶ The silicon Zener diode is used to clamp R2


5V1
Arduino
4K7
any input voltage spike (above 5.1V) that 1N4625 GND
may be electro-magnetically coupled in, if
long wires to the sensor is used.
Let R2 = 4K7 & VR2 = 5V, But VR2 = 24V x R2/(R1 + R2)
̶ However, the high voltage sensor ground Therefore: R1 = ((24V x R2)/VR2) - R2
must be shared with the Arduino digital R1 = ((24V x 4K7)/5V) – 4K7 = 17860 ≈ 18K (E24)
ground. Therefore: VR2 = 24V x 4k7/(18K + 4k7) = 4.97V
IR1 = (24V – 4.97V)/18K = 1mA, which is > IZT = 250uA
Optically-Isolated High Input Voltage Interface
̶ If transient kilo-volt isolation between a 4N25: VISO = 5000Vrms, Ifmax = 60mA, Vf = 1.3V and
high input voltage sensor and an Arduino CTRDC = 50%, VCEmax = 30V, ICmax = 50mA and
digital input pin is required, a opto-coupler VCEsat = 0.5V
or opto-isolator can be used. 5V
+24V
̶ A typical opto-coupler device such as the Sensor R1 R2
4N25, has a 5 KV isolation between the Input 1K2 10K +9V +5V
4N25 Or
input and output circuits. 1 6 Vin 5V
̶ The kilo-volt electrical isolation rating is Arduino
2 5
achieved because the coupling between Digital pin
input and output circuits is a light beam. 3 4
Sensor NC
GND
̶ Therefore, input sensor coupled transient GND
voltages less than 5 KV will not damage
R1 = (24V-Vf)/If >> let If = 20mA
the output circuit connected to the R1 = (24V-1.3V)/20mA = 1135Ω ≈ 1K2 (E24)
Arduino input pin. IC = (If x CTRDC) = (20mA x 50%) = 10mA
And R2 > (5V-VCEsat)/IC = (5V-0.5V)/10mA = 450Ω
Optically-Isolated 5 V to 30 V Input Voltage Interface
̶ This circuit allows any voltage 4N25: VISO = 5000Vrms, Ifmax = 60mA, Vf = 1.3V and CTRDC = 50%,
input between 5 V to 30 V to VCEmax = 70V, ICmax = 50mA and VCEsat = 0.5V
provide an optically isolated BC107: with IC ≥ 10mA, VBE= 0.7V, VCEsat = 0.25V and hfe=110,
VCEmax = 45V, ICmax = 100mA and Pd = 300mW
5 V digital input to the 1N4007: Ifmax = 1A, VRmax = 1000V 5V
Arduino microcontroller.
R3
̶ The transistor Q1 is used to +9V +5V
R1 10KΩ
4N25 Or
limit current to opto-coupler 750Ω
1 6 Vin 5V
LED, when the input voltage +
Arduino
Q1
is greater the 5 V. 5V-30V
BC107
2 5
Digital pin
Input Q2
̶ If the applied input voltage is 1N4007 R2 3
NC
4
reversed, 1N4007 diode will 150Ω GND
conduct to prevent damage -
to the opto-coupler LED. ICQ2 ≥ 4 x (5V/10K) = 2mA and ICQ2 = 50% x If, So: If = ICQ2/50% = 4mA
At 5V input: VR2 = VBEQ1 = 0.6V. So: R2 = 0.6V/4mA = 150Ω (E24)
And R1 = (5V-1.3V-0.6V)/4mA = 775Ω ≈ 750Ω (E24)
Now at 30V input: IR1 = (30V-1.3V-0.6V)/750Ω = 37.47mA
PR1 = (IR12 x R1) = (37.47mA)2 x 750Ω = 1.05W ≈ 2W
And at 30V: PQ1 = VCEsat x ICQ1, where ICQ1 = (37.47mA – 4mA) = 33.47mA
Therefore : PQ1 = (0.25V x 33.47mA) = 8.4mW
Switch, Push-button and Keypad Input Interfacing
̶ A user input interface can be provide by a
switch, push-button or keypad (which is just an Reads Multiple
+5V +9V +5V
array of switches) connected to Arduino digital switch transistions
Or
input pins. Vin 5V
10K
̶ Switches come in many different sizes, but all
Arduino
switches are interface in the same way.
̶ For a pull-up input interface, when the switch is Digital pin
closed or the push-button is pressed, the Pull-up input
Arduino digital input pin goes low. GND

̶ For a pull-down input interface, when the


switch is closed or the push-button is pressed,
the Arduino digital input pin goes high. Reads Multiple
̶ When a switch is closed its mechanical +5V switch transistions +9V +5V
contacts tend to bounce for a few milliseconds Or
before settling in the closed position. Vin 5V

̶ This means that the Arduino digital input pin, Arduino


sampled at high speed will read multiple switch Digital pin
transitions and interpret a single switch Pull-down input
activation as multiple switch activations. 10K GND
̶ When the switch or push-button is opened, the
same mechanical contact bounce occurs.
̶ Note, Arduino input pin internal pull-ups can be
used instead of an external pull-up resistor.
Software De-bounce Subroutine
̶ The software that reads the switch digital input pin will
have to avoid the mechanical switch contact bounce. Debounce

̶ The duration of mechanical contact bounce is difficult to is


predict because it depends on the switch’s physical No
input low
construction. ?
̶ However, for smaller tactile switches the mechanical Yes
contact bounce duration is usually less than 10 ms. D10ms
̶ A way to eliminate the mechanical contact bounce effect is
to simply wait for 10 ms and then read the switch input is
No
again, hoping that the switch has finished “bouncing”. input low
̶ For a pull-up input interface, after the “Debounce” ?
function is called, if the returned flag is clear the switch is Yes
pressed else if the flag is set the switch is not pressed. Clear flag
̶ The flowchart for this de-bounce function is straight
forward and works if the correct time delay is chosen. Return
̶ Note that a switch assumes toggle operation mode where
the switch remains in the set position until changed.
̶ Push-buttons remain in the set position only when held Set flag
but toggle operation can be implemented in software to
obtain a push-on or push-off operation. Return
Hardware De-bouncing
̶ For a pull-up input interface, when the
+5V +9V +5V
push-button is pressed the voltage at the 5V logic 1 Or
digital input pin goes low, but then jumps 3V Vin 5V
back up to 5 V due to mechanical contacts 10K
logic 0
bouncing open. Arduino
t<0.1s
̶ However, with a capacitor connected Digital pin
across the push-button, when the contacts Pull-up Input
close the capacitor discharges quickly GND
through the short circuit, but can only 10nf
recharge slowly via the pull-up resistor
when the contacts bounce open.
̶ If the contacts close again before logic-1 T = RC = (10k x 10nf) = 100ms
threshold voltage of 3 V is crossed, the Vcap = 63% of 5V, after one time constant
Arduino digital input pin will be prevented So Vcap = (5V x 0.63) = 3.15V, Therefore
from detecting a logic-1 state.
logic-1 (3V) reached just before a 100ms.
̶ A time constant between 10 ms to 100 ms
(T = RC), will de-bounce the input signal
adequately.
̶ Note that the capacitor needs to be large
enough to give a slow voltage rise during
the charging phase, but not too large as to
cause a high damaging discharge current
through the closed contacts when the
push-button is pressed.
AC Voltage Zero-Cross Detection
̶ A zero-crossing detector is used to Vm = (VRMS x √2) ≈ VRMS x 1.414
generate a synchronized pulse related +Vm
to the AC voltage phase angle, which is
often used in power control circuits.
0V t
̶ Note that the relationship of a zero-
crossing detector pulse to a sine wave,
is shown in the figure on the right. -Vm
̶ The digital 5 V zero-crossing detector
pulse occurs at either 0° or 0 ms, 180° +5V
or 10 ms, and 360° or 20 ms.
0V

Zero crossing pulse at 0, 180 and 360 degrees.


F = 50Hz, T = 1/F = 20ms, Half-cycle = 10ms
Optically-Isolated Zero-Cross Detection Circuit One
̶ The H11AAXM series consists of two H11AA1M: Ifmax = 60mA but @ If ≈ 10mA, Vf = 1.17V, and CTRCE = 20%,
gallium-arsenide infrared emitting VCEmax = 100V, ICmax = 50mA, VCEsat = 0.4V, VISO = 7500Vac(pk)
diodes connected in inverse parallel, 5V
driving a single phototransistor R2
output. 10K +9V +5V
R1
H11AA1M Or
1K 2W
̶ This opto-coupler is used for AC line 1 6 Vin 5V
Arduino
monitoring, unknown polarity DC 230V 2 5
Digital pin
sensor and telephone line interface. AC
3 4
NC
̶ The 230 VAC to 24 VAC transformer Transformer GND
provides electro-magnetic isolation 230V to 24V

from the high AC voltage. IC ≥ 4 x (5V/10K) = 2mA and IC = 20% x If, So: If = IC/20% = 10mA
At 1ms, let If = 10mA
̶ Every time the zero-crossing point is But: V1ms = VmSin2πft, f = 50Hz & Vm = Vrms x √2 = (24Vx√2) = 33.94V
reached, the opto-coupler infrared V1ms = 33.94V x Sin(2π x 50Hz x 1ms) = 10.49V
So: R1 = (V1ms-Vf)/If = (10.49V – 1.17V)/10mA = 932Ω ≈ 1K (E24)
emitting diodes stop conducting. At Vm: If = (Vm-Vf)/R1 = (33.94V-1.17V)/1K = 32.77mA (< Ifmax = 60mA)
PR1 = IR1max2 x R1 = (32.77mA)2 x 1K = 1.07W ≈ 2W
̶ The opto-coupler phototransistor
also stops conducting and the 10 K
pull-up resistor ensures a 5 V pulse
on the Arduino digital input pin,
during the AC voltage zero-crossing.
Optically-Isolated Zero-Cross Detection Circuit Two
̶ A center-tap transformer using 4N25: VISO = 5000Vac(pk), Ifmax = 60mA, Vf = 1.3V and CTRDC = 50%,
two diodes or even a transformer VCEmax = 70V, ICmax = 50mA and VCEsat = 0.5V
using a four diode bridge rectify, 5V
Pulsating DC
can be used to convert AC voltage R2
into pulsating DC voltage. R1
10K +9V +5V
230V 4N25 Or
910Ω 1W
̶ In this way a simpler opto-coupler AC 1 6 Vin 5V
(4N25) can also be used to detect Arduino
2 5
Digital pin
the zero-crossing point instead.
3 4
NC
GND
Transformer
230V to 12VCT
IC ≥ 5 x (5V/10K) = 2.5mA and IC = 50% x If, So: If = IC/50% = 5mA
At 1ms, let If = 5mA
But: V1ms = VmSin2πft, f = 50Hz & Vm = Vrms x √2 = (12Vx√2) = 16.97V
V1ms = 16.97V x Sin(2π x 50Hz x 1ms) = 5.24V
So: R1 = (V1ms-Vf)/If = (5.24V – 1.3V)/5mA = 985Ω ≈ 910Ω (E24)
At Vm: If = (Vm-Vf)/R1 = (16.97V-1.3V)/910Ω = 17.22mA (< Ifmax)
PR1 = IR1max2 x R1 = (17.22mA)2 x 910Ω = 0.27W ≈ 1W
Zero-Cross Detection Circuit Connected To Mains
̶ The H11AAXM opto-coupler can H11AA1M: Ifmax = 60mA, but @ If ≈ 10mA, Vf = 1.17V, CTRCE = 20%,
also be connected directly to mains. VCEmax = 100V, ICmax = 50mA, VCEsat = 0.4V, VISO = 7500Vac(pk)
5V
̶ The limiting resistor cannot be used
on its own, because of the high C1 R2
R1
330nF 270Ω 10K +9V +5V
power dissipation due to the high 230V H11AA1M Or
1W
AC mains voltage. 230V 1 6 Vin 5V
AC Arduino
̶ Instead a capacitor must be used in 5V1 2 5
Digital pin
series, so that the high capacitive Zener
3 4
reactance can limit the current. NC
GND
̶ The capacitor does not dissipate
energy across it but rather absorbs IC ≥ 4 x (5V/10K) = 2mA and IC = 20% x If, So: If = IC/20% = 10mA
and then releases the majority of But: V1ms = VmSin2πft, f = 50Hz & Vm = (230V x √2) = 325.27V
V1ms = 325.27V x Sin(2π x 50Hz x 1ms) = 100.51V
the energy back to the supply. Let XC1 = 1/(2πfC1) = (V1ms-Vf)/If = (100.51V – 1.17V)/10mA = 9934Ω
̶ However, if a voltage spike occurs, So: C1 = 1/(2π x 50Hz x 9934Ω) = 320nf ≈ 330nf (E24) 240V capacitor
XC1 = 1/(2π x 50Hz x 330nf) = 9646Ω, But ZT = (R1 + XC1) = 9934Ω
the capacitor reactance will drop to So: R1 = (9934Ω – 9646Ω) = 288Ω ≈ 270Ω (E24)
zero and the energy will then be At Vm: If = (Vm-Vf)/ZT = (325.27V-1.17V)/(9646Ω + 270Ω) = 32.68mA
dissipated across the resistor during PR1 = IR1max2 x R1 = (32.68mA)2 x 270Ω = 0.288W ≈ 1W
that short time interval.
̶ A back to back 5V1 Zener diode
protects the H11AAXM device by
clamping the voltage spike.
AC Power Control Circuit
̶ A zero-crossing detection circuit H11AA1M: Ifmax = 60mA, @ If ≈ 10mA, Vf = 1.17V, CTRCE = 20%,
together with an optically-isolated VCEsat = 0.4V, VCEmax = 100V, ICmax = 50mA, VISO = 7500Vpk
resistive triac switch, can be used to MOC3022: Ifmax = 60mA, Vfmax = 1.5V and LED trigger current:
10mA ≤ If ≤ 60mA, VISO = 7500V
control AC power to a lamp load. BTA06-600C: IT(RMS) = 6A, VDRM = 600V, IGT = 25mA, VGT = 1.3V
̶ The voltage value adjusted by the 5V
potentiometer connected to A0 pin, C1 R1
R2
is used to set the triac firing delay. 330nF 270Ω
10K +9V +5V
230V H11AA1M Or
1W
̶ After a zero-crossing pulse on pin D2 1 6 Vin 5V
is detected, the interrupt service Arduino
5V1 2 5
routine is entered. Zener
D2 input
3 4
̶ The potentiometer value is read to NC
determine the new triac firing delay.
230V 5V
A0 input
̶ After this delay, the triac is pulse for AC 230V, 60W
Lamp Load
a short period to switch power to 10k
the lamp load for the rest of the AC R4 MOC3022 R3
180Ω 6 1 330Ω
mains half cycle. D5 Output
A2
̶ Note: the longer triac firing delay is BTA06
5 2
GND
(between 200us and 9407us) the 600C
G 4 3
less power will be delivered to the A1 NC
lamp load.
AC Power Control Code Example
/* detects zero crossing pulse on (INT0) digital pin 2 and after a set
potentiometer delay, pulses the triac to switch power to the load */

#define pinZC 2 // zero cross detection input digital pin


#define pinTP 5 // triac pulse control output digital pin

void setup()
{
pinMode(pinZC, INPUT);
pinMode(pinTP, OUTPUT);
attachInterrupt(0, CtrlAC, FALLING); // enable interrupt
}

void loop(){
}

// Interrupt routine, delay() will not work, only delayMicroseconds()!


void CtrlAC ()
{
// (1023*9)+200=9407us -> Control from 200us to 9407us (within 10ms)
delayMicroseconds((analogRead(A0) * 9) + 200); // read A0
digitalWrite(pinTP, HIGH);
delayMicroseconds(50); // 50us output pulse to turn on triac
digitalWrite(pinTP, LOW);
}
EXERCISE
1. Illustrate using a sketch the difference between “sink” and “source” relating to a
microcontroller output interfacing.
2. Sketch a basic NPN transistor “sink’ switch connected to an Arduino digital output pin that
can deliver 150 mA at 12VDC to a given lamp load. Calculate the base resistor for a
P2N2222A transistor and its power dissipation if: VCEmax = 40 V, ICmax = 600 mA,
Pdmax = 625 mW, VBE = 0.6 V, VCEsat = 0.3 V and hfe = 100.
3. State the Arduino UNO microcontroller’s maximum current output pin limitation and
discuss what is the recommended current limit for each digital output pin?
4. Sketch without component values, both a NPN and PNP power Darlington transistor
switch circuit connected to an Arduino digital output pin, that is used to control a DC
motor load. Explain why a freewheeling diode is require.
5. Sketch without component values, a high power Darlington transistor H-Bridge motor
control circuit. Describe how the Arduino digital output pins can control the DC motor
speed in the forward and reverse directions.
6. Explain how shoot through currents and DC motor inductive back EMF spikes can be
avoided in a high power Darlington transistor H-Bridge DC motor control circuit?
7. Sketch a basic N-channel MOSFET “sink’ switch connected to an Arduino digital output
pin, that can deliver 5 A at 12 VDC to a given lamp load. Use a IRF630 and determine its
power dissipation if: VDSmax = 200 V, IDmax = 9 A, VGSmax = ±20 V, VGS(th) = 4 V and
RDS(on) = 0.4 Ω. Diccuss why a resistor of a certain value should be connected between
the gate and source terminals.
EXERCISE
8. Sketch without component values, a basic P-channel MOSFET switch for both a 12 VDC
and a 24 VDC supply that sources a lamp load. Explain why a Zener diode is require for the
24Vdc supply and state what this circuit configuration is often called?
9. Sketch without component values, a power MOSFET H-Bridge motor control circuit.
Describe how the Arduino digital output pins can control the DC motor speed in the
forward and reverse directions.
10. Create an Arduino C program without comments, to bi-directionally control a permanent
magnet DC motor via an H-bridge control interface circuit. The left H-Bridge leg has pin D7
connected to the high-side switch and PWM pin D5 is connected to the low side switch.
The right H-Bridge leg has pin D8 connected to the high-side switch and PWM pin D6 is
connected to the low side switch. The Arduino C program must continually drive the DC
motor in one rotational direction for two seconds at one third of the maximum possible
speed and then in the opposite rotational direction for four seconds at one fifth of the
maximum possible speed. When changing direction make sure to wait for at least 20
microseconds in float mode to avoid high damaging shoot-through H-bridge currents.
11. Discuss advantage of using opto-couplers for microcontroller input/output interfacing?
12. Sketch an optically-isolated NPN Darlington transistor switch connected to an Arduino
digital output pin that drives a DC motor load of 2.5 A at 12 VDC. Calculate the required
limiting resistor values if a 4N25 opto-coupler (VCEsat = 0.5 V, Vf = 1.3 V, CTR = 50 %) and
a TIP120 NPN Darlington transistor (VBE = 2.5 V, hfe = 1000) is used.
13. Sketch an optically-isolated PNP Darlington transistor switch connected to an Arduino
digital output pin that drive a DC motor load of 4 A at 12 VDC. Calculate the required
limiting resistor values if a 4N25 opto-coupler (VCEsat = 0.5 V, Vf = 1.3 V, CTR = 50 %) and
a TIP125 PNP Darlington transistor (VBE = 2.5 V, hfe = 1000) is used.
EXERCISE
14. Sketch without component values, both an optically-isolated N-channel and P-channel
MOSFET switch circuit connected to an Arduino digital output pin, that is used to control a
lamp load.
15. Sketch an optically-isolated resistive triac switch connected to an Arduino digital output
pin, which is used to control a 230 VAC lamp load. Calculate the required LED limiting
resistor for a MOC3022 optically-isolated triac driver with If = 10 mA and Vf = 1.5 V that is
used to drive a BTA06-600C non-sensitive gate power triac circuit.
16. Sketch an optically-isolated inductive sensitive triac switch connected to an Arduino digital
output pin, which is used to control a 220 VAC magnetic contactor load. Calculate the
required LED limiting resistor for a MOC3021 optically-isolated triac driver with If = 15 mA
and Vf = 1.5 V that is used to drive a BTA06-600SW sensitive gate power triac circuit.
17. Identify and state five optically isolated triac device drive applications.
18. Sketch an optically-isolated inductive non-sensitive triac switch connected to an Arduino
digital output pin, used to control a 230 VAC magnetic contactor load. Calculate the
required LED limiting resistor for a MOC3023 optically-isolated triac driver with If = 5 mA
and Vf = 1.5 V that is used to drive a BTA06-600B non-sensitive gate power triac circuit.
19. Sketch an optically-isolated triac live side switch connected to an Arduino digital output
pin, which is used to control a 240 VAC load. Calculate the required LED limiting resistor
for a MOC3020 optically-isolated triac driver with If = 30 mA and Vf = 1.5 V that is used to
drive a power triac circuit. Discuss which components are used for snubbing the triac and
opto-coupler?
20. Sketch an input voltage signal correction interface circuit, connected to an Arduino digital
input pin. Explain when it is required and how it improves a slow changing input voltage.
EXERCISE
21. Sketch a high input voltage interface using a voltage divider connected to an Arduino
digital input pin for a 12 VDC output sensor and calculate the required resistor values.
Include a 5V1 Zener diode in the sketch and explain why it may be required.
22. Sketch an optically-isolated high input voltage interface circuit connected to an Arduino
digital input pin for a 12 VDC output sensor. Calculate the required resistor values if a
4N25 device is used with If = 20 mA, Vf = 1.3 V, VCEsat = 0.5 V and CTRDC = 50 %. Discuss
how the kilo-volt isolation is achieved?
23. Sketch without calculating component values, an optically-isolated 5 to 30 VDC input
voltage interface circuit connected to an Arduino digital input pin. Discuss how a wide
voltage input range and reverse voltage protection is achieved?
24. Describe and illustrate using a sketch, the difference between a pull-up and pull-down
input push-button including the disadvantage of using this type of interfacing?
25. Explain and illustrate using a flowchart, how a simple software de-bounce routine can be
used to avoid mechanical contact bounce for a small tactile switch pull-up input interface.
26. Design an Arduino C program without comments, to software de-bounce a normally open
tactile pushbutton switch connected to input pin 2, without an external pull-up resistor.
The high and low transition of the pushbutton input circuit must be de-bounced and its
known state must control the state of the LED connected to pin 13 on the Arduino UNO.
27. Explain and illustrate using a sketch with component values, how a hardware de-bounced
pull-up pushbutton input interface can be used to avoid mechanical contact bounce.
EXERCISE
28. Sketch without calculating component values, an optically-isolated zero-cross detection
circuit using a H11AA1M device connected to an Arduino digital input pin. A 230 VAC to
24 VAC transformer must be used to provide electro-magnetic isolation from the high AC
voltage. Describe how this circuit detects the AC voltage zero-crossing points?
29. Sketch without calculating component values, an optically-isolated zero-cross detection
circuit using a 4N25 device connected to an Arduino digital input pin. To provide electro-
magnetic isolation from the high AC voltage a 230 to 12 VAC center-tap transformer is
used.
30. Sketch without calculating component values, a zero-cross detection circuit connected
directly to 230 VAC mains using a H11AA1M device. Explain why an input resistor and
capacitor including a back to back 5V1 Zener diode must be used.
31. Sketch without calculating component values, a H11AA1M device zero-cross detection
circuit with an optically-isolated resistive triac MOC3022 device switch that is used to
control a 230 VAC, 60W lamp load. A 10k potentiometer connected to pin A0 must be
used to set the triac firing delay time. The zero-crossing pulse must be detected on pin D2
and pin D5 must be used to turn the triac on.
32. Create an Arduino C program to detect a zero-crossing pulse on digital interrupt pin 2.
After an adjustable 200 us to 9407 us delay that must be set by a 10k potentiometer
connected to pin A0, fire an optically-isolated resistive triac switch connected to pin 5 in
order to control the power delivered to an AC lamp load.

You might also like