I was lying in bed sick over the weekend, contentedly watching old Firefly episodes, when something horrible happened. I remembered that I had a load of clothes in the dryer and I was going to have to get up, walk across my apartment like a caveman and use my own eyeballs to check if the dryer was done. After that ordeal I vowed to come up with a way to make sure I never had to go through that again. Fortunately Kookye recently sent us their Raspberry Pi IoT Starter Kit which has all sorts of easy-to-use sensors along with example code to get started. If you are interested in smart home projects make sure to check out the review we did of this kit a while back.
I was sure that something in there would let me check on the dryer without getting off the couch. I noticed that the kit included a vibration sensor and, because my dryer is old and shaky, I decided that would do nicely. My plan was to attach the vibration sensor to the side of the dryer and have the Pi host a website that I could look at on my phone to check whether the dryer was done. Before we get started here is a screenshot of the final result:
The first step is to hook up the vibration sensor to your Pi. The vibration sensor is really easy to use with just 3 pins: ground, Vcc and a digital out. The digital out will go high when vibration is detected and low when it is sitting still. You can adjust the sensitivity using a screwdriver.
If you don’t need the whole kit you can buy just this sensor, but if you want to try out more than a few of the sensors then buying the kit will probably end up being cheaper. I will be using GPIO 21 on the Raspberry Pi 2 B+ as shown below. You can use any pin you want but you will need to change a constant in the Python script. Also the pin numbering scheme on your Pi may vary slightly depending on which version you have.
Now all we need to do is poll GPIO 21 to check whether vibration is going on. I ran some tests to see how sensitive the sensor is and the answer is: not very. I set it up to measure 100 times a second for 10 seconds while the dryer was running. I repeated that test a few times and got the results below. low:929 high:61 low:942 high:48 low:943 high:47 low:945 high:45 low:952 high:38
Even while the dryer is vibrating it won’t register most of the time. That said, it is still easily sensitive enough to work for what we are trying to do. We don’t need to check whether the dryer is on every millisecond, we can measure the vibrations over a period of seconds and if it detects any vibrations during that period we can be pretty confident that the dryer is running. This is because while the vibration detector will sometimes tell us there are no vibrations while it is in fact vibrating, it will never tell us (at least it didn’t in my tests) that it is vibrating while it is actually sitting still.
Using the Python GPIO library is pretty simple. Just a few functions will get us up and running to put it in input mode and read the value. First the init_gpio method is used to set a pin as input:
And finally a function that will call our polling function in a loop and write the results to a file. Our website will pull data from that file and display it. For the sake of simplicity, if the vibration detector saw a vibration on even 1 sample during our 10 second measurement period we will say that the dryer is running.
I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.