Parallel Port Relay Interface

Here is an example of controlling a relay from the PC's parallel printer port (LPT1 or LPT2). The 7.5K resistor is connected to one of the data output lines (D0-D7) and a common connection is made from the negative side of the power supply to one of the port ground pins (18-25). Data is inverted by the 3904 transistor so that writing a "0" to the base address will energize any relays connected to D0-D7 and a "255" will reset them. You may need to try all three base addresses to determine the correct address for the port you are using but LPT1 is usually at Hex 0378. The QBasic "OUT" command can be used to send data to the port. OUT, &H0378,0 sets D0-D7 low and OUT, &H378,255 sets D0-D7 high.


Reading Data From The Parallel Port

The diagram below shows 5 switches connected to the 5 input lines of the parallel port. An external 5 volt power supply is used to provide high logic levels to the input pins when the switches are open. Three 1.5 volt batteries in series can be used to obtain 4.5 volts which is close enough. The 330 ohm resistors in series with the port connections provide some protection in case a connection is made to the wrong pin. If you are sure of the connections, the 330 ohm resistors can be left out and the switches connected directly to the input pins. The negative side of the power supply should be connected to the ground point, or any pin from 18 to 25.

The following short QBasic program can be used to read the state of the switches. QBASIC.EXE can be found in the "OLDMSDOS" directory of the Windows 95/98 CD Rom. Note that there are three possible printer port address that correspond to LPT1, LPT2 and LPT3 and LPT1 is usually the one to use which is at address decimal 889. The program waits for the user to press the enter key before reading the state of the 5 input lines. The state of the 5 lines is received as a single 8 bit number between 0-255 which is stored as the value of (V). Each switch input represents a decimal value of 8,16,32,64 and 128 which correspond to pins 15,13,12,10 and 11. The last 3 bits (1,2 and 4) are not used and should return a high level, so the value received with all switches open should be 1+2+4+8+16+32+64=127. If a switch is closed and the input is at ground, the value will be 0 except for pin 11 which is inverted and yields a value of 128 and 0 when high, so the value received when all switches are closed should be 1+2+4+128=135.

Address = 889: REM 889 = port address, other addresses could be 633 or 957
PRINT "Press the enter key to read printer port pins (15,13,12,10,11)"
PRINT "A (0) reading indicates the pin is at ground level, (1) indicates"
PRINT "the pin is at a high level or unterminated."
V = INP(Address)
P11 = 1
IF V > 127 THEN P11 = 0: V = V - 128
IF V > 63 THEN P10 = 1: V = V - 64
IF V > 31 THEN P12 = 1: V = V - 32
IF V > 15 THEN P13 = 1: V = V - 16
IF V > 7 THEN P15 = 1
PRINT "Pin 15 ="; P15
PRINT "Pin 13 ="; P13
PRINT "Pin 12 ="; P12
PRINT "Pin 10 ="; P10
PRINT "Pin 11 ="; P11


Micro Power AM Broadcast Transmitter

In this circuit, a 74HC14 hex Schmitt trigger inverter is used as a square wave oscillator to drive a small signal transistor in a class C amplifier configuration. The oscillator frequency can be either fixed by a crystal or made adjustable (VFO) with a capacitor/resistor combination. A 100pF capacitor is used in place of the crystal for VFO operation. Amplitude modulation is accomplished with a second transistor that controls the DC voltage to the output stage. The modulator stage is biased so that half the supply voltage or 6 volts is applied to the output stage with no modulation. The output stage is tuned and matched to the antenna with a standard variable 30-365 pF capacitor. Approximately 20 milliamps of current will flow in the antenna lead (at frequencies near the top of the band) when the output stage is optimally tuned to the oscillator frequency. A small 'grain of wheat' lamp is used to indicate antenna current and optimum settings. The 140 uH inductor was made using a 2 inch length of 7/8 inch (OD) PVC pipe wound with 120 turns of #28 copper wire. Best performance is obtained near the high end of the broadcast band (1.6 MHz) since the antenna length is only a very small fraction of a wavelength. Input power to the amplifier is less than 100 milliwatts and antenna length is 3 meters or less which complies with FCC rules. Output power is somewhere in the 40 microwatt range and the signal can be heard approximately 80 feet. Radiated power output can be approximated by working out the antenna radiation resistance and multiplying by the antenna current squared. The radiation resistance for a dipole antenna is 80*pi^2*(length/wavelength)^2 which yields about 0.2 ohms for a 3 meter dipole at a frequency of 1.6 MHz. Radiated power at 20 milliamps is about I^2 * R = 80 microwatts and for a grounded system with a single element whip antenna, the radiated power is about half that, or 40 microwatts.


FM Beacon Broadcast Transmitter (88-108 MHz)

This circuit will transmit a continuous audio tone on the FM broadcast band (88-108 MHz) which could used for remote control or security purposes. Circuit draws about 30 mA from a 6-9 volt battery and can be received to about 100 yards. A 555 timer is used to produce the tone (about 600 Hz) which frequency modulates a Hartley oscillator. A second JFET transistor buffer stage is used to isolate the oscillator from the antenna so that the antenna position and length has less effect on the frequency. Fine frequency adjustment can be made by adjusting the 200 ohm resistor in series with the battery. Oscillator frequency is set by a 5 turn tapped inductor and 13 pF capacitor. The inductor was wound around a #8 X 32 bolt (about 3/16 diameter) and then removed by unscrewing the bolt. The inductor was then streached to about a 3/8 inch length and tapped near the center. The oscillator frequency should come out somewhere near the center of the band (98 MHz) and can be shifted higher or lower by slightly expanding or compressing the inductor. A small signal diode (1N914 or 1N4148) is used as a varactor diode so that the total capacity in parallel with the inductor varies slightly at the audio rate thus causing the oscillator frequency to change at the audio rate (600 Hz). The ramping waveform at pins 2 and 6 of the timer is applied to the reversed biased diode through a large (1 Meg) resistor so that the capacitance of the diode changes as the ramping voltage changes thus altering the frequency of the tank circuit. Alternately, an audio signal could be applied to the 1 Meg resistor to modulate the oscillator but it may require an additional pullup resistor to reverse bias the diode. The N channel JFET transistors used should be high frequency VHF or UHF types (Radio Shack #276-2062 MPF102) or similar.


12 Volt Lamp Dimmer

Here is a 12 volt / 2 amp lamp dimmer that can be used to dim a standard 25 watt automobile brake or backup bulb by controlling the duty cycle of a astable 555 timer oscillator. When the wiper of the potentiometer is at the uppermost position, the capacitor will charge quickly through both 1K resistors and the diode, producing a short positive interval and long negative interval which dims the lamp to near darkness. When the potentiometer wiper is at the lowermost position, the capacitor will charge through both 1K resistors and the 50K potentiometer and discharge through the lower 1K resistor, producing a long positive interval and short negative interval which brightens the lamp to near full intensity. The duty cycle of the 200 Hz square wave can be varied from approximately 5% to 95%. The two circuits below illustrate connecting the lamp to either the positive or negative side of the supply.


Simple Op-Amp Radio

This is basically a crystal radio with an audio amplifier which is fairly sensitive and receives several strong stations in the Los Angeles area with a minimal 15 foot antenna. Longer antennas will provide a stronger signal but the selectivity will be worse and strong stations may be heard in the background of weaker ones. Using a long wire antenna, the selectivity can be improved by connecting it to one of the taps on the coil instead of the junction of the capacitor and coil. Some connection to ground is required but I found that standing outside on a concrete slab and just allowing the long headphone leads to lay on the concrete was sufficient to listen to the local news station (KNX 1070). The inductor was wound with 200 turns of #28 enameled copper wire on a 7/8 diameter, 4 inch length of PVC pipe, which yields about 220 uH. The inductor was wound with taps every 20 turns so the diode and antenna connections could be selected for best results which turned out to be 60 turns from the antenna end for the diode. The diode should be a germanium (1N34A type) for best results, but silicon diodes will also work if the signal is strong enough. The carrier frequency is removed from the rectified signal at the cathode of the diode by the 300 pF cap and the audio frequency is passed by the 0.1uF capacitor to the non-inverting input of the first op-amp which functions as a high impedance buffer stage. The second op-amp stage increases the voltage level about 50 times and is DC coupled to the first through the 10K resistor. If the pairs of 100K and 1 Meg resistors are not close in value (1%) you may need to either use closer matched values or add a capacitor in series with the 10K resistor to keep the DC voltage at the transistor emitter between 3 and 6 volts. Another approach would be to reduce the overall gain with a smaller feedback resistor (470K). High impedance headphones will probably work best, but walkman stereo type headphones will also work. Circuit draws about 10 mA from a 9 volt source. Germanium diodes (1N34A) types are available from Radio Shack, #276-1123.