Raspberry Shake

Ever got yourself so absorbed in an evenings TV binge that you’ve accidentally forgotten about a load of washing, and left it to fester in the machine overnight? Need a subtle reminder to take the towels out of the dryer? Wishing that you could connect your dishwasher to the Internet of Things? Then the Raspberry Shake is for you!

The basics

This project boils down to a simple accelerometer hooked up to a Raspberry Pi Zero, put inside a case that can stick to a washing machine/dishwasher/dryer or anything else you can think of! A simple Python script runs on the Pi to monitor the forces being exerted on the accelerometer, and send notifications when it determines that the appliance has started and finished. In this build I’ve just made it light up some LEDs and then send a notification via Pushover, but you could easily hook up a buzzer or other components to really make a noise! This is a very cheap and simple build, requiring only a few components and the most basic building, programming and electronics knowledge.

The components

I had most of the components for this project lying around already, so I don’t know the exact cost, but I’d estimate it to be under £20 (~$30USD) – it’s a cheap enough build that I’ve made two, with plans to make a third.

The build

I recorded myself putting together my second Raspberry Shake (the first involved too much swearing and a little bit of fire) – the video can be viewed here

The software

The hardest part of this project was getting access to the data from the LIS3DH sensor in Python, since there wasn’t a pre-existing library. However, I’ve already solved that problem! You can read about that part of the project here, and find the resulting code on GitHub.

I’ve also published the Python code for monitoring the sensor and sending notifications – it’s available in my projects repository. You may find the shaker.py code useful, it contains a thread that monitors an instance of the LIS3DH library described above, and a class that can interpret the results of that into “hot” and “cold” (appliance running and not-running) states, making the appropriate callbacks. The Appliance.py file is designed to be run from the command line, or through something like Supervisord, and contains the callbacks to send notifications on my network – they won’t be much use to you!

The future

I don’t think there’s much more tweaking I want to make to the units I’ve already put together – I’m very happy with them being “set and forget” type sensors. However, there are plenty of opportunities for expanding this, such as:

  • Connecting a speaker/buzzer to make noise when the appliance finishes
  • Connecting a button to silence the noise-maker
  • Using different types of sensor (such as heat to check if an oven is on, light to check if the fridge door is open, and many more)

Once your appliances are part of the Internet of Things then the only limit is your imagination!

The conclusion

While this project was nowhere near as involved as the AlarmPi I made previously, I thoroughly enjoyed putting this together – and I think it would make a fantastic (and cheap) introduction for anyone wanting to get started playing with the endless possibilities for GPIO development on the Raspberry Pi.

I’d love to hear about any projects inspired by this – please leave links and details in the comments below!

12 thoughts on “Raspberry Shake

  1. Pingback: Talking to a LIS3DH via Python on a Raspberry Pi | Matt Dyson

  2. Pingback: Raspberry Shake: IoT for your boring appliances | Matt Dyson

  3. I’m Deaf and this seems like an interesting technological solution for my dryer. It seems a bit complicated for me to put together so I wonder if there’s anything like this that’s available for purchase?

    • Hi Colin,
      It’s a very simple build, as you can see in the video – the LEDs are connected to GPIO pins, and the LIS3DH is connected over I2C.

  4. Matt,

    I tried using SW-420 vibration sensors but that approach failed. I kept getting “cross-contamination” when the washer and the dryer were both running. I could never quite get the vibration thresholds set even when only one machine was running. Do you think your accelerometer approach can be tuned more specifically to avoid it picking up motion from the wrong machine?

    So, I already have the Pi ZeroW (so no need for the additional dongle) I’m going with a power monitor for the washer. Hedging my bets on which approach works. I’ve ordered a LIS3DH to give this a try on my dryer. You mentioned in one of your responses above that the hookup is fairly simple. Would you mind adding a wiring diagram with pin-outs to your blog (or to the GitHub repository)? I’m still pretty inexperienced with all of this and would definitely appreciate the additional information… so I don’t end up with a bit of fire of my own 😉

    Cheers!

    Mike

    • Hi Mike,
      The LIS3DH is connected over I2C – so just requires connection to the 3.3V, Ground, I2C data and I2C clock. You can read a bit more about them at https://pinout.xyz/pinout/i2c

      You can play about with the sensitivity in the Appliance.py code I’ve linked above – hopefully this should be enough to tweak it so you’re not picking up other nearby motion.

      Good luck!
      Matt

      • I have everything operational. LIS3DH & Pi wired, your code libraries installed (with a couple of required tweaks due to Python 3 and Adafruit I2C library updates). I took my old vibration module and plugged Shaker into it and I was off to the races. I ran through a cycle with me shaking the LIS3DH with my hand to watch it activate and deactivate. So kudos for the tutorial and the great code!

        Now that I’ve buttered you up… 😉 Help!

        My appliance (a clothes tumbler), does not shake enough. The X/Y/Z readings never go above 1. Thus the rate remains pegged at 0. Before I go and change the driver to lower the sensitivity (you take a parameter and add 1 to it), I wanted to ask you if there was a technical reason why the sensitivity (magnitude) has to be greater than 1. Do you have any suggestions on how best I could handle my situation (my dryer shakes, but only lightly)? Any insights are greatly appreciated.

        Regards.

        • So, I passed a negative value for the sensitivity. It sets the “absolute” sensitivity value that the vibration looper checks to a value under 1 which triggers the metering.

          I also ensured that the LIS3DH module was as parallel with the X/Y/Z axes to ensure at least one direction measured the maximum effect of the dryer vibrations. Which caused me to think… to avoid sensitivity to the mounting direction, would taking the vector magnitude math.sqrt(x**2+y**2+z**2) rather than relying on one axis to trigger the threshold be more foolproof?

          Regards.

          Mike

Leave a Reply

Your email address will not be published. Required fields are marked *