|
||||||
Using Home Computers to Control Household DeviceInterfacing a Computer Parallel Printer Port
Home computers may be used to control household lighting, heating, or any other device that uses an electrical switch. Up to eight devices or circuits may be controlled.
A laptop, Personal Computer, or any device with a printer port may be interfaced to external devices or circuitry. This application has many uses, such as controlling greenhouse heating or lighting, driving a motor or pump, and so on. Up to eight circuits may be controlled from one printer port. There are two key components: software to control the switching, and an electronic interface to connect the computer to the external switching circuit. How Interfacing Software WorksThe parallel printer port on the PC has 8 lines, and by convention these are referred to as bits 0 to 7, and they represent an 8-bit binary number. They are all initialised at OFF, by writing the number zero to the printer port. The section "Software to Control Device Via PC" describes how to do this. Converting Binary Numbers to Decimal NumbersIn the most simple case, where only one device needs to be controlled, the only numbers sent to the printer port are 0 and 1, so no binary to decimal conversion is needed. If a known combination of switches needs to be set, let OFF be represented by 0, and ON be represented by 1. For example, switch on the heating(switch 0), lighting (switch 1), and humidifier (switch 2). The binary number is 111, and it can be converted using the Microsoft Excel function BIN2DEC(111), and will return the number 7. To set the three switches, simply write the number 7 to the parallel printer port. For a more complete description of decimal and binary conversion, see Decimal, Binary, Octal and Hexadecimal Number Systems. Software to Control Device via PCThis can be written in any language, but the programming language C / C++ is used here. The laptop or PC needs to be loaded with the software that controls the output or outputs. #include<stdio.h> /* Use the Standard Input and Output library*/ #define LLEL_ADDR 0x378 /* Define the hexadecimal address of the parallel printer port */ void main(void) { outportb(LLEL_ADDR,0); /* Initialise all devices to OFF*/ while() /* Enter the conditions to wait for e.g. Wait for 6 hours */ { }; /* Do nothing */ outportb(LLEL_ADDR,7); /* Switch on bits 0, 1 and 2 (For example) */ while() /* Enter the conditions to wait for e.g. Wait for 18 hours */ { }; /* Do nothing */ outportb(LLEL_ADDR,0); /* Switch all devices to OFF*/ } /* End of Main */ This example shows how to do the cycle once. For timer control of household devices that need to be switched at certain times every day, a loop could be used: do{} while(); Interfacing the Parallel PortFigure 1 shows the circuit needed to interface one line from the parallel printer port to a small motor. If all that is needed is to switch on a plug socket to operate mains-operated equipment, then only the opto-isolator is needed, connected to a solid state relay. A 12 Volt supply is needed, and can be obtained cheaply. On a standard 25-pin parallel port, pins 2 to 9 (i.e. bits 0 to 7) can each supply about 5 volts when switched on. Each line from the printer port needs to be completed by attaching it to the PC ground, and these can be found at pins 18 to 25 of the 25-pin printer port. The component values used are typically:
Transistor TIP141 is heavy-duty darlington pair that can drive a small motor. The motor M may be replaced with a solid state relay (SSR) that is used to switch on any mains electricity. If a relay will be used to switch on household devices, then the circuit will change, as described in the article Computer Control of External Devices Using a Relay should be consulted. Summary of Interfacing PC to External DeviceHome computers, laptops, and even PDAs have a wide range of uses to control switching devices in the home, garden, greenhouse or other areas. It is a simple task to program and wire the computer to an external device or circuit via the parallel printer port, with readily available components.
The copyright of the article Using Home Computers to Control Household Device in Computer Engineering is owned by Martin Bell. Permission to republish Using Home Computers to Control Household Device in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||