Web Enabled Dryer Monitor for the Raspberry Pi

This is a BreakoutBros.com tutorial. Please go here for source code or questions you may have.

web-enabled-dryer-monitor-for-the-raspberry-pi

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.

kookye-smarthome-kit

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:

website-1-1024x244-png
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.

vibration-sensorIf 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.

dryer_monitor_schematic

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:

def init_gpio_input(bcm_pin):
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(bcm_pin, GPIO.IN)

Let’s define another function to poll the GPIO over the course of a few seconds and return the number of times it was high and low:

def poll_gpio(duration_secs, frequency_hz, input_pin):
    start_time = time.time()
    end_time = start_time + duration_secs
    count_high = 0
    count_low = 0
    while time.time() < end_time:
        if GPIO.input(input_pin) == 0:
            count_low += 1
        else:
            count_high += 1
        time.sleep(1.0 / frequency_hz)
    return count_low, count_high

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.

Read More: Web Enabled Dryer Monitor for the Raspberry Pi

Scroll to Top