Category Archives: Uncategorized

Emulate all the things

The clothes washer stopped working and would get stuck waiting forever for the water to fill up so it could agitate or spin.

It turned out that it has a vertical tube in the basin beside the drum which fills up with water alongside the drum; a hose connects this to a pressure switch with a rubber diaphragm, and as water fills the tube, it displaces the air into the switch until the pressure is enough for the diaphragm to push a set of electrical contacts together, which tells the sequencing mechanism it’s time to move on the the next part of the cycle.

This pressure switch seemed to have stopped working sporadically, or at least it would work on the initial fill but always fail after the water drained and tried to refill for the rinse cycle. The washer repairman came and tried a few things and left, saying he’d try to find a replacement but it could be a while since his usual sources were closed.

I had an automotive MAP (manifold absolute pressure) sensor lying around and tried moving the washer’s air hose from the mechanical pressure switch to the MAP sensor. Watching the output of the MAP sensor I could see that while the MAP sensor’s range wasn’t a great match it was probably good enough since I got a range of maybe 30 discrete values from empty to full on the esp32’s kind of weird ADC.

The first attempt was just energizing the relay on the esp32 board when the ADC reading reached a high threshold and then de-energizing it when the reading reached a low threshold. This ended up not working well because the ADC output was pretty noisy both because of electronics and because the air pressure fluctuates quite a bit as the washer drum churns and spins.

A couple of refinements were needed: first, since the MAP sensor reads absolute pressure, not pressure relative to ambient atmospheric pressure, I had to come up with a workable baseline pressure value, and a way to reset it in case there were major changes in atmospheric pressure. This is acheived by measuring absolute pressure on startup and from then on working with values relative to that. Power cycling the board makes it re-measure its baseline pressure. A relative pressure sensor would make more sense but the whole point here was to use what I had.

Second, the ADC data needed smoothing and cleanup. I imposed a floor of 0 (relative) on the measured value and it now maintains a several second moving average against which the thresholds are compared. This keeps noise in the readings from triggering rapid relay switching and the actual trends in the data are preserved.

With these changes it detects the full and empty conditions completely reliably and the washer works exactly like it did before the mechanical switch failed.

The third revision just adds instrumentation and remote control. It has wifi that can be set up via a mobile app, announces itself as “washingmachine.local” via mDNS, sends every reading via UDP to a collector for graphing, and has an http API server that lets you query the thresholds and current pressure value, change the on and off thresholds on the fly, and trigger a reset. The valve emulation also has to operate completely independently of the nework so it doesn’t stop if wifi or internet connectivity fails.

Now the washer works just like it used to, but you can also, for example, get an email when your laundry needs to go in the dryer, and you can set the fill level for large or small loads to save water.