Download An Introduction to Electronics for Advanced High School Students

Document related concepts

Superconductivity wikipedia , lookup

Electrical resistance and conductance wikipedia , lookup

Electromagnet wikipedia , lookup

Metadyne wikipedia , lookup

Transcript
An Introduction to Electronics for
Advanced High School Students
Shyam Modi, ‘14
Submitted to the
Department of Mechanical and Aerospace Engineering
Princeton University
in partial fulfillment of the requirements of
Undergraduate Independent Work.
Final Report
May 1, 2014
Michael Littman
Daniel Steingart
MAE 442D
70 pages
File Copy
c Copyright by Shyam Modi, 2014.
All Rights Reserved
This thesis represents my own work in accordance with University regulations.
Abstract
The objective of this thesis was to design and teach a short introductory course
on electronics to advanced high school students. While many high school science
classes have well-developed hands-on exercises to complement theory from lecture,
high school physics classes often lack a significant hands-on component. This thesis
was designed to help remedy that problem. To that end, six lectures were developed
with accompanying lab exercises. The topics covered in the lectures included diodes,
transistors, logic gates, flip flops, the Hall Effect, relays, switches, and the Arduino.
Each lesson was structured to have approximately twenty minutes of lecture, followed by twenty-five minutes of lab work. The lectures were designed to align with
the topics covered in the AP Physics curriculum. The labs were sequenced with
increasing complexity, such that each week’s lab built on the lab exercises from the
previous weeks while introducing one or two new components.
I arranged to teach my course to the two AP Physics classes at Princeton High
School. At the time of thesis submission, I have taught five out of the six lessons. I
have thoroughly enjoyed the experience, and based on the fact that many students
continue to work on their circuits long after class is over, it seems that they are
enjoying the work as well. After I teach the last lesson, the students will work in
small groups to complete a two week-long design project which will put together
the topics they have learned. The design project is derived from the MAE412 final
project; students will use the Arduino in conjunction with the electronic components
they have learned about to sense, actuate, and sequence a model train set. Through
this project, students will learn not just about electronics but also how to write clear
project proposals and how to work effectively as a team.
iii
Acknowledgements
I am grateful to Professor Littman for his guidance throughout the year, and for
supporting me in pursuing an unusual type of thesis. I am also indebeted to Jon
Prevost, who spent many hours helping me in the lab and helped me proofread this
report. Additionally, my work would not have been possible without the behind-thescenes work of Jo Ann Love, who made purchasing materials incredibly seamless.
Thanks also to Professor Steingart for serving as the second reader for my thesis.
I’d also like to thank Mr. Mark Higgins, the AP Physics teacher at Princeton High
School, for giving me the opportunity to guest teach in his class. Thanks also to Dr.
Cherry Sprague, the science supervisor at Princeton Public Schools, for accommodating my thesis into the AP Physics schedule.
Additionally, I’d like to thank the Department of Mechanical and Aerospace Engineering and the School of Engineering and Applied Sciences for generously funding
my thesis.
In addition, thank you to Christian Fong, my roommate and friend, for taking time
out of his busy schedule to take pictures of me teaching.
Finally, I’d like to thank my family: my parents, Raksha and Yogesh, and my brother,
Vrajesh, for their support and motivation.
iv
Contents
Abstract . . . . . .
Acknowledgements
List of Figures . . .
List of Symbols . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Introduction
1
1 Diodes and Transistors
1.1 Introduction to the course . . . . . . . . . . .
1.2 Diodes as “one way wires” . . . . . . . . . . .
1.3 What is physically happening in a diode? . . .
1.4 The Transistor as a switch and as an amplifier
1.5 Lab exercise . . . . . . . . . . . . . . . . . . .
2 Logic Gates and Flip Flops
2.1 Motivation . . . . . . . . .
2.2 Logic gates . . . . . . . .
2.3 Flip-flops . . . . . . . . .
2.4 Making logic gates . . . .
2.5 Lab exercise . . . . . . . .
iii
iv
vii
x
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
4
6
8
11
.
.
.
.
.
13
13
14
16
17
19
3 Magnetic Proximity Sensors
21
3.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2 Discussion of E.H. Hall’s paper . . . . . . . . . . . . . . . . . . . . . 22
v
3.3
3.4
3.5
The Hall Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Hall Effect sensors and flip-flops . . . . . . . . . . . . . . . . . . . . .
Lab exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Solenoids and Relays
4.1 Motivation . . . . .
4.2 The solenoid . . . .
4.3 Inside the relay . .
4.4 Lab exercise . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
23
24
25
27
27
27
29
31
5 Throwing a Switch
33
5.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2 The trickle charge circuit . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.3 Lab exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6 The
6.1
6.2
6.3
6.4
6.5
6.6
Arduino
Motivation . . . . . . . . .
The Arduino Nano . . . .
Programming the Arduino
Example program . . . . .
Other useful functions . .
Lab exercise . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
39
39
40
41
41
42
45
7 Final Design Project
48
Conclusions
51
A Trickle Charge Circuit Simulation
58
B Solution Code for Lab 6
60
vi
List of Figures
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10
1.11
Simple circuit with resistor; current flow in CCW direction . . . . . .
Simple circuit with resistor; current flow in CW direction . . . . . . .
IV plot of a simple circuit with a voltage source and resistor . . . . .
Simple circuit with resistor and diode; current flow in CCW direction
Simple circuit with resistor and diode; no current flow . . . . . . . . .
IV plot of a diode . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PN junction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Forward-biased PN junction . . . . . . . . . . . . . . . . . . . . . . .
Reverse-biased PN junction . . . . . . . . . . . . . . . . . . . . . . .
An NPN transistor . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Detailed diagram showing the inner workings of a bipolar junction
transistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.12 Pinout diagrams for 2N3904 and LM7805. The LM7805 takes +9V
unregulated as an input and outputs +5V. It is already set up on your
breadboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
2.1
2.2
2.3
2.4
2.5
2.6
2.7
14
14
14
15
15
15
15
NOT gate and corresponding truth table . . . . .
AND gate and corresponding truth table . . . . .
OR gate and corresponding truth table . . . . . .
A NAND gate combines the NOT and AND gates
A NOT gate combines the NOT and OR gates . .
A XOR gate: (A OR B) AND (NOT (A AND B))
A XNOR gate combines the NOT and XOR gates
vii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
4
5
5
5
6
7
7
8
8
9
2.8 Truth Table for S̄R̄ latch . . . . . . . . . . . . . . . . . . . . . . . . .
2.9 OR and AND gates can be constructed using diodes and resistors . .
2.10 Pinout diagram for 74LS76 . . . . . . . . . . . . . . . . . . . . . . . .
3.1
3.2
4.1
4.2
4.3
4.4
4.5
4.6
5.1
The Hall Effect is observed when a magnetic field is applied perpendicular to a conducting plate . . . . . . . . . . . . . . . . . . . . . . .
Pinout diagrams for A1104 and 74LS76 . . . . . . . . . . . . . . . . .
A picture of a solenoid . . . . . . . . . . . . . . . . . . . . . . . . . .
Ampere’s Law can be used to find the magnetic field of a solenoid . .
An current-bearing solenoid and a bar magnet have the same magnetic
field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The internal structure of a SPDT (single pole double throw) relay . .
Ferromagnetic materials become magnetized in the direction of the
externally applied magnetic field . . . . . . . . . . . . . . . . . . . . .
Pinout diagrams for 74LS244 and 2N3906 . . . . . . . . . . . . . . .
16
18
19
23
25
28
28
29
29
30
31
5.3
A latching relay can be constructed using two coils and an armature
in between . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Screenshot from DC trickle charge circuit simulation. Adapted from
AC trickle charge circuit simulation on MAE412 website . . . . . . .
Pinout diagrams for 74LS244, TIP122, and 2N3906 . . . . . . . . . .
6.1
6.2
A top view of the Arduino Nano . . . . . . . . . . . . . . . . . . . . .
Pinout diagrams for 74LS244, 2N3906, and 74LS76 . . . . . . . . . .
40
46
7.1
A diagram of the design project setup. The ends of the loop will be
provided. Two teams will share space on each project board. . . . . .
48
5.2
viii
35
36
37
List of Symbols
V
I
R
Ic
Ib
β
E
B
C
A
B
Q
S̄
R̄
Q
Q̄
Z
Vcc
GND
P RE
CLR
Q
F
Voltage . . . . . . . . . . . . . . . . . . . . . . . .
Current . . . . . . . . . . . . . . . . . . . . . . . .
Resistance . . . . . . . . . . . . . . . . . . . . . .
Collector current . . . . . . . . . . . . . . . . . . .
Emitter current . . . . . . . . . . . . . . . . . . .
Current gain . . . . . . . . . . . . . . . . . . . . .
Emitter . . . . . . . . . . . . . . . . . . . . . . . .
Base . . . . . . . . . . . . . . . . . . . . . . . . . .
Collector . . . . . . . . . . . . . . . . . . . . . . .
Input 1 to logic gate . . . . . . . . . . . . . . . . .
Input 2 to logic gate . . . . . . . . . . . . . . . . .
Output from logic gate . . . . . . . . . . . . . . .
SET input to S̄R̄ latch . . . . . . . . . . . . . . . .
RESET input to S̄R̄ latch . . . . . . . . . . . . . .
Output of S̄R̄ latch . . . . . . . . . . . . . . . . .
Inverse of output of S̄R̄ latch . . . . . . . . . . . .
Output of logic gate . . . . . . . . . . . . . . . . .
Voltage common collector, in practice +5V for this
Ground . . . . . . . . . . . . . . . . . . . . . . . .
SET pin on 74LS76 . . . . . . . . . . . . . . . . .
RESET pin on 74LS76 . . . . . . . . . . . . . . .
Output pin on 74LS76 . . . . . . . . . . . . . . . .
Lorentz Force . . . . . . . . . . . . . . . . . . . . .
ix
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
project
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
4
4
10
10
10
11
11
11
14
14
14
16
16
16
16
18
19
19
19
19
19
23
q
E
v
B
I/O
dl
µ0
Ienc
L
I
n
N
S
COM
NC
NO
Charge of particle . . . . . . . . . . .
Electric field vector . . . . . . . . . .
Velocity of particle . . . . . . . . . . .
Magnetic field vector . . . . . . . . .
Input/Output . . . . . . . . . . . . .
Infinitesimal path length vector . . . .
Permeability of free space . . . . . . .
Current enclosed by Amperian loop .
Length of Amperian loop along axis of
Current in solenoid . . . . . . . . . .
Number of coils per meter . . . . . . .
North pole of magnet . . . . . . . . .
South pole of magnet . . . . . . . . .
Common . . . . . . . . . . . . . . . .
Normally closed . . . . . . . . . . . .
Normally open . . . . . . . . . . . . .
x
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
solenoid
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
23
23
23
23
27
28
28
28
28
28
28
28
28
29
29
29
Introduction
Between 2010 and 2020, the number of STEM (Science, Technology, Engineering,
and Mathematics) jobs is projected to increase at a rapid pace. For instance, while
the projected increases of occupations on the whole is 14%, computer systems analyst
jobs are projected to increase by 22%, and biomedical engineering jobs are projected
to increase by 62% [24]. Simultaneously, interest in STEM careers among high school
students is quite low: “Only 16 percent of American high school seniors are proficient
in mathematics and interested in a STEM career. Even among those who do go on
to pursue a college major in the STEM fields, only about half choose to work in a
related career” [24]. In addition, it is clear that the interests of high school students
are highly malleable; of those high school seniors that are interested in STEM, 53.3%
became interested after their freshman year. [35]
Recognizing the disparity between projected STEM jobs and interest in STEM
among American students, “educators everywhere are struggling with how to improve
STEM literacy and how to encourage more students to pursue college and careers
in STEM fields” [14]. One approach has been to create specialized STEM schools.
These schools “typically offer more rigorous curricula, more qualified teachers, more
instructional time, and more resources than traditional high schools” [14]. The results of these schools, particularly those which are selective, have been very positive:
“Their graduates pursue STEM fields in college at a rate nearly 50% higher than
that of other students” [14]. Studies identify “challenging curricula, expert instruction, and peer stimulation” as key factors which influence whether or not talented
high schoolers will study STEM subjects in college [14]. Given the success of special-
1
ized STEM schools, it could make sense to replicate aspects of their programs into
non-specialized schools. Some recommendations include “grounding STEM education in ‘real-life’ practical problems” and “student participation in original research
projects” [14].
This thesis was designed with these recommendations in mind. The objective
of this thesis was to expose high school physics students to the fun and interesting
applications of the theory they were learning in class. In order to do this, I designed
lectures and labs for an short introductory course in electronics. I aimed to integrate
topics from the students’ physics curriculum into the lessons I taught. For instance,
when discussing Hall sensors, I discussed the physics behind the Hall Effect, which
was a straightforward application of the Lorentz force, which the students had studied
in class. Similarly, when discussing the relay, I derived the magnetic field of the coil
using Ampere’s Law, which was part of the physics curriculum. The purpose of
integrating the physics curriculum into my lectures was to demonstrate that the
material the students were learning in class had real-life applicability.
In addition, to give the students an opportunity to engage in an original project,
I decided to have the mini-course culminate in a design project which combines the
various electronic components discussed in the lessons. The purpose of this project
was to give students a flavor of what engineering projects are all about: proper
planning, good design, and teamwork, among other things. It was my hope that
my thesis project would give some students the confidence and inspiration to study
science or engineering in college.
2
Chapter 1
Diodes and Transistors
1.1
Introduction to the course
• I’m Shyam, a senior MAE at Princeton. I took a course last year, MAE412,
which I enjoyed. I realized that with some modifications, it was accessible to
advanced high school students. I decided to make this my thesis.
• Over the next two months, we will cover the following topics, while emphasizing
both the physics behind the components as well as the applications
– Diodes
– Transistors
– Flip Flops
– Magnetic Proximity Sensors
– Relays
– Switches
– Arduino
• After learning about this topics, the course will culminate in a design project
after the AP exam. The design project will require you to put all these pieces
3
together. (Show video of my MAE412 project: https://www.dropbox.com/
s/k770zets0o0kugt/CIMG8276.MOV)
1.2
Diodes as “one way wires”
• Definition: A semiconductor device with two terminals, typically allowing the
flow of current in one direction only [9]
• Let’s compare a diode to a wire. Consider the circuit below:
Figure 1.1: Simple circuit with resistor; current flow in CCW direction
What is the magnitude and direction of current in this circuit? Recall that by
convention, current flows from positive to negative. So the direction of current
will be counter-clockwise. To find the magnitude, use Ohm’s Law:
V = IR
In our case, V = 10V and R = 50Ω, so I = 0.2A.
What if we switched the direction of the battery?
Figure 1.2: Simple circuit with resistor; current flow in CW direction
4
(1.2.1)
Then I = 0.2A in the clockwise direction.
For a simple circuit with only a resistor, the plot of voltage versus current looks
like this:
[10]
Figure 1.3: IV plot of a simple circuit with a voltage source and resistor
• Now, consider the original circuit with a diode put in:
Figure 1.4: Simple circuit with resistor and diode; current flow in CCW direction
What is the current? The diode is facing in the direction of current flow, so
it behaves (almost) like a wire. The diodes we will be using have a forward
voltage drop of about 0.7V [18], so the voltage across the resistor is 9.3V . Since
R = 50Ω, I = 9.3V /50Ω = 0.186A, which is close to the current of 0.2A we
had before.
What if we put the diode in the opposite direction?
Figure 1.5: Simple circuit with resistor and diode; no current flow
5
Diodes only allow the flow of current in one direction. In this case, the diode is
facing opposite to the direction that current would flow, so the diode prevents
the flow of current in the circuit.
This is an idealization, however. If a diode is reverse-biased with a sufficiently
high voltage (called the breakdown voltage), then it will allow current to flow
through it. [37] This will usually destroy the diode due to the high amount
of heat dissipated. For the diodes we will be using (1N4001), the breakdown
voltage is about 50V . [18]
So what does the I-V plot look like for a diode, keeping in mind the forward
voltage drop and the breakdown voltage?
[4]
Figure 1.6: IV plot of a diode
1.3
What is physically happening in a diode?
• Earlier, we defined a diode as “A semiconductor device with two terminals.”
What is a semiconductor? A semiconductor is “a material with a varying
ability to conduct electrical current.” [12]
• Take a substance like silicon or germanium. These substances are not good
conductors in their pure form. However, through a process called doping, the
6
balance of charge can be altered. Silicon has four valence electrons, so if we
dope with phosphorus or arsenic (which have five valence electrons), then the
overall charge is negative, and we call this a N-type impurity. Similarly, if we
dope silicon with boron or gallium (which have three valence electrons), we
have an absence of electrons and the overall charge is positive. This is called a
P-type impurity. [3]
• Put a P-type material and an N-type material next to each other. What
happens?
Figure 1.7: PN junction
Close to the P-N junction, the electrons from the N-type material fill the holes
in the P-type material. This leads to an insulating section in the middle of the
diode, called the depletion zone. [3]
• If we connect a voltage source across the diode, what happens?
Figure 1.8: Forward-biased PN junction
7
The flow of current coming out of the positive side of the battery pushes the
holes in the diode across the P-N junction, and the diode allows the current to
flow through it. [3] The effort associated with pushing the holes across the P-N
junction is what accounts for the forward-biased voltage drop across a diode.
• What if we orient the battery in the opposite direction?
Figure 1.9: Reverse-biased PN junction
In this case, the depletion zone gets even larger, and current does not flow.
1.4
The Transistor as a switch and as an amplifier
• What happens when you “sandwich” two diodes together?
Figure 1.10: An NPN transistor
It might seem that no current could flow through this, since it looks like two
diodes pointing in opposite directions.
8
However, there is a way to allow current to flow through this structure (called
a transistor). If we apply a positive voltage difference across the base (P) and
emitter (one of the Ns), some current will flow from the base to the emitter, like
in a diode. When holes are introduced to the base, electrons from the emitter
are strongly attracted towards it. Some of those electrons will indeed combine
with the holes. In practice, the emitter is very heavily doped, and the base
layer is very thin. Not all of the electrons which have crossed into the base will
combine with holes. The collector is designed with a thin, high resistivity layer
close to the base/collector junction (and low resistivity elsewhere), so there is
a strong potential gradient which pushes the electrons towards the collector
terminal. Therefore, electrons are able to pass from one end of the transistor
to the other. [5]
[5]
Figure 1.11: Detailed diagram showing the inner workings of a bipolar junction transistor
9
The reason that a transistor can be thought of as a switch is because we can
turn on the current from the collector to the emitter by turning the base current
on and off. It is more accurate to think of the transistor as a dimmer rather
than a switch, because the greater the base current, Ib , the greater the collector
current, Ic (this is true to an extent; transistors have maximum ratings for Ic ;
the maximum Ic for the 2N3904 is 200mA) [31]. The relationship between Ib
and Ic is given by
Ic = βIb
(1.4.1)
where β is the gain of the transistor.
10
1.5
Lab exercise
In this lab, students will learn about diodes and transistors, by varying the direction
that diodes face in the circuit (to see their use as “one way wires”) and by varying the
base current to the transistor (to see how the transistor can be used an an amplifier).
Instructions:
1. Assemble the circuit shown in the diagram (N.b. in the diagram, the terminal
of the transistor with an arrow is the emitter)
2. Vary the value of R1 from 250Ω to 4.7kΩ and then to 75kΩ.
Notice that the brightness of D2 decreases as you increase the resistance. Notice
also that when R1 is increased to 4.7kΩ, the brightness of D1 remains the same,
but when R1 is increased to 75kΩ, the brightness of D1 decreases. That is
because when R1 is 75kΩ, the transistor is not fully turned on, so the collector
current is limited to only about 11mA:
Ic = βIb
(1.5.1)
Ib = 0.067mA; β is approximately 160 at this current [6]; Ic = 11 mA.
3. Make R1 250Ω again. Change the orientation of D2 to the opposite direction.
Note that current no longer flows through the diode (demonstrated by the fact
that D1 is also off). This shows the “one-way wire” nature of a diode.
[31] [33]
Figure 1.12: Pinout diagrams for 2N3904 and LM7805. The LM7805 takes +9V unregulated as an input and outputs +5V. It is already set up on your breadboard.
11
2
4
LED
3
D1
LED
Q1
2N3904
Title
Lab 1 - Diodes and Transistors
Sheet
1
1
of
1
Re v
C
Date:
Size
A
2
Saturday, March 22, 2014
Document Number
A
250, 4.7k, 75k
D2
R2
250
D
A
+5V
R1
+5V
1
B
5
3
Lab 1 - Diodes and Transistors
4
B
C
D
5
Chapter 2
Logic Gates and Flip Flops
2.1
Motivation
• In the model trains projects, we will want to store information. In particular,
we will want to know when a train is on a certain portion of the track.
• To control the trains, we will be using a microcontroller (a small computer)
called an Arduino, which has on-board memory. This would be one way to
store information.
• However, we want to understand how memory works. Fundamentally, memory
in computers consists of millions of flip-flops, which are capable of having two
stable states (0 and 1). Rather than using the on-board Arduino memory, we
will use external flip-flops (74LS76) to store train locations.
• Before discussion what flip-flops are and how they are made, we need to have
a solid understanding of logic gates, which are the one of the building blocks
of electronics. We will then combine logic gates to create a flip-flop circuit.
13
2.2
Logic gates
• There are three main types of logic gates which we need to know about: NOT,
AND, and OR. Each of these performs a different boolean function.
• Each logic gate has an associated truth table, which tells us how different
combinations of inputs correspond to the output.
A Q
[16]
1
0
0
1
Figure 2.1 & Table 2.1: NOT gate and corresponding truth table
[16]
A
B
Q
0
0
0
0
1
0
1
0
0
1
1
1
Figure 2.2 & Table 2.2: AND gate and corresponding truth table
[16]
A
B
Q
0
0
0
0
1
1
1
0
1
1
1
1
Figure 2.3 & Table 2.3: OR gate and corresponding truth table
14
• We can combine these three logic gates to create other logic gates:
[16]
Figure 2.4: A NAND gate combines the NOT and AND gates
[16]
Figure 2.5: A NOT gate combines the NOT and OR gates
[16]
Figure 2.6: A XOR gate: (A OR B) AND (NOT (A AND B))
[16]
Figure 2.7: A XNOR gate combines the NOT and XOR gates
• Logic gates have the potential to be very useful in train projects. For example,
we may want Train 1 to move only when Train 2 is not on a certain part of
track. In this case, we could detect if Train 2 is on a certain part of track,
have this signal go through a NOT gate, and have the output control power to
Train 1.
15
• It can get pretty cumbersome to put together large sequences of logic gates. In
practice, we will do most logic in the Arduino.
2.3
Flip-flops
• We can put together two NAND gates to create a memory cell, which we call
a flip flop. There are other ways of making memory cells, but this is one of
the simplest. It is called an S̄R̄ latch (S̄ stands for set; R̄ for reset). The bars
above the S̄ and R̄ mean that they are active low.
[15]
S̄
R̄ Q
Q̄
1
0
0
1
0
1
1
0
1
1
remembers
0
0
undefined
Figure 2.8 & Table 2.4: Truth Table for S̄R̄ latch
• Let’s walk though how this flip-flop would work. We would set it up so that
by default, both S̄ and R̄ are HIGH (though a pull-up resistor).
• Now, take S̄ LOW. What happens? The output of the corresponding NAND
gate has to be HIGH. The output of this NAND gate feeds into the other
NAND gate. Since R̄ is HIGH, the NAND gate outputs LOW. So Q̄ is LOW.
This means Q should be HIGH. Indeed, we can verify this by noting that Q̄
is fed back into the other NAND gate, and since Q̄ is LOW, the output of the
NAND gate corresponding to Q is HIGH.
• Now, bring S̄ back HIGH. What happens? The NAND gate corresponding to
Q has inputs of HIGH (from S̄) and LOW (from Q̄), so the output of that
16
NAND gate is HIGH. Q has kept the same value. Now, to verify that Q̄ has
stayed LOW, note the inputs to the other NAND gate: HIGH (from Q) and
HIGH (from R̄), which outputs LOW.
• Now bring R̄ LOW. The corresponding NAND gate has inputs of LOW (from
R̄) and HIGH (from Q), so it outputs HIGH (i.e. Q̄ is now HIGH). The inputs
to the other NAND gate are HIGH (from Q̄) and HIGH (from S̄), so the output
(i.e. Q) is LOW. By setting R̄ LOW, we have “reset” Q.
• We can now bring R̄ back HIGH. The inputs to the corresponding NAND gate
are HIGH (from R̄) and LOW (from Q), so the output (i.e. Q̄) stays HIGH.
That output is fed into the other NAND gate, and along with HIGH from S̄,
the output (i.e. Q) is LOW. So Q and Q̄ have retained their values. This is how
a flip-flop functions as a memory cell; it can “remember” the previous state.
• Why is it illegal to have both R̄ and S̄ be LOW? Both of the NAND gates
would output HIGH. But this is a problem; Q and Q̄ cannot both be HIGH
(by definition, Q̄ means NOT(Q)). What would happen if both R̄ and S̄ were
brought back HIGH simultaneously? The outcome is indeterminate. Depending on whether R̄ or S̄ becomes HIGH first (even by a fraction of a second),
the resulting values of Q and Q̄ will be different.
2.4
Making logic gates
• What is happening inside a logic gate? The logic gates we use transistors (called
TTL, or transistor-transistor logic). These circuits can be quite complicated
to analyze. However, it’s possible to create simple logic gates using just diodes
and resistors.
• Here are OR and AND gates using just diodes and resistors. For the OR gate,
note that if either A or B is HIGH, Z will be HIGH, but if neither of them are
HIGH, then Z will be low. For the AND gate, if either A or B are LOW, then
17
Z will also be LOW. However, if both A and B are HIGH, then there will be
no voltage drop across the resistor and Z will also be HIGH. [26]
Figure 2.9: OR and AND gates can be constructed using diodes and resistors
18
2.5
Lab exercise
In this lab, students will learn how flip-flops work. They will change the inputs to
the 74LS76 flip-flop in particular sequences and see how this affects the output.
Instructions:
1. Assemble the circuit shown in the diagram. Note that not all pins on the
74LS76 are noted on the circuit diagram. Specifically, the pins for Vcc and
GND are not labeled. You will need to consult the datasheet for the 74LS76
to find which pins correspond to Vcc and GND (and this will generally be true
for future components that we use).
2. Connect Pin 2 (P RE) to GND and Pin 3 (CLR) to +5V. Henceforth, we’ll
refer to these pins as SET and RESET. What is Q? It should be HIGH.
3. Now connect both SET and RESET to +5V. Keep the circuit powered on the
whole time as you perform this sequence of inputs; unlike last week’s lab, the
manipulations you are performing in this lab are not independent. What is Q?
It should still be HIGH (the flip-flip “remembers”).
4. Now keep SET connected to +5V but connect RESET to GND. What is Q?
It should be LOW now.
5. Once again, connect both pins to +5V. What is Q? It should still be LOW.
[19]
Figure 2.10: Pinout diagram for 74LS76
19
2
4
R4
1k
3
3
2
1
4
16
74LS76
CLR
PRE
CLK
J
K
U1A
Q
Q
15
14
Title
270
R7
Lab 2 - Logic Gates and Flip Flops
LED
D4
LED
D3
Sheet
1
1
of
1
Re v
C
Date:
Size
A
2
Saturday, March 22, 2014
Document Number
A
R5
1k
+5V
D
A
SET
RESET
+5V
1
B
5
3
Lab 2 - Logic Gates and Flip Flops
4
B
C
D
5
Chapter 3
Magnetic Proximity Sensors
3.1
Motivation
• In the projects, we will want to know where the train is at different points in
time
• Last time, we talked about flip-flops, which can store a state (e.g. the train is
on a certain part of track or it is not)
• Why is this important? Maybe you only want train 2 to move if train 1 is not
nearby (to avoid a crash).
• There are many different ways to sense that a train has entered a certain part
of track. One option is to use optical sensors. Another type of sensor, which
we will use, varies its output voltage in response to a magnetic field. It is called
a hall sensor.
21
3.2
Discussion of E.H. Hall’s paper
The paper can be found here: http://www.stenomuseet.dk/skoletj/elmag/kilde9.
html [11]. Here is a summary of the paper:
• Hall’s inquiry started when he noticed an inconsistency between Maxwell and
Edlund. Maxwell wrote that “The mechanical force which urges a conductor
carrying a current across the lines of magnetic force, acts, not on the electric
current, but on the conductor which carries it.” This didn’t make sense to
Hall since “a wire not bearing a current is in general not affected by a magnet
and...a wire bearing a current is affected exactly in proportion to the strength
of the current, while size, and in general, the material of the wire are matters
of indifference.” When Hall read Prof. Edlund’s “Unipolar Induction” paper,
he noticed that Edlund assumed “that a magnet acts on a current in a fixed
conductor just as it acts on upon the conductor itself when free to move.”
The difference between Maxwell and Edlund motivated Hall to conduct his
experiment.
• In his first experiment, Hall placed a spiral of silver wire between the poles of an
electromagnet so that the magnetic field lines were perpendicular to the spiral.
Regardless of the whether the electromagnet was on or off, the resistance didn’t
change (contrary to what Hall had expected).
• Hall then postulated that there would be a difference in potential across two
sides of a conductor when current was passed through it with a perpendicular
magnetic field. When he used a metal plate, he didn’t detect any current using
his galvanometer, because the plate was too thick. His advisor, Prof. Rowland, advised him to try to same experiment with a gold leaf (much thinner).
Hall found that the current in his galvanometer varied proportionally with the
strength of the magnetic field. More generally, he found that the electric field
in a conductor is proportional to the magnetic field strength and the current
in the conductor, and inversely proportional to the area.
22
3.3
The Hall Effect
[27]
Figure 3.1: The Hall Effect is observed when a magnetic field is applied perpendicular to
a conducting plate
• Pass a current though a conductor, with a magnetic field applied perpendicular
to the plate. How does the trajectory of an electron get affected?
• The Lorentz force tells us F = q(E + v × B). When we first start passing
current through the conductor, there is no electric field across the short side of
the plate, so that term goes away and the equation simplifies to F = q(v × B).
[30]
• If we imagine an electron moving through the plate, in which direction does
the Lorentz force act on it? It is moving in the opposite direction of I (recall
conventional current points I in the direction of the movement of positive
charge). Since B is pointing up, and v is pointed back, by the right hand
rule, the force on a positive charge would be to the right. So the force on the
electron is to the left.
• As electrons get deflected to the left, we generate an electric potential across
the conductor. This is called the Hall voltage. [30] By measuring this voltage,
we can detect the strength of the magnetic field.
• Why doesn’t charge just keep on building up so that the Hall potential becomes
infinite? Recall the other term in the Lorentz force, related to the electric field.
23
We have a force of F = qE oriented in the opposite direction to the magnetic
force. When E = −v × B, the net force is zero and charge stops accumulating.
3.4
Hall Effect sensors and flip-flops
• Hall Effect sensors can be analog or digital. In analog sensors, the output
voltage varies proportionally to the magnetic field strength, whereas in the
digital sensors, the output is binary (5V or GND). We will be using digital
sensors.
• The sensors we are using have three pins. One needs to be connected to an
input voltage (in our case, +5V), and a second pin is connected to ground.
The third pin is the output. Because it is an open collector output, we need
to connect the output to +5V via a resistor. When a magnetic field is applied
across the sensor, the output will be pulled down to 0V. [22]
• If we combine hall-effect sensors with flip-flops, we can store whether or not a
train is on a certain part of a track. Connect the output of one hall sensor to
the SET pin, and the other hall sensor to the RESET pin. RESET the flip-flop
to start. When the train (with a magnet attached to it) passes over the first
sensor, it will SET the flip flop (so that Q is HIGH). When the train passes over
the second sensor, the flip-flop will be RESET and Q will go back LOW. In a
later lab, will we use the Arduino to read in Q, and make sequencing decisions
based on its value.
24
3.5
Lab exercise
In this lab, students will learn how hall effect sensors work and how they can be
combined with flip-flops. They will vary the magnetic field in the proximity of the
hall sensors and see how it affects the output of the flip-flop.
Instructions:
1. Assemble the circuit shown in the diagram. Remember that the Vcc and GND
are not labeled for the 74LS76. You will need to consult the datasheet for the
74LS76 to find which pins correspond to Vcc and GND.
2. Start by resetting the flip-flop. You can do this by holding the magnet next to
the hall-effect sensor which is connected to the RESET pin (Pin 8). The LED
should be off.
3. Now put the magnet next to the other hall sensor, which is connected to Pin
7. The LED should turn on because the flip-flop has been set.
4. Reset the flip-flop by placing the magnet next to the other hall sensor.
[22] [19]
Figure 3.2: Pinout diagrams for A1104 and 74LS76
25
5
+5V
A1104
HALL EFFECT SENSOR
A1104
HALL EFFECT SENSOR
+5V
A
3
2
+5V
4
+5V
+5V
R22
1k
R21
1k
3
8
7
6
9
12
Date:
Size
A
Title
74LS76
CLR
PRE
CLK
J
K
U1B
Q
Q
LED
R8
250
2
Friday, April 04, 2014
Document Number
Lab 3 - Magnetic Proximity Sensors
11
10
D5
Sheet
Lab 3 - Magnetic Proximity Sensors
4
GND
B
C
D
5
SIGNAL
SIGNAL
GND
1
1
1
of
1
Re v
A
B
C
D
Chapter 4
Solenoids and Relays
4.1
Motivation
• We will be using a microcontroller called an Arduino to control the power on
the train tracks. However, the maximum current that can be sourced from an
individual I/O pin is 40 mA. [1] An N Scale train can consume upwards of 250
mA.[23] We could destroy the Arduino if we tried to use it to power the tracks.
• Instead, we can use the Arduino as a signaling mechanism by using it to turn
on a transistor. By powering the tracks through a transistor, we don’t have to
worry about the current limitations of the Arduino.
• We want to do more than simply power the track in one direction. Sometimes
we want to reverse the direction of the train, or turn off power on the track.
To do this we can use a relay, which is the topic of today’s lecture.
4.2
The solenoid
• A solenoid is a coil of wire wrapped around in a cylinder.
27
[17]
Figure 4.1: A picture of a solenoid
• What happens when we pass current through the solenoid? From Ampere’s
H
Law, we have B · dl = µ0 I. Sufficiently far from the solenoid, B = 0. Because
we are taking dot products, and we know that B will be along the axis of the
solenoid, only one side of the closed loop contributes to the integral. We get
that BL = µ0 Ienc , or B = µ0 Ienc /L = µ0 In, where n is the number of coils per
meter. [36]
[13]
Figure 4.2: Ampere’s Law can be used to find the magnetic field of a solenoid
• What does the magnetic field look like? All the vertical components cancel
each other out, but the horizontal components add. The magnetic field looks
the same as that of a bar magnet.
28
[29]
Figure 4.3: An current-bearing solenoid and a bar magnet have the same magnetic field
4.3
Inside the relay
[7]
Figure 4.4: The internal structure of a SPDT (single pole double throw) relay
• In the figure above, connect one of the coil terminals to the signal, and the
other to ground. When the signal is LOW, there is no current going through
the solenoid.
29
• When there is no current going through the coil, the spring holds the armature
in the normally closed position. This results in the common terminal being
connected to the normally closed terminal.
• When the signal goes HIGH, current goes through the solenoid, resulting in a
magnetic field. The field strength is further amplified by the iron core, which
has a high magnetic permeability. [29]
• The contact on the armature is made of a ferromagnetic material like iron.
When subjected to a magnetic field, the iron contact becomes magnetized in
the direction of the magnetic field. The iron therefore gets attracted to the
solenoid, regardless of which way the solenoid is oriented. Assuming this force
is strong enough, it overcomes the force from the spring, and the common
terminal gets connected to the normally open terminal.
[28]
Figure 4.5: Ferromagnetic materials become magnetized in the direction of the externally
applied magnetic field
• Note that the armature in the relay stays in the normally open position only
as long as current flows through the solenoid. There is another type of relay,
called a latching relay, which does not require this constant flow of current to
maintain the normally open position. An example of a latching relay is a light
switch on the wall.
30
4.4
Lab exercise
In this lab, students will learn about two new components: the 74LS244 (buffer),
and the DPDT (double pole double throw) relay. They will build a circuit which
reverses the direction of power on the train tracks, causing the DC trolley to reverse
direction when the input to the relay is changed from HIGH to LOW.
Instructions:
1. Assemble the circuit shown in the diagram. Remember that power and ground
are not labeled on the circuit diagram, so you will need to consult the datasheet.
Also note that the input to COM1 is unregulated power, not +5V.
2. Once you have assembled the circuit, verify that it works properly by changing
the input from HIGH to LOW. You should hear a clicking sound from the relay
(this is the sound of the armature moving from normally closed to normally
open). Using the multimeter, verify that the outputs from Pins 11, 9, 6, and 8
are as you expect them to be.
3. When you are ready, come to the test board and connect your circuit to the
train tracks. Change the input from HIGH to LOW. The DC trolley should
change its direction. Because of the pull-up resistor (R9), the input is HIGH
by default.
Figure 4.6: Pinout diagrams for 74LS244 and 2N3906
31
A
B
C
D
5
5
INPUT
3
2
1
19
2
4
6
8
11
13
15
17
4
74LS244
1OE
2OE
A1
A2
A3
A4
A5
A6
A7
A8
U3
Y1
Y2
Y3
Y4
Y5
Y6
Y7
Y8
18
16
14
12
9
7
5
3
+5V
R9
1k
1k
R10
3
+5V
Q2
2N3906
Date:
Size
A
Title
Relay DPDT
B
8
COM2
NO2
A
9
COM1
NO1
NC2 6
NC1 11
D6
1N4003
2
Wednesday, April 16, 2014
Document Number
Lab 4 - Solenoids and Relays
16
1
4
13
U2
+9V Unregulated
Lab 4 - Solenoids and Relays
4
Sheet
1
1
1
of
1
Re v
D7
1N4003
A
B
C
D
Chapter 5
Throwing a Switch
5.1
Motivation
• Switches are used to divert a train from on train track to another. They allow
us to make more complicated railroad designs.
• In order to ”throw a switch”, that is, to change the orientation of a switch from
one direction to the other, we need to provide two pieces of information to the
switch: the direction in which the switch needs to be thrown (DIRECTION
input), and when to throw the switch (TRIGGER input)
• Throwing a switch requires a significant amount of current. At the moment
when a switch is thrown, the switch momentarily draws several amps of current.
Our power supplies are only able to provide 1A of current; therefore we need
a different way to provide this current.
5.2
The trickle charge circuit
This week’s lab is longer than that of previous weeks, so the lecture today will be
focused on explaining the different parts of the circuit diagram.
33
• Let’s start with the upper left part of the circuit diagram. We use the unregulated +9V power supply to charge a capacitor. Notice that the current that is
drawn from the power supply is limited by the 1k resistor. Also note that the
capacitor is polarized. This means that the capacitor must be put in the circuit
with the correct orientation, or you will destroy the capacitor. The longer lead
on the capacitor is the positive side. Another indicator is a white ribbon on
the side of the capacitor, which denotes the negative side (cathode).
• The capacitor (and the +9V power supply, through the 1k resistor) are connected to one of the common terminals of the relay. In practice, when current
flows into this common terminal, it will be coming from the capacitor, not the
power supply. This is because the capacitor is not current-limited by a resistor.
This is how we avoid drawing too much current from the power supply.
• The NC and NO terminals corresponding to this common are connected to
two of the terminals on the switch. I’ve called them NC and NO. However,
unlike the relay, where a constant supply of current across the coil is required
to maintain the NO position, the switch does not require a constant supply
of current in the coil. If the switch is in the NO position, it will stay there
until current is passed through the NC coil of the switch. A simple way to
think about how to build something like this is that the switch consists of two
solenoids with a piece of iron in between. When one solenoid, the NC solenoid,
is energized, the iron is pulled in that direction. When the NO solenoid is
energized instead, the iron is pulled in the opposite direction. There are also
springs which are oriented in manner that keep the iron in place once it has
reached either the NC or NO positions.
34
[21]
Figure 5.1: A latching relay can be constructed using two coils and an armature in
between
• The third terminal of the switch is the common. It is connected to ground
through the TIP122, which is a Darlington pair transistor. It consists of two
NPN transistors connected to each other, so that the emitter of the first transistor is connected to the base of the second. [34] This results in a greater
overall current gain, which is necessary since we want to sink several amps of
current.
• Note that current can only flow through the transistor when it is turned on,
that is, when the input to the base of the transistor is HIGH. We call this input
the TRIGGER. When the TRIGGER is LOW, no current can flow through the
coils of the switch, so the switch cannot be thrown. When we want to throw the
switch, we make TRIGGER HIGH. This discharges the capacitor and throws
the switch. Then we bring TRIGGER back LOW so that the capacitor can
recharge.
• To control the direction that the switch is thrown, we use the DIRECTION
input. Through the 2N3906 transistor, this input controls whether or not the
coil in the relay is energized, and therefore whether current will flow into the
NC or NO terminal of the switch.
35
• Finally, a couple small things. The capacitors on the switch help reduce the
magnitude of the transients when the switch is thrown. Without these, the
transients on the power supply can affect other components (like the state of a
flip flop). Also, the two pull-up resistors on the DIRECTION and TRIGGER
lines coming out of the buffer are there to eliminate chatter when the circuit is
first powered up.
• (Show Falstad circuit simulation; see Appendix A for instructions)
[8] [25]
Figure 5.2: Screenshot from DC trickle charge circuit simulation. Adapted from AC
trickle charge circuit simulation on MAE412 website
36
5.3
Lab exercise
In this lab, students will build the DC trickle charge circuit, which is used to throw a
railroad switch. They will integrate many of the components they have used in past
labs, including transistors, relays, and buffers. In addition, two new components are
introduced: the switch and the Darlington pair transistor.
Instructions:
1. Assemble the circuit shown in the diagram. Remember that power and ground
are not labeled on the circuit diagram. Also note you are asked to use both
+9V unregulated power and +5V in different parts of the circuit.
2. This is a complicated circuit which you should build in pieces. Build the
DIRECTION part of the circuit first, and make sure that the relay switches
from NC to NO when you change the DIRECTION input. Then build the
TRIGGER part of the circuit. Before you come to test your circuit, make sure
all three switch wires can be easily plugged into your breadboard.
3. To test whether or not your circuit works, start with both DIRECTION and
TRIGGER LOW. Then, after charging the capacitor for a couple seconds,
make TRIGGER HIGH. Depending on the original orientation of the switch,
the switch may change direction, or it may not. If it does not, try it again,
but this time set DIRECTION HIGH. Don’t forget to make TRIGGER LOW
once the switch has been thrown in order to recharge the capacitor.
[20] [34] [32]
Figure 5.3: Pinout diagrams for 74LS244, TIP122, and 2N3906
37
A
B
C
D
TRIGGER
DIRECTION
5
5
1
19
2
4
6
8
11
13
15
17
74LS244
1OE
2OE
A1
A2
A3
A4
A5
A6
A7
A8
U7
Y1
Y2
Y3
Y4
Y5
Y6
Y7
Y8
1k
R14
18
16
14
12
9
7
5
3
+9V Unregulated
3
2
4
+
C1
4700 uF
+5V
R17
1k
4.7k
R18
+5V
3
1k
R16
R15
1k
Q4
TIP122
2N3906
Q5
+5V
9
COM1
NO1
NC2 6
NC1 11
Date:
Size
A
C3
10uF
C2
10uF
2
Wednesday, April 16, 2014
Document Number
Lab 5 - Throwing a Switch
Relay DPDT
B
Title
16
8
COM2
1
NO2
A
4
13
U6
Lab 5 - Throwing a Switch
4
Sheet
1
1
of
1
N.O. (Red)
Re v
Common (Black)
N.C. (Green)
RR Switch
1
A
B
C
D
Chapter 6
The Arduino
6.1
Motivation
• The goal of the design projects is to build a robust system which senses, actuates, and sequences the model trains. The projects need to work automatically,
without any manual inputs.
• In previous labs, we manually moved around signal wires (to turn on the coil
in a relay, or to throw a switch). We are going to make this process automatic
by using a microcontroller called an Arduino.
• Today’s lecture will focus on the different pins on the Arduino Nano and how
they are used, as well as a primer on the Arduino programming language.
39
6.2
The Arduino Nano
[1]
Figure 6.1: A top view of the Arduino Nano
• The Arduino has 14 digital I/O pins and 8 analog input pins. The digital pins
are numbered 0 through 13, and the analog pins are numbered 14 through 19.
These pin numbers will be useful when writing your Arduino code. Note that
the pin numbers do not correspond directly to the physical location of those
pins on the Arduino. For example, the pin which we would usually call pin 4
is connected to GND, not digital pin 4. [1]
• In addition to the I/O pins, the Arduino needs to be connected to power and
ground. Since the recommended input voltage is 7-12V, we will connect +9V
unregulated power to pin 30 (Vin ). Note that there are two ground pins, pins
4 and 29; both of these must be connected to ground. [1]
• For power and ground, we can connect to the Arduino directly. For the I/O
pins, however, we will always connect to the Arduino through the 74LS244
buffer. The reason is that each I/O pin can supply only 40 mA of current,
and if we accidentally draw more than that (by using the Arduino to turn on
a relay without a transistor, for example), we could damage that pin or even
the entire Arduino. By using a buffer, we ensure that too much current is
not drawn from the Arduino. If we make a mistake, we will break the buffer
(cheap) rather than the Arduino (expensive).
40
6.3
Programming the Arduino
• To program the Arduino, we will use the Arduino software, which has already
been installed on your computers. The Arduino software uses the Arduino
programming language, which is simple to learn and is described here: http:
//arduino.cc/en/Reference/HomePage
• Once you write the code that the Arduino is supposed to run, you will upload
it to the Arduino using a USB cable. To do so, go to “Tools” → “Board” →
select “Arduino Nano w/ ATMega328. Then press the check mark in the upper
left part of the window to verify that your program has been written correctly.
Finally, upload it to the Arduino using the right arrow that is next to the check
mark.
6.4
Example program
• One of the simplest programs you can write is to make the Arduino behave like
a wire. Such a program would take in an input on one pin and immediately
output the same value on another pin. Here is what this program would look
like:
int in = 5;
int out = 6;
void setup() {
pinMode(in, INPUT);
pinMode(out, OUTPUT);
}
void loop() {
int val = digitalRead(in);
digitalWrite(out, val);
}
41
• Let’s analyze this program. There are three main parts. In the first part, we
define two integer variables, in and out, to equal 5 and 6, respectively. This
means that whenever we refer to in in our program, the Arduino will know to
go to digital pin 5, and whenever we refer to out, the Arduino will go to digital
pin 6.
• The second part of the program is the setup() function. In this function, we
define the pin modes. The Arduino needs to know which digital pins will be
inputs and which will be outputs. To do this, we use the pinMode() function,
which takes in two parameters: the number of the pin, and the mode (either
INPUT, OUTPUT, or INPUT PULLUP). [2]
• The last part of the program is the loop() function, which contains the instructions for the actions that you want the Arduino to perform. As the name
of the function suggests, the actions in the loop() function repeat indefinitely.
In the case of this program, we want the Arduino to continuously read in the
input on pin 5 and write it to pin 6. To do this, we use the digitalRead()
function, which takes one parameter: the pin number to be read in. We store
this in a variable called val and then use the digitalWrite() function to
output val on out, which we earlier defined as pin 6. [2]
6.5
Other useful functions
There are many operators, variables, and functions that are part of the Arduino
programming language, but here are a few more key functions that you may find
useful in writing your programs:
• The boolean data type can store two values, true and false. If you are
alternating between two things (for instance, a switch being NC and NO),
using a boolean variable to store the current state of the switch can be useful.
[2]
42
• The if...else loop will also be very useful. The loop is structured in the
following way:
if (condition)
{
// do this
}
else
{
// do that
}
Such a loop could be very useful for collision avoidance. For example, if you
program wants to send train 2 across an intersection only if train 1 is not nearby,
you could make the condition that train 1 is not nearby. If that condition is
true, then you send train 2 across the intersection. If it is false, you do nothing.
How do you do nothing for a certain period of time? Use the delay() function,
whose input parameter is the number of milliseconds you want to delay. [2]
• One other loop that will be very useful is the while() loop. This loop is
structured in the following way:
while (condition)
{
// do this
}
This loop is useful if you want something to keep happening while a condition
is true. Using the same example as before, of train 2 crossing an intersection,
maybe you want train 2 to keep going back and forth across the intersection
while train 1 is not nearby. When train 1 comes nearby, the condition becomes
false and train 2 stops crossing the intersection. [2]
• You should also take a look at the Arithmetic Operators and Comparison
Operators (not the difference between the assignment operator, which is =,
43
and equal to comparison operator, which is ==). The boolean operator for not,
!, may also be useful. The Arduino website provides sample programs to help
you understand how to use these operators functions. [2]
44
6.6
Lab exercise
In this lab, students will learn to use the Arduino programming language. They will
then use the Arduino to make a train go back and forth on a piece of track. The
Arduino will read in the output of a flip flop and output a signal to a transistor,
which is used to turn on a relay to change the direction of power on the track.
Instructions:
1. Your goal in this lab is to make the train move to one side of the track, wait
two seconds, then move to the other side of the track, wait two seconds, go
back to the first side, etc.
2. Begin by analyzing the circuit diagram and writing pseudocode for the actions
the Arduino would need to take to achieve the desired sequence. Then write
the code in the Arduino programming language. Check that your program
works by connecting it to the test board, which already has the working circuit
assembled.
3. Assemble the circuit shown in the diagram. Try to get the train to operate in
the manner described using your own circuit.
4. You might find that the circuit works fine when magnets are placed over the
hall sensors, but that the train behaves erratically when placed on the track.
This is related to the inductive load of the motor in the train. The noise the
train creates can affect many of the other components on your breadboard.
Here are some suggestions for reducing the noise:
• Use a separate power supply to power the tracks
• Make sure your track is smooth, and that wires are cleanly soldered. Bad
connections can lead to noise.
• Place plenty of despiking capacitors (approximately 0.1µF) between +5V
and GND. Also put a decoupling capacitor (approximately 10µF between
45
+5V and GND). It may also help to put capacitors between track power
and GND.
• Lower the resistance of the pull-up resistors to the Hall Sensor signals.
This will help the signals stay HIGH.
[20][32][19]
Figure 6.2: Pinout diagrams for 74LS244, 2N3906, and 74LS76
46
A
B
C
D
5
D12
1N4003
9
6
5
A1104
HALL EFFECT SENSOR
A1104
HALL EFFECT SENSOR
+5V
GND
SIGNAL
8
11
D13
1N4003
+5V
GND
SIGNAL
+5V
+5V
+5V
4
3
R12
1k
R11
1k
CLR
PRE
CLK
J
K
1
19
74LS244
1OE
2OE
A1
A2
A3
A4
A5
A6
A7
A8
U8
74LS76
2
4
6
8
11
13
15
17
3
2
1
4
16
U4A
3
Y1
Y2
Y3
Y4
Y5
Y6
Y7
Y8
Q
Q
15
14
18
16
14
12
9
7
5
3
Date:
Size
A
Title
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Relay DPDT
B
2
Tuesday, April 29, 2014
Document Number
Lab 6 - The Arduino
NC1 11
8
COM2
NO2
A
16
1
4
PC5
PC4
PC3
PC2
PC1
PC0
AGND
AREF
AVCC
PB5
PB4
PB3
PB2
PB1
Sheet
ATmega328
PC6
PD0
PD1
PD2
PD3
PD4
VCC
GND
PB6
PB7
PD5
PD6
PD7
PB0
IC1
9
COM1
NO1
NC2 6
13
U5
+9V Unregulated (PS2)
2N3906
Q3
+5V
R13
1k
2
+9V Unregulated
Lab 6 - The Arduino
+5V
4
28
27
26
25
24
23
22
21
20
19
18
17
16
15
1
1
of
1
Re v
+9V Unregulated
See railroad
tracks for pin
connections
1
A
B
C
D
Chapter 7
Final Design Project
You will be placed in groups of 4-5 students to build a project which combines the
various components we have discussed: diodes, transistors, flip-flops, hall sensors,
relays, switches, and the Arduino. A drawing of the project board is shown below.
Figure 7.1: A diagram of the design project setup. The ends of the loop will be provided.
Two teams will share space on each project board.
Each team has 44” of space to work with. At the beginning and end of this length,
you must have a straight piece of track which is at least 2” long. What you do in the
remaining 40” is up to you. The width of your project is not strictly constrained,
48
but it must not interfere with the work of the team across from you.
For project ideas, look at the project videos on http://www.princeton.edu/
~mae412/. These projects are far more complex that what we expect you to do,
since you will only have two weeks. However, you might be able to derive some ideas
from previous projects.
Part of the engineering process is proper planning. Therefore, before you start
building your circuits and putting together train tracks, you need to submit a project
proposal. The proposal must include a drawing of your proposed project (either made
on the computer, or hand-drawn very neatly). You must label all relevant dimensions
of the track and include all components which will be on the board (hall sensors,
motors, etc.). Your drawing should be detailed enough that two groups working
independently off the same drawing would make the same project.
You also need to include a parts list, which includes the following:
• Switches (teams are limited to a maximum of two switches)
• Relays
• Flip-Flops
• Hall Sensors
• Track pieces
• Any other special parts you need (please talk to me so that we can see if it is
feasible in terms of budget)
You must specify how many of each of these you will need. Track parts are only
available in certain dimensions. You can find the possible track parts here:
http://www.atlasrr.com/Trackmisc/ncode80.htm. Note that we will not be using
flex-track. You need not specify parts such as rail joiners, nails, and wire in your
parts list.
In addition, you should write a short description of how the project will work.
What is the exact sequence of events that will take place? Keep in mind that since
49
the track is shaped in a loop, the train will come back onto your project over and over
again. This means you could design a project that alternates between two things
each time the train enters your project. The more you think through the details
now, the less likely it is that you will have trouble later.
Finally, a note on grading. The most important factor in your grade will be
robustness: does your project consistently do what you say it will do? Other factors will include complexity and workmanship. Individual contribution will also be
considered.
If you have any questions, email me at [email protected].
50
Conclusions
Though I haven’t yet finished teaching the mini-course, the results so far have been
very positive, and I am glad that I took a risk and pursued an unusual thesis.
One of my primary objectives when I started this thesis was to expose high school
students to the fun and interesting applications of physics and engineering, and based
on the feedback I’ve received from students, I’ve been successful in accomplishing
this objective. When I informally surveyed students during class to ask them what
they think about the work I am asking them to do, I received comments like, “It’s
challenging, but it’s also fun” and “It’s nice to actually make a circuit that does
something.” Teaching high school students has also been very fulfilling for me; I’ve
always enjoyed mentoring and this project gave me a chance to teach a subject I am
passionate about while simultaneously giving back to my alma mater.
The work I accomplished also aligned quite well with the objectives I proposed
at the beginning of this year. I had written that “the course will consist of eight
classes, as well a week-long design project.” In the end, I developed only six classes,
but made the design project more extensive, so that it would take two weeks rather
than one.
While I view my thesis as a success on the whole, there are a few things I would
do differently if I were to repeat the project. First of all, I would allow more time
to teach each lesson. I overestimated the speed with which the students would be
able to build the circuits. I quickly learned on the first day of teaching that many
students didn’t know how to read a circuit schematic or had never used a breadboard
before. This lack of familiarity meant that building circuits took more time than I
51
had expected, and it was often difficult for students to complete the lab exercises in
the twenty-five minutes I had allotted. As a result, I modified my lessons as I went
along, shortening the lecture component as much as possible to allow more time for
building the circuits. Especially for the last two lessons, where the lab exercises
are quite extensive, I limited my lecture to a discussion of the circuit itself, while
omitting all extraneous information. I would recommend that for future years, each
lesson be split into two, so that forty-five minutes can be dedicated to an in-depth
discussion of the theory behind each circuit, and a full forty-five minutes can be given
to complete each lab. This would help ensure that most of the groups in the class
finish the circuit, rather than only the fastest groups.
I would also recommend that all the lessons be taught consecutively. I taught
lessons once a week (typically the Friday of every week). In one sense, this was a
nice break from the regular classwork that the students had, and I got the sense
that the students looked forward to doing something different but still intellectually
challenging at the end of the week. However, the downside of teaching only once a
week was the lack of continuity. Transistors were introduced in the first lab but not
used again until the fourth lab, and many students forgot how transistors worked
in the intervening three weeks. Had the lessons been taught consecutively, this gap
would have been much shorter. I’ve discussed this suggestion with Mr. Higgins and
he agreed that it would make sense to structure the lessons this way in future years.
There is usually about a month of school between the end of AP exams and the end
of the school year, and this would be the perfect length of time to each the lessons
and complete the design project.
There are many directions that future work could take. One direction would be
to dig deeper into the physics behind each component. For example, when discussing
how relays work, I simply stated that a current-bearing solenoid induces a magnetic
field in the iron armature, but I didn’t go into too much depth as to the reason behind
this. It would have been possible to discuss the quantum mechanical interactions
that lead to magnetic domains. I didn’t go into this topic because I was restricted
for time, but with more time, topics like this could be introduced.
Another direction for future work would be to introduce more components. In
52
MAE412, we spent the first half of the semester building our own computers, by
putting together a CPU, RAM, EPROM, VIA, etc. Again, because of the time
constraints, I used an Arduino instead. While the Arduino has the advantage of
being easy to use, building a computer from scratch would have led to a much better
understanding of how computers work.
Finally, a completely different direction for future work would be to build lab kits
for high school physics classes and commercialize them. Most high school science
departments don’t have the time to develop extensive projects like this, but it’s
possible that they might be able to purchase ready-made kits. Of course, to determine
the viability of this idea, it would be necessary to perform significant market research
and determine if there is enough demand for a product like this, and if the price point
would be accessible to public school districts. If it was financially feasible, it could
be a great way to get more hands-on learning into the physics classroom.
53
Bibliography
[1] Arduino. Arduino nano. http://arduino.cc/en/Main/arduinoBoardNano.
Accessed: 2014-04-22.
[2] Arduino. Language reference. http://arduino.cc/en/Reference/HomePage.
Accessed: 2014-04-29.
[3] Marshall Brain.
How semiconductors work.
http://electronics.
howstuffworks.com/diode1.htm. Accessed: 2014-04-21.
[4] All About Circuits. Introduction: Diodes and rectifiers. http://www.
allaboutcircuits.com/vol_3/chpt_3/1.html. Accessed: 2014-04-21.
[5] Eric Coates.
How bipolar transistors work.
http://www.
learnabout-electronics.org/bipolar_junction_transistors_04.php.
Accessed: 2014-04-22.
[6] Saint John’s University Physics Department College of Saint Benedict. Npn
characteristic curves. http://www.physics.csbsju.edu/trace/NPN.CC.html.
Accessed: 2014-04-22.
[7] Glolab Corporation. Relays, the electromechanical amplifier. http://www.
glolab.com/relays/relays.html. Accessed: 2014-04-22.
[8] Paul Falstad. Circuit simulator applet. http://falstad.com/circuit/. Accessed: 2014-04-26.
54
[9] Google. define diode - google search. https://www.google.com/search?q=
define+diode. Accessed: 2014-04-21.
[10] Resistor Guide. Ohm’s law. http://www.resistorguide.com/ohms-law/. Accessed: 2014-04-27.
[11] E. H. Hall. On a new action of the magnet on electric currents. http://www.
stenomuseet.dk/skoletj/elmag/kilde9.html. Accessed: 2014-04-22.
[12] Tom Harris and Wesley Fenlon. How light emitting diodes work. http://
electronics.howstuffworks.com/led1.htm. Accessed: 2014-04-21.
[13] Addison Wesley Longman Inc. Magnetic field. http://www.physics.sjsu.
edu/becker/physics51/mag_field.htm. Accessed: 2014-04-22.
[14] EDC Inc.
Specialized stem secondary schools.
http://
successfulstemeducation.org/sites/successfulstemeducation.org/
files/Specialized%20STEM%20Secondary%20Schools_FINAL_0.pdf.
Accessed: 2014-04-28.
[15] Wikimedia Foundation Inc. Flip-flop (electronics). http://en.wikipedia.org/
wiki/Flip-flop_(electronics). Accessed: 2014-04-22.
[16] Wikimedia Foundation Inc. Logic gate. http://en.wikipedia.org/wiki/
Logic_gate. Accessed: 2014-04-22.
[17] Wikimedia Foundation Inc. Solenoid.
Solenoid. Accessed: 2014-04-22.
http://en.wikipedia.org/wiki/
[18] Diodes Incorporated. 1n4001 - 1n4007. http://www.diodes.com/datasheets/
ds28002.pdf. Accessed: 2014-04-21.
[19] Texas Instruments. Dual j-k flip-flops with preset and clear. http://www.ti.
com/lit/ds/symlink/sn5476.pdf. Accessed: 2014-04-22.
55
[20] Texas Instruments. Octal buffers and line drivers with 3-state outputs. http:
//www.ti.com/lit/ds/symlink/sn74s241.pdf. Accessed: 2014-04-22.
[21] R.G. Keen. Relays for switching audio signals. http://www.geofex.com/
article_folders/relays/relays_for_switching_audio_signa.htm.
Accessed: 2014-04-26.
[22] Allegro Microsystems LLC. A1101, a1102, a1103, a1104, and a1106. http:
//www.nist.gov/pml/div683/hall_effect.cfm. Accessed: 2014-04-22.
[23] Japanese Modeling and Japan Rail Enthusiasts Forum. Optimal volt and
amp for n and h0 scale. http://www.jnsforum.com/community/topic/
7539-optimal-volt-and-amp-for-n-and-h0-scale/. Accessed: 2014-04-22.
[24] U.S. Department of Education. Science, technology, engineering and math:
Education for global leadership. http://www.ed.gov/stem. Accessed: 201404-28.
[25] Princeton University Department of Mechanical and Aerospace Engineering.
Mae412-microprocessors. http://www.princeton.edu/~mae412/electronic.
html. Accessed: 2014-04-26.
[26] Georgia State University Dept. of Physics and Astronomy.
Diode
logic gates. http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/
diodgate.html. Accessed: 2014-04-22.
[27] Georgia State University Dept. of Physics and Astronomy. Hall effect. http:
//hyperphysics.phy-astr.gsu.edu/hbase/magnetic/hall.html. Accessed:
2014-04-26.
[28] Georgia State University Dept. of Physics and Astronomy. Magnetic domains.
http://hyperphysics.phy-astr.gsu.edu/hbase/solids/ferro.html. Accessed: 2014-04-26.
56
[29] Georgia State University Dept. of Physics and Astronomy. Magnets and
electromagnets. http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/
elemag.html. Accessed: 2014-04-22.
[30] The National Institute of Standards and Technology. The hall effect. http:
//www.nist.gov/pml/div683/hall_effect.cfm. Accessed: 2014-04-22.
[31] Fairchild Semiconductor. 2n3904 / mmbt3904 / pzt3904 npn general purpose
amplifier. http://www.fairchildsemi.com/ds/2N/2N3904.pdf. Accessed:
2014-04-22.
[32] Fairchild Semiconductor. 2n3906 / mmbt3906 / pzt3906 pnp general purpose
amplifier. https://www.fairchildsemi.com/ds/2N/2N3906.pdf. Accessed:
2014-04-22.
[33] Fairchild Semiconductor. Lm78xx / lm78xxa 3-terminal 1 a positive voltage regulator. http://www.fairchildsemi.com/ds/LM/LM7805.pdf. Accessed: 201404-22.
[34] Fairchild Semiconductor. Tip120/tip121/tip122 npn epitaxial darlington transistor. http://www.adafruit.com/datasheets/TIP120.pdf. Accessed: 201404-26.
[35] STEMconnector.
Where are the stem students?
http:
//www.stemconnector.org/sites/default/files/store/
STEM-Students-STEM-Jobs-Executive-Summary.pdf. Accessed: 2014-04-28.
[36] Frank Wolfs. Ampere’s law. http://teacher.pas.rochester.edu/phy122/
Lecture_Notes/Chapter31/chapter31.html. Accessed: 2014-04-22.
[37] B. Van Zeghbroeck. Reverse bias breakdown. http://ecee.colorado.edu/
~bart/book/book/chapter4/ch4_5.htm. Accessed: 2014-04-22.
57
Appendix A
Trickle Charge Circuit Simulation
The circuit in Lesson 5 is complex, and the flow of current can be difficult to visualize.
Fortunately, Paul Falstad has developed a circuit simulation applet. [8] To simulate
the circuit in Lab 5, go to http://falstad.com/circuit/ and run the applet. Click
”File” and then select ”Import”. Type in the text below and then press ”Import”
again. Then press ”Close”.
By manipulating the TTL Dir and TTL Trig inputs, we can simulate throwing
a switch. First set DIRECTION to be HIGH or LOW while keeping TRIGGER
LOW. Then set TRIGGER HIGH to release the current from the capacitor. Restore
TRIGGER to LOW, change DIRECTION from LOW to HIGH or HIGH to LOW,
and after letting the capacitor charge, set TRIGGER HIGH again to release current
on the other coil of the switch.
Text to import:
$
r
c
w
r
g
1 0.0010 17.532943091211475 52 5.0 50
336 272 432 272 0 1000.0
432 272 432 368 0 0.0047 1.376731597321112
432 272 576 272 0
560 512 640 512 0 4700.0
432 368 432 400 0
58
w 736 496 736 512 0
w 688 496 736 496 0
t 688 528 736 528 0 1 0.014845647455757338 0.6289455347617325 100.0
t 640 512 688 512 0 1 0.5873792956333251 0.5725336481775678 100.0
g 736 544 736 576 0
178 736 192 736 112 1 1 0.2 0.1438126605659496 0.05 1000000.0 0.02 20.0
R 704 112 688 80 0 0 40.0 5.0 0.0 0.0 0.5
t 544 128 592 128 0 -1 1.4238877283252338 -0.6998590603557713 100.0
w 592 112 688 112 0
g 592 144 592 176 0
r 544 128 480 128 0 1000.0
r 480 128 480 64 0 1000.0
R 480 64 480 32 0 0 40.0 5.0 0.0 0.0 0.5
w 736 192 736 272 0
w 736 272 576 272 0
w 752 112 752 96 0
w 752 96 832 96 0
w 720 112 720 64 0
w 720 64 832 64 0
r 928 80 928 32 0 100.0
r 928 80 928 128 0 100.0
l 928 32 928 0 0 1.0 -0.00762250584722776
l 928 128 928 160 0 1.0 -7.625554544697507E-7
w 928 80 976 80 0
w 976 80 976 368 0
w 976 368 736 496 0
w 928 0 832 64 0
w 832 96 928 160 0
L 480 128 448 128 0 0 false 5.0 0.0
x 335 138 413 144 0 24 TTL Dir
x 397 515 486 521 0 24 TTL Trig
x 123 267 256 273 0 24 Track Power
x 845 88 916 94 0 24 Switch
L 560 512 528 512 0 1 false 5.0 0.0
R 336 272 304 272 0 0 40.0 9.0 0.0 0.0 0.5
o 1 64 0 35 10.0 9.765625E-5 0 -1
o 0 64 0 35 10.0 0.0125 1 -1
o 25 64 0 35 6.103515625E-4 9.765625E-5 2 -1
59
Appendix B
Solution Code for Lab 6
Below is the code which makes Lab 6 run successfully:
int in = 5;
int out = 6;
void setup() {
pinMode(in, INPUT);
pinMode(out, OUTPUT);
}
void loop() {
int val = digitalRead(in);
delay(2000);
digitalWrite(out, val);
}
60