For example. My fridge is starting to have some issues. It wants to keep freezing everything in the fridge. It dials the temperature setting all the way up and we don’t know why. I’ve taken the fridge apart as best as I can the last time we defrosted it just to wiggle all the wiring connections.
I wanted to really see what was going on with the fridge. I grabbed a Raspberry Pi Zero W and a couple of 1 wire digital thermometers and put together a Fridge monitoring system in a couple of hours. I can now see what happens with my fridge. It does a defrost sequence and comes out of it cold, freezing up the fridge.
A quick dashboard configuration, and I now have a view of the current temperature and a graph of the temperature history.
Add a couple of more nodes and I now get email notifications when the fridge is too cold. Another node, and the Google Home announces the too-cold temperature.
My fridge now complains that it is cold.
How epic is that? Under $20 worth of parts to give my fridge a voice.
So I decided to put together a monitoring system. It will monitor my sump pump, letting me know when it is getting used hard so I know to pay it more attention. It will monitor my Aquaponics grow bed, telling me when my flood and drain / ebb & flow grow bed isn’t functioning correctly. It will also monitor my fish tank water levels and let me know when the water is getting low, or more importantly when I am filling it and it gets to where it ought to be.
This is put together with Raspberry Pis. An older original B model for the fish tank because I have it and it’s close enough to Ethernet that I can run a wire to it. The Sump Pump is getting a Zero W as it is further away, and I needed to buy something and it was the cheapest option ($10).
I am measuring water height by 2 methods. An ultrasonic distance meter and a differential pressure setup.
I coded up the project a couple of different ways, learning as I went along. I ended up starting with the hardest methods first, and moving towards easier methods. Starting at OS level triggering of shell scripts, moving through python programming, and finally landed on Node Red. I am happy for the path I took as I now have a solid understanding of what a Raspberry Pi can do for me and how to control it at multiple levels. Node Red is how I will be building most of my projects going forward as it’s easier for the kids to understand.
Node Red is a graphical programming environment that you use with a web browser. This means a quick tweak can be made from your cell phone! Not the best experience, a cell phone, but doable.
The core concept of Node Red, is you drag ‘nodes’ or blocks onto your screen and set them up with the particular details that node needs. Configuration settings such as the specific pins on the raspberry pi you have a sensor plugged into, a login for an online service, etc.
You then connect the different ‘nodes’ together with lines, and the whole thing just starts working. Amazing, really.
You program a computer using the same methods you would use to explain a process to another person. Draw a bunch of boxes saying this box does this thing, and connect the various boxes together with lines showing how different events are chained together.
When you use the Node Red menu in the Raspberry Pi, it opens up a text window, with a bunch of stuff on the screen. In amongst that text, is instructions on how to set Node Red up to turn itself on automatically when the Pi starts. Now you have automatic monitoring even if the power goes out and comes back on.
Direct reading of water level via sonar
Ultrasonic distance meters turn to out to measure the distance to a water surface fairly well. The water needs to be reasonably flat & calm for it to work reliably. The thing basically beeps at a high enough frequency that we can’t hear it, and listens to see how long until it hears it’s echo back. A little bit of math, which computers happen to be good at, and you have a distance measurement!
I picked up a bunch of HC-SR04 sensors for cheap from eBay. You can get them from reputable sources for around $5 each.
The HC-SR04 sensor tutorial I followed when writing code is found at https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi
If you want to learn about all of this, it is good to work through the tutorial. I ended up dropping the tutorial method and used Node Red.
Node Red needs an add-on node to ‘talk’ to the sensor. The one I found is https://flows.nodered.org/node/node-red-node-pisrf . Install it according to the instructions, restart Node Red (or the Raspberry Pi if you haven’t figured out how to restart Node Red) and reload your browser window for it, and you can now start taking distance measurements.
Differential Pressure water level method
Have you ever noticed that if you hold your finger over the end of a straw, stick it in your glass, the water goes up the straw only a little bit? When you do that, you are increasing the air pressure inside the straw.
If you compare that air pressure inside the straw, to the air pressure outside the straw, you are working with differential pressure. We can use this to simply see the cycle of water rising and falling, or calculate the actual height of the water inside the pipe. I don’t know what physics principle to use to do the math for calculating actual water height.
I used a BMP280 temperature and pressure sensor. The adafruit library didn’t work well for me. I did however find https://github.com/ControlEverythingCommunity/BMP280/blob/master/Python/BMP280.py which worked well.
The Node Red library has a bug in it at the moment. When you try to use it with the BMP280 module, it crashes Node Red. If you see this happen, the fix is simple, you need to call in the bigNumbers.js library in the right spot. Once you do this, things work correctly.
The BMP280 had some issues with longish wires. I ended up using some Cat5 with the tip from https://www.raspberrypi.org/forums/viewtopic.php?t=82049 for how to pick the wires to get the best performance. This worked well, if a bit time consuming to pigtail the doubled up wires so I only had 1 wire to solder onto the printed circuit boards.
Seeing the data
I logged the data to io.adafruit.com using MQTT. The library I used is found at https://github.com/adafruit/io-client-python for coding things the hard way. Node Red has a built in MQTT node as well.
I used Adafruit’s IO tool because it’s cheap (free) and easy, and is great for learning how to do all of this. There are other options available from Amazon, Azure, Google, IBM, and many many more. Adafruit’s tool is great to start out with.
I just came across an interesting use of a mobile phone for sciency things… a audio frequency analysis to count RPM.
Another great video by Matthias Wandel, or what I new him from for many years before I found his youtube channel, woodgears.ca
The premise is you find the audible frequency spike, combine that with the knowledge of what is actually compressing the air to make the noise, and do some simple math.
Simple, really. All great things are simple.
I thought I would give it a try with my small battery Dremel tool. A bit of tape to compress the air and get it to make noise as it spun, and I get some numbers. They are less than the rated speed, but that is to be expected as the tape flap is pretty big and slows things down a lot.
Testing an app on my cell phone
Notice in the following images in their top right corner, there is a red and green labeled numbers. Those are the peak frequencies. Frequency of the loudest noise it hears, plus the ‘local’ or whatever is on the screen. So you can zoom in on something and get the number of just what you are looking at. Red is the ‘Peak’ and green is current.
The low speed setting on my Dremel with tape reads at 97.85Hz times the 60 seconds per minute gives me 5871 which is a bit less than the 6500 listed on the label for low speed. Battery drain, load, etc. I think this sounds about right.
Trying the high speed, I see 170.89 or 10,253 RPM. Much lower than the 14000 listed.
I remove the tape and tried again now that I have an idea of what to expect.
Low Speed, the first spike is at 103.36Hz which works out to be 6201RPM, pretty close to the 6500 claimed RPM.
Looking beyond that first spike, we can see the harmonic frequencies. The first big harmonic is a multiple of 3. If I rotate the shaft by hand, I feel 6 ‘clicks’ so this makes some sense, but I don’t yet fully understand this. Something to look into.
Here we see the the 2nd spike at 311.46hz.
Zooming way out, we see all sorts of spikes in frequencies, fairly evenly spaced out.
Lastly, lets look at that high speed setting without the tape.
The high speed is coming in at 208.1Hz or 12486 RPM. Much closer to the 14000 listed on the label.
A different App
Trying a different App I get slightly different numbers. They are all less, so it could be that I drained the battery a bit and it’s running slower. Or I could be seeing a difference in the maths under the hood. Not sure, more investigation will be required.
I see 102Hz
I tried kicking up the FFT ‘bucket’ size as recomended by Matthias in his video and don’t see much difference here.
Looking at the higher speed I see 204Hz.
With the higher FFT size I see 207Hz instead. I think the higher FFT sizes gives smaller ‘slices’ of the data so it can better find the peaks.
Things to try
I am wondering if basically covering the microphone on the phone with something like a stick and touching the stick to the frame of whatever you are trying to count RPM might be a way to ‘hear’ the frequency. Kinda like a stethoscope.
I think this is a really great technique. Thanks to Matthias for creating an exceptional video explaining what is going on.
This is certainly a great way to use a cell phone in creative ways. Multiple apps are available to accomplish this cool trick.
A long time ago, this site got hacked. Not 100% sure how it was done, either by wordpress exploit on this site, or a joomla exploit on another site on the same shared host. It took a bit of doing, but we finally got it killed. But the hack embeded links on about half my blog post pages. I wasn’t keen on manually editing about a thousand pages, so I just let them sit.
I finally figured out how to clean these links out!
I found a WordPress plugin that allows me to run a regular expression find/replace. The one I used is “Search/Replace” which was fairly highly scored with a good amount of traffic. I am sure there are others that would work.
What this allows me to do is to write a regex to find the particular defacement – in this case a link at the end of a post, and remove it. Across all my posts. I ran it 10 at a time a few times just to make sure it wasn’t going to eat all my posts. And as always when doing bulk updates, backup the site first!