Computer-Controlled Washing Machine
I've got this automatic washing machine, you see.... and one day the
electronic controller decided to fry itself, and so it stopped working! :(
I couldn't bring myself to throw it away - all the bearings, motors and
solenoids were still in excellent condition, but a new controller would
have cost much more than a good second-hand machine in similar condidion!
So..... I found an old 386 computer (with no hard drive) lying in the shed,
and after a bit of searching on the internet, found out how to use the
printer interface to turn relays on and off! The circuit was fairly simple,
and the software to drive it was a piece of cake to understand.
The following is a simplified version of the truth, and I know that there
is much more to it than this - but for those of us who just want the thing
to WORK and are not too worried about the details...
The printer port on most IBM-Compatible computers exists (as far as the
computer is concerned) as an OUTPUT port at a certain address, and as an
INPUT port at that address + 1.
This means that, if we send a piece of data
to the OUTPUT port, the data appears on some of the pins of the printer port,
and if we read the data from the INPUT port, we can tell the state of certain
other pins of the printer port.
We can use the OUTPUT lines to turn relays on and off, which can in turn
switch the motors and solenoids of the washing machine on or off under
program control. We can use the INPUT lines to tell if the "WATER FULL"
sensor is on or off, or the "LID OPEN" sensor is on or off.
The most common addresses (in decimal) for the printer port are:
956 - for most 386 computers, e.g. COMPAQ 386
888 - for most 486 computers
632 - for most 286 computers (with hercules video/printer cards)
I found the address (956) used by my old COMPAQ 386 by trial and error.
I tried each of the addresses above until I found the right one. (There
is a way of asking the computer which address it uses, but I didn't
Then I did some experimenting. I used a 25-pin male D-connector, which
plugs into the printer port at the back of the computer. This plug has
a 1.5 metre length of ribbon cable attached, and I could easily identify
which wire came from which pin of the D-connector. The wires I was
interested in are the following:
Pins 2-9 - Data OUT D0-D7 (These are my 8 OUTPUT wires)
Pin 15 - Data IN S3 (S3 means "Status" bit no 3)
Pin 13 - Data IN S4 (Status bit 4)
Pin 12 - Data IN S5 (Status bit 5)
Pin 10 - Data IN S6 (Status bit 6)
Pin 11 - Data IN S7 (This one's value is back to front, as you'll see)
Pins 18-25 - Ground
I used a hobbyists breadboard strip to connect up the following
circuits for testing the outputs and inputs:
Testing the OUTPUTS
After connecting the circuit to test the OUTputs, I plugged it in, turned
the computer on (watching to see if any smoke came out!!!), and
wrote the following little program in QBASIC. It asks the operator for
a NUMBER (from 0 to 255), and OUTputs that number to the printer port (956
in my case - you'll have to try ports until it works for you...)
INPUT "WHAT NUMBER (0-255)?";NUMBER
To stop the program, you'll need to press [CTRL]-[BREAK]
You'll notice that each number you enter causes different sets of lights
to switch on... The lights are a BINARY representation of the number you
enter, for example,
If you enter 255, then ALL the lights switch on (Binary 11111111)
If you enter 0, then NO lights switch on (Binary 00000000)
If you enter 6, then the lights D2 and D1 switch on (Binary 00000110)
You see, 6 is 4+2, and D2 represents 4, and D1 represents 2.
(It goes: 128,64,32,16,8,4,2,1 for D7,D6,D5,D4,D3,D2,D1,D0)
Perfectly logical, isn't it?
So if you enter 25, (which is 16+8+1), you get D4,D3,D0, which is 00011001
It's rather fun getting the computer to FLASH the lights on and off at
intervals, under automatic program control - have a go, you'll be
How to get the computer to PAUSE between flashes
While I was playing with this idea, I realised that when the lights flashed
on and off, it happened so fast that I couldn't see what was happening. So
I had to work out how to make it pause for a second or so between turning
lights on or off....
I made use of the TIMER function in QBASIC to read the computer's clock
at a given moment, then to wait until the timer had clicked on for another
second or so before going on. Here's an example:
REM Switch on the lights
REM Now read the TIMER and wait until it advances 1 second
loop1 = TIMER
WHILE TIMER - loop1 < 1
REM Switch off the lights
REM read the TIMER again, and wait until it advances 1 second
loop1 = TIMER
WHILE TIMER - loop1 < 1
REM repeat this until you stop it
Testing the INPUTS
When I was sure that I understood the outputs, I had a go at the inputs.
My first program to test the inputs looked like this:
INPORT=957 : REM NOTE THIS IS ONE MORE THAN THE OUTPUT PORT
This program printed the number "135" down the left side of the screen.
(Which is 128+4+2+1, or S7,S2,S1,S0).
Now, when you press the following switches, you get the following results:
Switch S3 produces "143", which is 128+8+4+2+1, or
S7,S3,S2,S1,S0 (Note that 8 has been added to our "135" to get 143)
Switch S4 produces "151", which is 128+16+4+2+1, or
S7,S4,S2,S1,S0 (Note that 16 has now been added to 135)
Switch S5 produces "167", which is 128+32+4+2+1, or
S7,S5,S2,S1,S0 (Note that 32 has now been added to 135)
Switch S6 produces "199", which is 128+64+4+2+1, or
S7,S6,S2,S1,S0 (Note that 64 has now been added to 135)
Switch S7 produces "7", which is 3+2+1, or
S2,S1,S0 (Note that 128 has now been Subtracted from 135, which is
the wrong way round - as I referred to right at the start...)
You'll also notice that S0,S1,S2 are always ON, and we don't have any way
of controlling these ones with our circuit. We can only control 5 of the
input pins easily, but we only need two, so that's not important.
I wrote a second program to test the inputs, one which would tell me which
of my 5 switches has been pressed at any time.
The program inputs the data from the port, then by subtracting the powers
of two from this data, works out which bits are ON and which are OFF.
(It subtracts 128, 64, 32, 16, 8, 4, 2, 1, after deciding if the number
which is left is big enough..... have a good look, it's fairly nifty!)
Then the program prints the names of the switches which are ON, and loops
over again and again, until you stop it.
inputbyte = INP(inport)
FOR i = 0 TO 7
inbit(i) = 0
inbit(7) = 1: REM This one is back to front..
IF inputbyte >= 128 THEN inbit(7) = 0 : inputbyte = inputbyte - 128
REM All the rest are the right way round..
IF inputbyte >= 64 THEN inbit(6) = 1 : inputbyte = inputbyte - 64
IF inputbyte >= 32 THEN inbit(5) = 1 : inputbyte = inputbyte - 32
IF inputbyte >= 16 THEN inbit(4) = 1 : inputbyte = inputbyte - 16
IF inputbyte >= 8 THEN inbit(3) = 1 : inputbyte = inputbyte - 8
IF inputbyte >= 4 THEN inbit(2) = 1 : inputbyte = inputbyte - 4
IF inputbyte >= 2 THEN inbit(1) = 1 : inputbyte = inputbyte - 2
IF inputbyte >= 1 THEN inbit(0) = 1 : inputbyte = inputbyte - 1
IF inbit(7)=1 THEN PRINT "S7";" ";
IF inbit(6)=1 THEN PRINT "S6";" ";
IF inbit(5)=1 THEN PRINT "S5";" ";
IF inbit(4)=1 THEN PRINT "S4";" ";
IF inbit(3)=1 THEN PRINT "S3";" ";
IF inbit(2)=1 THEN PRINT "S2";" ";
IF inbit(1)=1 THEN PRINT "S1";" ";
IF inbit(0)=1 THEN PRINT "S0";" ";
Testing the Washing Machine Components
Now this bit is DANGEROUS
If you're not comfortable working with 230 volt AC wiring, then DON'T
TRY THIS AT HOME!
But if you're like me, and have had some experience with these voltages,
then it's probably ok to continue...
I STRONGLY RECOMMEND THAT YOU USE A RESIDUAL CURRENT DEVICE (RCD)
TO PROTECT YOU AGAINST ELECTRIC SHOCK!! No, actually, I don't just
strongly recommend, I insist! - An RCD is cheap, and will save
your life if you accidentally touch a live contact. It works by detecting
"leakage" current flowing to earth through your body. It then trips the
switch before any lethal current can flow through you.
I had a careful look at the wiring inside the washing machine, and found
that each component I wanted to switch on and off had TWO wires going to it,
ONE OF WHICH WAS YELLOW. (Except for the Brake Solenoid, as you will
I worked out that the Yellow wire was the NEUTRAL wire, and the other was
the switched PHASE wire in each case. (The controller will need to turn
the PHASE line on and off for each component.)
I disconnected all the phase wires from the existing controller, and
labelled which one went where: Cold water Inlet, Hot water Inlet, Drain
Pump, Agitator Motor 1, Agitator Motor 2, and Brake Solenoid.
To explain about the Agitator Motor: This is a reversible motor, which has
THREE wires going to it. One is YELLOW (Neutral) and the other two
represent Clockwise and Anticlockwise Phases.
The Brake Solenoid (which releases the drum so that it can spin) is another
special case - this has two wires going to it, but NEITHER of them is
yellow! I figured out that the solenoid must work on DC, not AC - so I'll
need a rectifier - see later....
Now comes the dangerous bit: I wired up a flying lead to the PHASE side of
the main on/off switch on the washing machine, so that I could turn it on
and supply power to each component one at a time.
I connected the flying lead to the phase side of each component in turn,
switched on, and found that everything worked just fine.... The Inlet
Solenoids went "click", the Drain Pump spat water out of the drain hose,
and the Agitator went clockwise or anticlockwise. But the Brake Solenoid
just went "BUZZ!" when I tried it with Phase and Neutral across the two
So I "borrowed" a fairly hefty bridge rectifier from the local electronics
shop (400V, 5A) and wired it up like this:
I connected the flying lead and one yellow Neutral wire to the AC input
side of the Bridge Rectifier, and the two leads from the Brake Solenoid to
the DC output side. When I switched on, it made a decent "CLACK" sound as
the brake released. Good.
Note that there is a "freewheeling" diode connected backwards across the DC
outputs of the Bridge Rectifier - THIS IS IMPORTANT, because when the
solenoid switches OFF, it produces a BACK EMF as the magnetic field
collapses. This back emf can build up to many hundreds of volts, and can
destroy the diode bridge. The freewheeling diode allows current to flow
through the coil of the relay instead of building up a large potential at
the terminals of the diode bridge, and the energy is dissipated harmlessly.
Connecting the Computer Outputs to the Washing Machine Inputs
We're dealing with very different voltages here... Obviously we need a
way of switching on 230 Volt relays, using the 5 Volt outputs of the
printer port. It's fine to turn on LEDs, because they draw only milliamps
of current, but a relay which is suitable for switching the Agitator on or
off needs a reasonably hefty input current to make it go Click!
The answer to this dilemma is to use a separate 12Volt supply (to provide
the switching current to the relays) and to use transistors to control this
current. Thus we use a computer output line(5V, 2mA) to turn a transistor
on, which acts as a 12Volt 200mA switch which in turn switches on the
230Volt output Relay. Neat, huh?
So here's a circuit diagram. It's not brilliant, and it can certainly be
improved, but I believe it combines simplicity with a reasonable amount of
protection. You'll note that there are "freewheeling" diodes across the
relay inputs, for the same reason as described above, and there are diodes
in line with the computer outputs, to give some protection against reverse
voltages which would destroy the printer output port. (In case a transistor
fails for example, which could allow 12V back into the printer output
... This project description isn't finished yet...
It will have more details on how to program the washing machine!
Back to Main Page