Download 00A Microcontroller Relay Switch with Pushbutton Control Lab

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Opto-isolator wikipedia , lookup

Rectiverter wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Relay wikipedia , lookup

Protective relay wikipedia , lookup

Transcript
1
Microcontroller Relay Switch with Pushbutton Control Lab
I. Introduction
Through the use of relays, the microcontroller has the capability of controlling large currents and voltages
along their associated applications. The relay allows the microcontroller to interface with these large
voltages/currents so that the microcontroller may not be damaged. The microcontroller allows the user to
choose the manner in which the relay will interact with the high voltage circuit, e.g. timer controlled,
pushbutton controlled, or computer-interface controlled (among others).
II. The Relay (Component Description)
The relay to be used in this lab exercise is a Songle ISO9002 relay (data sheet attached). The relay is
capable of handling currents of 10 amps at voltages of 250VAC and 30VDC. These relays come attached
to a fiberglass circuit board in quantities of 1, 2, 4, 8, and 16 relays. Each relay requires an individual
input signal (in this case from the microcontroller). The relays also require a common ground (Vss) and
an input voltage (5v will be used—supplied from Vdd of the Basic Stamp microcontroller). To connect
the relay circuit board to the microcontroller requires jumper wires for breadboards and microcontrollers
with at least one female end per wire; this is because the relay circuit board uses male header pins to
connect to peripheral devices (e.g. the Basic Stamp).
Each relay itself has three screw terminals for connecting to high voltage circuits. These three screw
terminals correspond to one normally-closed terminal, one normally-open terminal, and a common
terminal. The common terminal is the connection point coming from the power source. This terminal
connects to only one of the other two terminals at a time. The load of the circuit is connected to either the
normally-open terminal or the normally-closed terminal.
2
When the device is unpowered, the normally-closed terminal (N.C.) is the terminal that closes the circuit,
whereas the normally-open terminal (N.O.) forms an open circuit. When the relay device is connected to
the Basic Stamp microcontroller, the relay is capable of closing contact with the normally-open terminal
and breaking contact with the normally-closed terminal. The Songle relay makes contact with the
normally-open terminal upon a LOW signal (0V) from the microcontroller. A HIGH signal (5v) will
make contact with the normally-closed terminal. When a relay is making contact with the normally-open
terminal, an LED will be lit on the relay circuit board that corresponds to that particular relay.
III. Wiring
Single Relay Module:
Note: 220 Ohm resistor may be replaced with a fewer Ohm resistor. This may be necessary if the Basic
Stamp cannot detect a HIGH signal on P6 when pushing the button.
3
4 Relay Module (for both 3 phase and single phase):
IV. Operation
Code for Single Relay module:
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 1000
onephase VAR Bit
onephase = 0
HIGH 3
LOW 6
'Initially sets the relay to N.C.
'Initially sets the pushbutton pin to low
DO
IF (IN6 = 1) AND (onephase = 1) THEN
onephase = 0
'When at 0, the relay is to be connected to N.C.
HIGH 3
'Signals the relay to contact the N.C. terminal
PAUSE 500
ELSEIF (IN6 = 1) AND (onephase = 0) THEN
onephase = 1
'When at 1, the relay is to be connected to N.O.
LOW 3
'Signals the relay to contact the N.O. terminal
PAUSE 500
ENDIF
PAUSE 50
DEBUG HOME, "onephase = ", DEC onephase, CR
LOOP
END
4
The IF statements in the code are looking for two conditions: (1) the state of the variable (onephase)
which indicates whether the relay is connected to the N.C. or N.O. terminal, and (2) if the pushbutton is
being depressed (which results in a high signal upon pin 6). The variable (onephase) is binary, and each
binary value is being mapped to one of the relay terminals (N.C. = 0; N.O. = 1). The single pushbutton
performs the function of turning the load on and off (through the relay). The LED on the relay circuit
board will indicate if the N.O. terminal is closed and the load is on.
With the 4 relay module, three relays are to be linked together under a second variable (threephase). This
variable uses a second pushbutton and a second pushbutton pin (P7) to replicate the function of a single
relay. The following code has 3 relays linked and the fourth relay as separate from the others.
Code for 4 Relay module:
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 1000
threephase VAR Bit
onephase VAR Bit
threephase = 0
onephase = 0
HIGH 0
HIGH 1
HIGH 2
HIGH 3
LOW 6
LOW 7
'Initially sets the relays to N.C.
'Initially sets the pushbutton pins to low
DO
IF (IN7 = 1) AND (threephase = 1) THEN
threephase = 0
'When at 0, relays 2, 3, and 4 are to be connected to N.C.
HIGH 0
'Signals the relays to contact the N.C. terminals
HIGH 1
HIGH 2
PAUSE 500
ELSEIF (IN7 = 1) AND (threephase = 0) THEN
threephase = 1
'When at 1, relays 2, 3, and 4 are to be connected to N.O.
LOW 0
'Signals the relays to contact the N.O. terminals
LOW 1
LOW 2
PAUSE 500
ELSEIF (IN6 = 1) AND (onephase = 1) THEN
onephase = 0
'When at 0, relay 1 is to be connected to N.C.
HIGH 3
'Signals the relay to contact the N.C. terminal
PAUSE 500
ELSEIF (IN6 = 1) AND (onephase = 0) THEN
onephase = 1
'When at 1, relay 1 is to be connected to N.O.
LOW 3
'Signals the relay to contact the N.O. terminal
PAUSE 500
ENDIF
PAUSE 50
DEBUG HOME, "3-phase = ", DEC threephase, " and 1-phase = ", DEC onephase, CR
LOOP
END