Professional Documents
Culture Documents
#define INPORT 12
#define OUTPORT 11
#define DEBOUNCE_DELAY 10
pinMode(INPORT, INPUT);
pinMode(OUTPORT,OUTPUT);
outputValue = LOW;
digitalWrite(OUTPORT,outputValue);
bool waitForEdge() {
newValue = digitalRead(INPORT);
delay(DEBOUNCE_DELAY);
return newValue;
// Repeat forever
void loop() {
if (!value) {
outputValue = !outputValue;
digitalWrite(OUTPORT, outputValue);
Skip to content
Relays
Relays have two distinct, electrically independent parts. The first part is an
electromagnet, a coil of insulated copper wire wound around a metal bracket,
the yoke, that becomes magnetic when a current is applied to it. The other
part is a spring-loaded metallic plate or armature resting on metal contacts.
When a current is applied to the electromagnet, enough force is applied to the
armature for it to disconnect from its resting contacts and make an electrical
connection with another set of metallic contacts on which the armature rests
for as long as there is electrical current in the electromagnet. When current
stops flowing in the electromagnet, the spring attached to the metallic
armature forces it back to its initial resting position, making an electrical
connection between the metallic plate and the resting contacts.
Relays come in a variety of sizes and ratings. Ratings are used to select a
relay to be used for specific applications. Automotive relays, for instance
have rated coil voltages of 12 volts. Relays intended to be used in household
appliances have rated coil voltages of 120 or 240 volts. Following is a list of
relay coil ratings supplied by manufacturers.
Transistors
Transistors are semiconductor devices used to amplify or switch electronic
signals and electrical power. There are many types of transistors, but the
most common is the bipolar junction transistor (BJT). There are two types of
bipolar junction transistors, the NPN and PNP types, describing the material
and configuration used to build the device. For the current project and
tutorial, we will use an NPN transistor. There are several configurations that
transistor circuits may use. In order to explain how the transistor operates, I
will be using the common-emitter configuration, that is a transistor circuit
with its emitter directly connected to ground. Consider the following circuit.
The transistor, labelled Q1, is at the center of the diagram. It is represented
by a circle with a vertical bar from which three branches are attached. The
diagonal branch at the top is called the collector. It is connected to a resistor,
RLoad, representing the device to be switched on or off. The branch to the left
of the transistor symbol, perpendicular to the bar is called the base. It is
connected to a resistor, RBase, that controls the current flowing into the base.
Finally, the diagonal branch with the arrow pointing outward is the emitter. If
the arrow had been pointing towards the bar inside the symbol, we would
have a PNP transistor. In this circuit, the emitter is connected to ground. The
principle of operation of the transistor is that a small current flowing from the
base to the emitter of the transistor will allow a larger current flowing from
the collector to the emitter, thus amplifying the base current.
Transistors, like other electronic devices, have specifications telling us about
the electrical limitations of the devices as well as information about their
capabilities. In the circuit that we will build later on, we will use a BC337-
40 NPN Bipolar Junction Transistor. I have found the following information
from the product data sheet provided at SparkFun.
Maximum Collector-
Base Voltage |VCES| – 50
V, the maximum voltage
drop between the
collector and the base.
Maximum Collector-
Emitter Voltage |VCEO| –
45 V, the maximum
voltage drop between the
collector and the emitter.
Maximum Emitter-Base
Voltage |VEBO| – 5 V, the
maximum reverse voltage
drop between the emitter
and the base.
Maximum Collector
Current |IC| – 800 mA,
the maximum amount of
current that can flow
through the collector.
Power Dissipation |PD| –
650 mW, the power
dissipation of the device.
Forward Current
Transfer Ratio |hFE|,
minimum – 250, the
minimum amount of
current amplification
between the base current
and the collector current.
Here is a picture of the BC337-40 transistor above. It comes in a TO-
92package, a small plastic half cylinder with a flat face on which the
transistor markings are written and three metal pins sticking out at the bottom
of the package. When the transistor’s flat face is facing the reader, the
collector pin is at the left side of the transistor, the base is the center pin, and
the emitter pin is at the right side of the transistor.
Transistor Operation
One characteristic that all silicon transistors have is the forward bias voltage
required between the base and the emitter for the transistor to work.
Remember that in a previous post titled the Blink circuit, we saw that
the LED had a constant voltage drop across its anode and cathode. Similarly,
transistor based on silicon have a voltage drop of approximately 0.7 volts
between their base and emitter when in operation. Below that voltage, no
current flows through the base nor the collector. When the base-emitter
voltage (VBE) of the transistor is increased to 0.7 volts, current starts flowing
through the base and through the collector. The base-emitter voltage remains
at 0.7 volts while current flows through the base. The amount of current
flowing through the collector (IC) is proportional to the current flowing
through the base (IB) times the Forward Current Transfer Ratio (hFE) of the
transistor.
IC = IB = 0, if VBE < 0.7 V
IC = hFE•IB, if VBE ≥ 0.7 V
Let’s have a look at a graph plotting the voltage drop across the relay’s coil
as a function of the voltage at the Arduino’s digital output pin.
On the plot, we see that the voltage applied to the load is 0 volts for as long
as the input voltage is below 0.7 volts. Then, as input voltage increases,
voltage at the relay coil increases until the input voltage reaches
approximately 3.5 volts, at which point the voltage drop across the relay’s
coil reaches 5 volts and the transistor enters saturation.
The vertical blue bands represent the guaranteed LOW and HIGH voltage
values output by the Arduino’s digital output pin. The top horizontal blue
band represents the voltage zone in which the relay is on and the bottom blue
horizontal band represents the voltage zone in which the relay is guaranteed
to be off. In the diagram, we note that the relay is off for all guaranteed
values for Arduino’s LOW output and that it is on for all guaranteed values
for Arduino’s HIGH output.
The maximum base current is 5 V / 10 K, or 0.5 mA, a totally acceptable
value for the Arduino’s digital output capability. The next step, is to connect
a household device to the relay.
Breadboarding
The following picture depicts how to connect the different parts using a
solderless breadboard, jumper wires, a transistor, a diode, a relay, a push
button and two 10K resistors. Connections to the household appliance are not
shown.
The Program
The following Arduino program completes the post. Cut and paste the code
in your Arduino IDE and download it to complete the project. It will toggle
the lamp on and off at each press of the pus button.
#define INPORT 12
#define OUTPORT 11
#define DEBOUNCE_DELAY 10
void setup() {
pinMode(INPORT, INPUT);
pinMode(OUTPORT,OUTPUT);
outputValue = LOW;
digitalWrite(OUTPORT,outputValue);
bool waitForEdge() {
newValue = digitalRead(INPORT);
delay(DEBOUNCE_DELAY);
return newValue;
}
// Repeat forever
void loop() {
if (!value) {
outputValue = !outputValue;
digitalWrite(OUTPORT, outputValue);
WARNING:
The project in this post involves household mains high-voltages. Use caution
whenever dealing with high-voltage wiring, including following directions
carefully and following general safety practices. Safe assembly and operation
of this project is the user’s responsibility. If unsure or if local laws prohibit
the assembly of high-voltage circuits, get the help of a professional
electrician. Do not make changes to the system while the device is plugged
in.
SHARE THIS:
Twitter
Facebook
A Light Activated SwitchDecember 26, 2020In "Electronics"
A Better Transistor Switch CircuitOctober 10, 2018In "Electronics"
Switch DebouncingMay 30, 2020In "Electronics"
PUBLISHED BY
Michel Lagacé
More than 40 years working in the high technology sector, I now share tips
and tricks on software and electronics. I also love to cook and to write in my
spare time. View all posts by Michel Lagacé
Posted onOctober 8, 2018AuthorMichel
LagacéCategoriesElectronicsTagsArduino, Electronics,learning, push
button, relay, transistor, tutorial
Leave a Reply
Post navigation
PREVIOUSPrevious post:LED Toggle with a Push-Button Switch
NEXTNext post:A Better Transistor Switch Circuit
Website Powered by WordPress.com.