Inspired by Matt Dyson's Raspberry Shake and hackaday (twice) I decided to build something like that myself. I liked the idea of monitoring my washing machine, but of course I had to make it different, just to enjoy the creative process.
I attached two MPU-6050 sensors to an Raspberry Pi, so I could monitor both the washing machine and the dryer at the same time. I built both sensors in a seperate box, and connected them with a CAT5 cable. The Raspberry Pi monitors the two sensors and notifies when the vibration starts or stops.
I went and bought some RGB-led's , because I could.
I bought two cheap but sturdy Curver plastic boxes. They are just right for this.
Two leds show the status of both sensors. A blue heartbeat flashes every 10 seconds
green (cold) - no vibration detected
blinking green (warmup) - some vibration detected, checking to see if it holds on
red (hot) - vibration detected, machine is active
blinking red (cooldown) - no more vibration detected, checking to see if it holds on
The python script that does all the work also displays some webpages, showing the status, a log and some configuration data.
I also used PushBullet to notify someone, I used the pushybullet libary for this. I built some webpages to configure all the settings, to make it possible to administer this remotely. The script can notify 5 devices / persons, everything is configurable.
I just ran the first test, both boxes on the table and using my cordless drill I just set on the table to create some vibrations, and it worked. Now I'm finetuning the software and the sensor status page, so that I can find the right setting for the threshold and the accuracy.
I couldn't get an Raspberry Pi Zero, because they're out of stock. And every shop sells them in a package with extra's, just to make some money on that. So I bought a new Raspberry Pi 3 model B. This was just as expensive as the previous model 2B if I added a WiFi adapter, it is faster and has twice the memory.
Both MPU-6050 sensors are attached to the same i2c bus, to make that possible one of them had to have another address. This was arranged by solering a bridge to AD0, setting AD0 to high changes the default address from x068 to x069. The picture shows someone else's soldering skills, not mine. My skills are worse, but not hopeless, I haven't ruined any parts and only burnt my thumb once. I haven't changed the bus speed, if some problems were to arise I could have lowered the speed of the i2c bus to 100 kbit/s .
From the CAT5 cable I used 5 wires, one twisted pair has ground and SCL, another pair has ground and SDA, another wire has +3.3v . The double ground wires are done like that to reduce crosstalk. If I run a test-script on both sensors, I can get all values out of both the sensors (gyro, accelerator and temperature) a 1000 times in 9.6 seconds. That's 0.005 seconds to read one set of data, I think that this length of cable, 2 meters, is just fine. I'm not interested in the gyroscopic data or the temperature, so the sensor performance is not an issue. The script reads the values from both sensors 10 times per second.
I used the MPU-6050 library from Tijndagamer.
I glued some neodymium magnets I had lying around to both boxes, so I could attach them to the sides of the washing machine and the dryer.
The script hase some threads:
- The webserver, waiting to serve pages
- the vibration detector, putting statistical data in Yunomi every 0.1 seconds
- a thread for each blinking led, two maximum
- a main thread that reads a EWMA rate per minute from Yunomi and makes the decisions
Things I changed from the ideas from Matt's Raspberry Shake are:
- an MPU-6050 sensor
- two sensors on one raspberry
- PushBullet instead of Pushover
- I use a formula to calculate the total amount of acceleration, and then check that against the default acceleration (1G) and the sensitivity. Matt's solution depends on having one of the axis of the accelerometer getting more G than the sensitivity. If you don't align the sensor just right, you might not see anything. The formula I used: √(x² + y² + z²) works for me.
There is still some work, I waited to write this to only publish this when it worked:
- write more stuff in this article, add screenshots and more pictures
- fine-tune some settings
- add some comments to my first python script ever (short ones don't count, this one is now 2145 lines)
- beautify my scripts / pages / files
- perhaps add MQTT