Silicon ChipPC Controlled Mains Switch Mk.2 - July 2006 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Nuclear power debate should look at the whole picture
  4. Feature: MoTeC Race Car Data Logging by Julian Edgar
  5. Feature: Television: The Elusive Goal; Pt.2 by Kevin Poulter
  6. Project: Mini Theremin Mk.2; Pt.1 by John Clarke
  7. Project: Programmable Analog On-Off Controller by Greg Radion
  8. Project: Studio Series Stereo Preamplifier by Peter Smith
  9. Salvage It: There Are Lots Of Good Bits Inside Junked Photocopiers by Julian Edgar
  10. Project: PC Controlled Mains Switch Mk.2 by Trent Jackson
  11. Project: Stop Those Zaps From Double-Insulated Equipment by John Clarke
  12. Vintage Radio: AWA B33: the ultimate Australian-made transistor portable by Rodney Champness
  13. Book Store
  14. Advertising Index
  15. Outer Back Cover

This is only a preview of the July 2006 issue of Silicon Chip.

You can view 38 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • MoTeC Race Car Data Logging (July 2006)
  • MoTeC Race Car Data Logging (July 2006)
  • MoTeC Race Car Data logging, Pt.2 (August 2006)
  • MoTeC Race Car Data logging, Pt.2 (August 2006)
Articles in this series:
  • Television: The Elusive Goal; Pt.1 (June 2006)
  • Television: The Elusive Goal; Pt.1 (June 2006)
  • Television: The Elusive Goal; Pt.2 (July 2006)
  • Television: The Elusive Goal; Pt.2 (July 2006)
  • Television – The Elusive Goal; Pt.3 (August 2006)
  • Television – The Elusive Goal; Pt.3 (August 2006)
Items relevant to "Mini Theremin Mk.2; Pt.1":
  • Mini Theremin Mk.2 PCB [01207061] (AUD $15.00)
  • PCB pattern for the Mini Theremin Mk2 (PDF download) [01207061] (Free)
  • Mini Theremin Mk2 front panel artwork (PDF download) (Free)
Articles in this series:
  • Mini Theremin Mk.2; Pt.1 (July 2006)
  • Mini Theremin Mk.2; Pt.1 (July 2006)
  • Mini Theremin Mk.2; Pt.2 (August 2006)
  • Mini Theremin Mk.2; Pt.2 (August 2006)
Items relevant to "PC Controlled Mains Switch Mk.2":
  • Software for the PC-Controlled Mains Switch Mk2 (Free)
  • PCB patterns for the PC-Controlled Mains Switch Mk.2 (PDF download) [10107061/2] (Free)

Purchase a printed copy of this issue for $10.00.

Ever wanted to control switched 240VAC outlets with your PC? You can do it with this project which controls two 240VAC outlets. You can switch virtually anything, at any time under full Windows control. It uses your computer’s parallel port and virtually any old (or new) computer can do the job. Features: • Full optical isolat ion protection • Fuse and Power Surge protection • Control two GPOs independently • Control up to 16 GPOs (optional) • Up to 32 timing ev en • Simple PC parallel ts per GPO port connection • Automatically log all • All settings autom actions atically saved • Full access contr ol including passwo rd • Connection to PC required only for switching devices on and off PC-Controlled Design by Trent Jackson T Mkll cludes a password and user access his is the safest way to control level facility which means that the 240VAC appliances from your project could function as a low cost PC’s parallel port. security switch. We have used the parallel port as Interestingly, you don’t need to it is still the most cost-effective way keep your PC turned on permanently to control external devices. Using a is housed in a plastic box with two to control the project since the circuit 3-bit address, up to 16 240VAC mains flush-mounted 240VAC 3-pin sockets. uses latches to retain the switch setoutlets can be controlled from your There are four indicator LEDs under tings until they are changed by the computer using Windows 95, 98, 2000, a Perspex panel. Two of those LEDs incomputer. XP or ME. dicate when one or both of the outputs The PC-controlled Mains switch You can create up to 32 different are switched while timing events and the third indicates save them to a directhat power is present tory for later recall. in the PC switch itThe software will self. The fourth LED actually reload the indicates successful last used settings connection to your the next time that PC. you run the program. Block diagram Applications can Fig.1 shows the range from lightblock diagram of the ing and security to circuit. Eight optoifull-on home autosolators are used to mation. Fig.1: the circuit uses optocouplers for safe islation from 240VAC. connect the PC’s parThe software in80  Silicon Chip siliconchip.com.au Mains Switch allel printer port to the interface which decodes the port addressing and drives two latches, one for each relay. The relays then switch power the 240VAC sockets. The circuit All told, it is a simple concept although the full circuit in Fig.2 (overleaf) looks a lot more complex. So let’s break it down into bite-size chunks. On the lefthand side of the circuit is the 8-bit parallel port and each of the eight data lines is fed to its own optoisolator. Data lines D5, D6 & D7 are coupled via optos to IC1, a 74HC138 1 of 8 decoder which works in conjunction with an 8-way DIP switch. IC1 decodes the 3-bit binary code from the parallel port and pulls one siliconchip.com.au of its eight outputs low as result. The desired output is selected by switching one of the 8-way DIP switches on. The DIP switch outputs are connected WARNING This is a mains-powered device and many sections of the circuit operate at full mains potential and are therefore dangerous. This project should only be constructed by those experienced in mains-powered projects and the testing procedure detailed here must be fully complied with before connection to a PC. via eight diodes to the commoned emitters of optoisolators 5, 6, 7 & 8. So when the desired output of IC1 goes low, it enables the internal transistors of the above-mentioned optos so that they control the relays via IC2 and transistors Q1 & Q2. IC2 is a quad Schmitt trigger NAND gate which is configured as two RS latches or flipflops. Such flipflops have two inputs, Reset & Set; hence the name RS. Notice we can use “latch” and flipflop interchangeably here. They are called flipflops because the outputs can change from high to low or low to high when they received an R or S input and they are called latches because the output states are “latched” permanently until the next input occurs. Each RS flipflop is made of two cross-connected NAND gates and the R & S inputs are each driven by an July 2006  81 82  Silicon Chip siliconchip.com.au optoisolator – nice and simple. But while RS flipflops are simple they do need to be reset each time the power is turned on. This is achieved with diodes D15 & D16 and the associated 22mF capacitors and 220kW resistors. These work as follows: when power is applied, the 22mF capacitors at pin 5 & 13 (reset inputs) of IC2 are at 0V while pins 1 & 9 (set inputs) with just 39pF present can immediately go high. This sets pins 3 & 8 low and keeps transistors Q1 & Q2 off so the relays are unenergised. Subsequently, the 22mF capacitors charge up to 6V via the 220kW and so all the inputs of the latches are under the control of the optoisolators. When power is turned off, diodes D15 & D16 discharge the 22mF capacitors via the collapsed 6V rail. The use of these latches along with addressing ensures that if multiple units are connected to the one PC, the units can retain their switch states. Along with having three optos to control the addressing, four to control the set and reset lines of the two latches, an eighth opto is used to enable IC1. This in turn allows us to use a LED that indicates that the unit is indeed connected to the PC. When the unit is enabled, transistor Q3 becomes forward biased and in turn switches on LED4. On the facing page is Fig.2, the complete circuit diagram.Figs 3 (right) and 4 (below) show the component overlays for the display board and main board, respectively. Not shown on the overlay below is the heatshrink safety covering over the opto couplers. The numbers in green circles (below) correspond to the pin numbers on the D-25 connector. No ground connection Interestingly, the cathodes of all eight optos are not connected directly to the port’s ground return (pins 18-25). Instead, they are switched to ground via transistor Q4, itself controlled by the port’s strobe line (pin 1). Why is this so? The simple answer is that when a PC first boots up all of the lines on the printer port except for the strobe get toggled. If the optos all had their negative returns connected directly to the ground of the PC, the result would that the 240VAC outputs would be erratically switched on and each time you turn on your PC. So, by controlling the return path with Q4 and the strobe signal, the optos are only enabled when commanded by the software. Finally notice the 220W resistor connected between pins 10 & 18-25 on the parallel port D25 connector. This resistor tells the software that a unit is connected, so the software can then initialise and perform accordingly. The software is the real heart of this project while the electronics is just a siliconchip.com.au July 2006  83 dumb interface between the PC’s parallel port and the two relays. Power supply Two supply rails are required for the circuit. 6V for the CMOS ICs and a 12V rail for the two relays. These are derived directly from the 240VAC mains via a bank of three 470nF 250VAC class ‘X2’capacitors and a series 47W resistor, which feed the bridge rectifier. The rectifier’s output is filtered with a 2200mF capacitor and clamped to 12V with a 5W zener diode, ZD1. A 470W resistor and 6.2V zener diode, ZD2, are used to derive the 6V rail from the 12V rail. This 6V rail actually drops down to about 5V or so once under full load with both relays active and all of the LEDs on. Note that the 12V zener diode does not dissipate 5W. In practice, it dissipates 1W or less under the worst case conditions which apply when both relays are off. With both relays on, the 12V rail drops down to about 9V. The relays will actually operate down to 6V or less. Hence, by not having a well-regulated 12V supply we reduce overall power consumption and keep the worst-case power dissipation in ZD1 to a comfortable figure (ie, below 1W or thereabouts). Directly connected across the 240VAC mains line after the 10A fuse is a 47nF c apacitor and a varistor. The 47nF capacitor provides a small degree of filtering for the mains supply while the varistor protects the entire circuit against voltage spikes of more than 275VAC. A 1.2MW resistor connected across the 240VAC mains input and a 100kW resistor in parallel with the three 470nF capacitors ensures that when power is disconnected the capacitors are discharged. Note that by virtue of the bridge This photo of an early prototype has minor changes to the component overlay shown in Figs. 4 & 5 – follow the overlay in case of differences. This shot was also taken before the heatshrink was applied to the right side of the PC board and cable. 84  Silicon Chip siliconchip.com.au Fig. 5: follow this diagram carefully when completing the wiring. Remember that significant portions of the circuit are at mains potential so never work on the project when plugged in and/or without the cover screwed into place. rectifier (diodes D1-D4), the 12V and 6V supply rails are tied close to the Neutral line of the 240VAC mains, so provided you connect to a correctly wired GPO (240VAC socket), most of the circuit is nominally at low potential and quite safe. However, you cannot always depend on this and if your GPO or power cord has Active & Neutral wires transposed, most of the circuit will be at the full 240VAC potential and definitely not safe to touch. That is why we have incorporated the eight high-voltage optoisolators into the circuit. Construction The PC-controlled Mains Switch is housed in a plastic case measuring 196 x 112 x 62mm. The lid is used as the base of the case and has the main PC board mounted on it. The main PC board measures 185 x 104mm and is coded 10107061. Also there is a small PC board to mount the four LEDs. It siliconchip.com.au Computer connection is via a standard 25-pin D connector, which emerges from a cutout in the end of the case, This connector is internally earthed via a length of earth wire back to the mains earth on the PC board. July 2006  85 Figs. 6 (right) and 7 (above): full-size PC board artwork for the display board and main board, respectively. mounts on the bottom of the case, next to the two GPO sockets. A short 6-way ribbon cable with a 6-way connector links the boards together. A 25-pin D socket for the parallel port interface is mounted at one end of the main PC board. A cutout needs to made at one end of the case for this socket. Other cutouts in the case are required for the Perspex window for the four LEDs, the two GPO sockets, the mains fuse and the mains cord cable gland. Before you start assembly of components onto the main PC board, you should use it as a template to drill the lid of the case. You need to mark out the positions of the four Nylon screws and nuts to mount the board. Note: do not use metal screws and nuts to mount the PC board. Having drilled the lid, note that the main PC board also needs cutouts to provide clearance for the four corner pillars in the case. If your board does not have these, you will need to cut and file them. Then use the diagram of Fig.3 to guide you in the PC board assembly. Install the wire links first, followed by the resistors and diodes. Make sure that you install the diodes with correct polarity and ensure that zener diodes are in their correct positions. Next, install the capacitors, making sure that the electrolytics are correctly polarised. Then mount the 8-way DIP switch; note the orientation shown on Fig.3 and in the photos. Then you can mount the two relays, the varistor, the integrated circuits and the four transistors. Finally, install the 25-pin D socket, the 6-way polarised header connector for the LED board and the three 3-way insulated terminal blocks for the 240VAC connections. Do not make Resistor Colour Codes o o o o o o o o o No.   1   8   1   1   11   4   1   3   1 86  Silicon Chip Value 1.2MW (VR25) 220kW 150kW 100kW (1W) 4.7kW 1.2kW 470W 220W 47W (1W) 4-Band Code (1%) brown red green brown red red yellow brown brown green yellow brown brown black yellow brown yellow purple red brown brown red red brown yellow purple brown brown red red brown brown yellow purple brown brown 5-Band Code (1%) brown red black yellow brown red red black orange brown brown greenblack orange brown brown black black orange brown yellow purple black red brown brown red black red brown yellow purple black black brown red red black black brown yellow purple black black brown siliconchip.com.au any connections to 240VAC power at this stage. Next, assemble the LED board, as shown in Fig.4. This board measures 60 x 35mm and is coded 10107062. Four rectangular LEDs and two diodes need to be mounted as well as the 200mm long 6-way ribbon cable which is clamped to the board with a small cable tie. The ribbon cable is terminated in a 6-way plug to match the polarising header connector on the main board. Note that the ribbon cable should be sheathed in heatshrink sleeving, for extra safety. Testing with a DC supply When both boards are complete, they can be connected together via the ribbon cable but do not connect 240VAC to the main board. Instead, it can be safely powered from a variable DC supply capable of delivering between 14V and 16V or thereabouts so you can perform the tests needed without risk. Connect the positive lead to the junction of the three 470nF capacitors and the 47W resistor and connect the negative lead to the Neutral supply line. This connection will let current flow via the bridge rectifier to the 12V zener diode, ZD1. Apply power and you should be able to measure 12V across ZD1 and 6.2V (or close to it) across ZD2 and between pins 16 & 8 of IC1 and pins 14 & 7 of IC2. Assuming that all is as it should be you can now test out the logic on the unit by firstly placing DIP switch 8 in its ON position, with all the rest off. Then connect a wire between 0V and pin 1 of the 25-pin D connector. Now we are going to enable the unit by connecting a wire between the +6V rail and pin 6 of of the 25-pin D connector. This effectively enables the unit and LED4 should come on. If we briefly connect another wire between +6V and pin 4, this should cause relay 1 to switch on; you should be able to hear the click. Do the same with pin 3 and relay 2 should come on. To reset the flipflops and switch off the relays, briefly make a connection between +6V and pin 2 to de-energise relay 1 and between +6V and pin 5 to de-energise relay 2. You should hear both relays switch off. If you haven’t managed to get this far and hear the relays click on & off, siliconchip.com.au Parts List – PC-Controlled Mains Switch 1 main PC board coded 10107061 1 display PC board coded 10107062 1 2mm thick red perspex “window”, 55 x 14mm 2 DPST PC-mount 12V relays with 10A/250VAC contacts (RLY1, RLY2) 1 V275LA20A varistor (MOV1) (Altronics R 4408, Jaycar RN-3400) 1 D-25 PC-mount male connector (CON1) 1 D-25 male connector with backshell 1 D-25 female connector with backshell 2 panel-mount GPO sockets 3 3-way 10A/250VAC terminal blocks 1 3AG panel-mount fuse holder with 10A/250VAC slow-blow fuse 1 waterproof cable gland to suit 240VAC mains lead 2 14-pin IC sockets 1 8-way DIP switch (S1-S8) 1 ‘UB2’ size jiffy box 2 M3 x 10mm (or 12mm) untapped Nylon spacers 4 M3 x 12mm Nylon screws 2 M3 x 20mm Nylon screws 14 M3 Nylon nuts 600mm length of brown and blue 10A/250VAC cable for mains wiring 850mm length of green/yellow 10A/250VAC cable for mains wiring 400mm length of 0.7mm tinned copper wire for links 300mm length of 6-way rainbow cable 2m length of 9-way shielded data cable 220mm length of 10mm diameter heatshrink tubing 70mm length of 85-100mm diameter heatshrink tubing 1 240VAC mains lead with moulded 3-pin plug Semiconductors 6 1N4007 diodes (D1-D6) 12 1N4148 small signal diodes (D7- D18) 1 12V 5W zener diode (ZD1) 1 6.2V 1W zener diode (ZD2) 4 5 x 2mm rectangular red LEDs (LED1-LED4) 8 SFH601-3 or CNY17-3 optocouplers (OPTO1-OPTO8) (do not substitute) 2 BC548 NPN transistors (Q1, Q2) 1 BC558 PNP transistor (Q4) 1 MPSA65 PNP Darlington transistor (Q3) (DSE Z-2088) 1 74HC138 1-of-8 decoder (IC1) 1 74HC132 quad NAND gate (IC2) Capacitors 1 2200mF 16V PC electrolytic 1 100mF 16V PC electrolytic 2 22mF 16V PC electrolytic 2 10mF 16V PC electrolytic 4 100nF 50V MKT polyester 2 39nF 50V MKT polyester 3 470nF 275VAC class ‘X2’ polyester 1 47nF 275VAC class ‘X2’ polyester (code 104, 100n or 0.1) (code 393, 39n or 0.39) (code 474, 470n or 0.47; X2) (code 473, 47n or 0.047; X2) Resistors (0.25W 5%) 8 220kW 1 150kW 11 4.7kW 4 1.2kW 1 470W 1 100kW 1W 1 47W 1W 1 1.2MW VR25 (do not substitute) (Farnell 947-7152) 3 220W Note: the SFH601-3 optocoupler is available from Wiltronics Research, phone 1800 067 674 or see www.wiltronics.com.au. The alternate CNY17-3 is available from Farnell (stock no. 359-8380), phone 1300 361 005 or see www.farnellinone. com.au. Large bore heatshrink is available from www.batterypower.com.au (choose the 125mm flat width product) or your local electrical wholesaler. July 2006  87 The completed project with heatshrink fitted for safety (in the unlikely event of a mains lead “letting go”). Once again, there are some minor component differences between this and the overlay diagrams of Figs. 4&5 shown earlier. If in any doubt, follow those diagrams! don’t go any further with the project until you do. Get some assistance if need be. The case When the PC board is fully checked out, the 240VAC mains wiring for the unit can be done and the rest of the assembly completed. Before proceeding though, you will need to do some more work on the case to provide the cutouts for the 25-pin D socket (in the end of the case), the two GPO sockets, the window for the LED board and holes in the other endo the case for the mains cable gland and the fuseholder. The LED window needs to be 55 x 14mm while the holes for the cable gland and fuseholder are 12.5mm in diameter. Fig.5 shows the complete wiring diagram. All the mains wiring must be run in 250VAC-rated wire and it should be tied in place with cable ties as shown. Don’t forget to run the green/yellow earth wire on the main PC board. This earths the 25-pin D socket. 88  Silicon Chip When all the wiring is complete, you need to fit pieces of heatshrink, to prevent the admittedly unlikely event of a mains wire coming loose and touching the PC side of the optos. The photo above shows the completed project, with both pieces of heatshrink fitted. First, a sleeve of heatshrink is fitted over the entire socket end of the board. After sliding the heatshrink over the D-socket and PC board (back as far as the row of resistors adjacent to the opto isolators) it must of course be shrunk into position. A hair dryer on highest heat should be able to do this but a heat gun will be better (but be careful with those – they can easily melt plastic or damage other components!). After fitting, a small amount of minor surgery will be needed – the corners have to be trimmed out with a sharp knife or blade to match the PC board profile underneath, allowing the PC board to fit into the case. Also, two holes need to be punched or drilled through the heatshrink to allow the mounting screws to pass through. A much thinner length of heatshrink should be used to shroud the ribbon cable between the main and display PC boards. Reality check You should make a few last checks before you connect the PC switch to your computer’s parallel port and power up. First, do a continuity test between Active & Neutral on the power lead with your DMM: if you get a reading of about 1.2MW, you’ve done well. Again with your DMM, make doubly sure that the Earth pin of the plug is connected through to the shell of the D25 socket. Finally, make sure there is no circuit between Active & Earth and Neutral & Earth. If, and only if, all those tests are satisfactory, proceed with loading the software and moving on to the setting up of your PC-controlled switch. siliconchip.com.au Driving the Controller First thing, load the setup for the parallel port. The most usual software (imaginatively named port address for LPT1 is H378, setup.exe; downloadable in a while LPT2 is usually H278. zip file from siliconchip.com. The H3BC base address was au). originally introduced used for Follow the install prompts parallel ports on early video cards. and get the main interface This address then disappeared for program (shown at left/right/ a while, when parallel ports were indifferent) on the screen. later removed from video cards. Assuming that you have They’ve now reappeared somewhat done all the testing as detailed as an option for parallel ports inearlier and given the board a tegrated onto motherboards, upon final sanity check, connect the which their configuration can be unit to your PC’s parallel port changed using BIOS. via a suitable cable (ie, straight One small wrinkle: the PC Conthrough, pin to pin) and power trolled Mains Switch requires the up. use of an “Enhanced Capabilities” By the way, you can dummy- This is the screen which should greet you once the (ECP)-enabled parallel port and at run through the software setup software is loaded and run . . . least originally, H3BC did not supwithout a unit connected, just to see what does what. port ECP. If you have problems with your controller, check that you Click on GPO A’s “manual on” button – it’s at the bottom right have the port set up for ECP and it is a valid address. of GPOA’s panel. Immediately you should see a couple of changes: If the unit’s adthe “LED” image below the switches changes from black to red, dress (set by the while a lightning bolt symbol appears across GPO A - both saying DIP switches) is that GPO A is on. still set to 8, seYou should also see a system message appear in the box at the lect unit 8 on the base of the screen saying, for example, “GPOA Switched ON <at> software, click 06:06:06 06-06-2006” Devilishly clever, what? on the “ON” butNow try the auto part: check your exact system time (double ton for GPO A click on the time at far bottom right of the PC screen). You might and the relay for like to correct the time now if it is out. GPO A should Select a time which is, say, a minute from the current time and click on and the enter it, in 24 hour format, into either GPOA or GPOB along with associated LED the date in DD/MM/YY format, into the “Start Date & Time” panel. should light. Alongside this, enter a stop date and time in similar manner – Now do the same for GPO B: click on the “ON” button and the make it, say, a minute later. Click the “ADD” button and all these other relay should click on and the LED for GPO B should light. details will appear in the appropriate GPO’s window. Now try selecting a few different addresses on the DIP switch and When your PC’s clock changes to the selected minute, you will ensure that all of the logic circuitry is working as it should be. again see the red “LED” and lightning bolt, showing the outlet is This done, you can finalise the settings on the software by setting turned on – and naturally the reverse when it turns off. SC up the access control part, assuming that this is required. Password protection Unless your PC, the Controller and all controlled devices are locked away, password protection would seem to be a bit of overkill (what’s to stop someone pulling a plug, or connecting to another [uncontrolled] outlet?). Still, the option is there, at the bottom of the screen, should you ever need it. The “keys” symbol allows you to log on and off, while the “heads” symbol allows you to set up access control. Parallel port and address The software gives you the option of three different addresses siliconchip.com.au July 2006  89