The device uses an ESP32 microcontroller. In this case I am using the Lolin32 development board by Wemos which you can buy on AliExpress for about $7. The accelerometer is the Sparkfun LIS3DH - it's important the accelerometer is digital rather than analog as you will see later. The battery I took from a old set of bluetooth speakers.

The ESP32 connects to the accelerometer via I2C. The first version of the code simply polled the three acceleration axes (x, y and z) for the measured acceleration value every 20ms. Placing the breadboard prototype on the washing machine and I produced the above graph which shows acceleration peaks during various phases of the wash cycle. Those peaks where absolute acceleration was greater than 125mg (125 thousandths of normal gravity) are shown in orange. We want to detect these periods and use them to determine the status of the washing machine.

How to determine if the machine is on or off?

One of the goals of building this device was that it would be entirely passive. I.e. no buttons should need to be pressed; it would just work. It also should be very low power as it was not really possible to extend power cables to the washing machine in my case.

Luckily the LIS3DH accelerometer has a feature where it can trigger an interrupt when acceleration exceeds a given threshold (note, this requires use of the accelerometer's built-in high-pass filter - see the code on Github for details) and the ESP32 can be woken up from its deep sleep mode via an interrupt. We can use this combination of features to create a very low power sleep mode that is triggered by movement.

The pseudo code would look something like this:

# Device wake up notification_threshold = 240 counter = 10 accelerometer.set_threshold(96) #96mg while counter > 0: if accelerometer.above_threshold(): counter++ else: counter-- if counter > notification_threshold: # final spin cycle detected sleep(1 second) accelerometer.set_threshold_interrupt() esp32.set_wakeup_trigger_on_interrupt() esp32.deep_sleep()

You can see here that we use a counter to detect how many seconds of acceleration we have detected during the current wake period. If the counter drops to zero then we can put the device back to sleep. If the counter reaches 240 (the notification threshold) then that means we have detected 4 minutes of vibration. We can tweak the values of these thresholds to make sure the device correctly detects the final spin cycle. Once sufficient vibration is detected, we can simply sleep for another 5 minutes (in my case this is how long it takes until the wash actually completes) before sending a notification.