Sump Pump, Aquaponics & Aquarium water level monitoring

I seem to like flooding my basement… Usually by overfilling one of my aquariums, or intentionally putting 55 gallons of water in a 45 gallon aquarium. Sometimes, I overfill the swimming pool in the back yard.

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

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.

HC-SR04 Node Red sensor, calibration, and logging flow.

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.

Sensor readings in a Bell Auto Siphon Fail to Break mode
Sensor readings in a Bell Auto Siphon Fail to Break mode. The ‘gap’ in the middle of the chart is from the auto-siphon failing to break siphon. We see it in both the upper graph measuring the actual water height plus the lower graph measuring the pressure elevation in the stand pipe.

 

 

A little bit about light

I’ve been giving myself a crash course refresher on light over the last new months. It started when I picked up a used Laser Cutter and wanted to figure out how it cuts with light. What I’ve written here is my understanding of things. I may be wrong, if so, please let me know in the comments.

My simplification of a CO2 laser is that it’s a poorly designed Neon light that gets way too hot and produces a heat ray that we can manipulate with mirrors to vaporize things. Magnifying lens on a sunny day style. I fear if I ever find an ant in my laser cutter whatever project I was working on will be a total loss as I will be chasing the ant with my laser beam. https://en.wikipedia.org/wiki/Carbon_dioxide_laser

So I now have this really sharp cut thing that I can’t see the blade on. A CO2 laser beam is invisible. If you see a red dot on a laser cutter, that is a separate cat-toy style red laser put in place so we can guess about where the actual invisible laser will do it’s thing.

Deep Infrared thermal image of laser cutting fabric
The heat line produced by laser cutting some fabric in a laser cutter
laser cutting fabric
The laser cut fabric. You can see where it has cut the fabric using focused invisible light.

My laser cutter’s light is 9.4-10.6 micron wavelength. This is the same wavelength that Humans glow in the dark. Well, everything room temperature glows at this light frequency or ‘color’.

Deep Infrared

A thermal camera can see light in this ‘Deep Infrared’ zone. I have a Seek Thermal camera that plugs into my cell phone which allows me to see effectively heat. I can walk around and find things that are plugged in that are doing a bad job of being off, and give off heat because they are still on. I can tell the temperature of anything, just by looking at it with my cell phone. I can also look for things that are supposed to help keep me warm and are failing at their job like doors and windows.

A Deep Infrared image of a Kurig Coffee Machine
A Kurig Coffee Machine that wasn’t told to ‘power save’. It’s been heating up since it was plugged in.

Except nothing is ever that simple. Materials have a property called ‘emissivity’. This is how well they emit light at a certain wavelength. Things that emit light well, tend to absorb light well. Things that don’t emit well tend to be reflective in nature.

Humans have a pretty high emissivity about .98 (with 1 being perfectly emissive and 0 being perfectly not-emissive) so we need clothes to stay warm as we would glow all of our heat away without them. But because we are highly emissive, we can absorb heat well too, so this is why you can feel heat being given off by things like hot pans, light bulbs, and turtle heat lamps, and sitting in a sunny spot.

You can see here that I glow. My clothes hold in some of my heat and my glasses block the Deep Infrared light.
You can see here that I glow. My clothes hold in some of my heat and my glasses block the Deep Infrared light.

Things such as shiny metals have a low emissivity, so they tend to reflect heat like a mirror. This is how camping space blankets work. The thermal ‘glow’ that us humans have gets reflected back at us. We absorb a lot of this reflected heat, so space blankets feel warm to us. Because, you know, science and stuff.

But, what this means, is that my fancy thermal camera can’t take accurate temperatures of shiny metal things. What I am really taking the temperature of is the things reflected on these ‘heat mirrors’. To do a good job using thermal imaging for temperature reading the more expensive equipment has material tables that you can assign to spots that have a lookup to a emissivity table so it can calculate the proper temperature based on what it sees.

I am going to carry some electrical tape which has a pretty high emissivity number around .96 and just stick that on things I want a proper temperature of. Because, you know, lazy and stuff.

Materials have some pretty funny ideas about what is ‘clear’ and what is ‘opaque’ at wavelengths other than what we can see with our eyes. Thin plastic bags that we can’t see through are transparent to deep infrared. Stick your hand in a bag, you can see your fingers as clearly as if the bag wasn’t there. Windows, glasses, things that we see through all the time are as black as night to thermal. “Low E” windows are not only black to thermal, they are reflective as well, so you can see your heat reflection in a ‘good’ modern window. CLICK. OH, that’s why “Low E” windows are better, they reflect heat. I get it now.

Near Infrared

Another portion of light, called Near Infrared, has some interesting properties as well. First off, things that aren’t metallic (reflective) are rather transparent. Things look kinda like jello at these wavelengths, the light can see into them a ways. A couple of centimeters often times.

The Near Infrared has another interesting ability. Oils, fats, sugars, alcohols, and proteins absorb certain frequencies of light – they have colors (for lack of a better word) in this range. Click here to Geek Out on Near Infrared. This means that a camera that uses Near Infrared is very useful around the house. We can look at something, and judging by it’s ‘color’ in Near Infrared, we can make a good guess as to what is made of, or at least major components of it. We can’t see near infrared, so we tend not to manipulate the colors in that range.

There is a gadget that takes advantage of these useful properties. The SCiO which is a Near Infrared ‘scanner’.

This little device is even cooler than the thermal camera. It’s small, and can tell you the interesting bits about your food like how many calories and of what type (fats, carbs, protein) are in it. You don’t have to guess at a restaurant if you are tracking your diet anymore.

This doesn’t work like a camera, it is instead a spectrograph. It doesn’t take a picture of stuff, it instead looks at all the colors that are present like how a prism works. You scan something with a SCiO and it breaks apart the intensities/brightness of different wavelengths of light (those would be the colors if this was visible light) and looks up what it sees against a database of stuff that it knows about and when it finds a match, tells you what it is looking at.
If we were to present only pure substances it would be able to tell us what things are easily. However, we don’t have much of anything that is truly pure. Table salt, sugar, baking soda, for the most part tap water are about all I can think of commonly around the house. Most of the stuff we interact with is made up of a variety of things.

This is where we get clever with the SCiO. Instead of needing to extract out the stuff into individual bits (imaging taking a baked cake and separate it back out to it’s flour, sugar, eggs, milk, water, etc) we just capture what a thing looks like in different bits of Near Infrared light and correlate it to things we’ve told the SCiO what they are previously.

The thing that makes this work is that we LIMIT THE DOMAIN of what things are so the SCiO has a chance at making a reasonable guess. For example, there are a lot of things that are Red. Lego, fancy cars, strawberries, some apples, etc. If we showed you a particular shade of red, and asked you what was that color, you can come up with a lot of wrong answers that are that exact shade of red. But if we said we have a berry that is this particular color, you would be able to tell very easily what it is most of the time. Especially if you can look back against other color samples and compare what you have now with what you have seen in the past.

So for the SCiO to work well, we need to train it. We get together a bunch of things that we want to tell apart if it’s not properly labeled. We then teach the SCiO this thing is X, that thing is Y. We can than ask SCiO what is this stuff, it’s something that belongs to this group that we trained it on.

An example could be clear liquids. Clean water, vodka, strong vodka, watered down vodka, rubbing alcohol, denatured alcohol, clear soda, vinegar. These things all look similar to our eyes. They will all look different from each other in Near Infrared. We can train the SCiO about all of these clear liquids, and when we find a glass of one and we don’t know what it is, we can check with the SCiO.

Amazing!

There are some ways in which the SCiO can fail.

  • Shiny mirror like surfaces tend to reflect all light, regardless of the wavelength. Metals for example. We also see this in Visible light as well as Deep Infrared.
  • Things that are black – they absorb light – tend to absorb all frequencies of light including Near Infrared. Things that have been colored black will likely be black to the SCiO as well, and it can’t get a good read on them.
  • Only the major components of something can be read by a SCiO. If there isn’t enough of something to make a strong ‘color’ influence, it simply can’t be read. A SCiO can ‘see’ stuff that is more than 1% or so of the overall item.

 

Understanding how a fancy new tool works ‘under the hood’ helps me manage my expectations of what the tool can and can’t do well. I can ‘hack around the edges’ of it’s capabilities because I understand what the edges of capabilities are and why they exist.

Internet of Things Phone Smart Charger

I pre-ordered one of the Samsung Galaxy Note7 phones. The ones in the news recently for being an explosion hazard.

I love the new phone – pocket computer really, the way I use it. I wasn’t about to give it up over some silly thing like spontaneous combustion.

I had read that Tesla runs their car batteries between 40%-80% for normal use to maximize the lifetime of their very expensive car batteries. I figured that cell phone batteries would benefit from similar treatment. A bit of research generally confirmed this, with http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries being the most concise write-up. The first half basically demonstrates that you can get the same amount of total power to flow through the battery regardless of how much you charge it – summed over the total life of the power draw in the data tables. The 2nd half is more interesting. It says that high voltage charges and heat shorten the overall lifespan of the battery.

The Note7 is a sealed phone wihtout a replaceable battery. I can’t pull my usual trick of replacing the battery after a year of abusing it.

Heat seams to be the trigger for the phone explosions. So I can make my phone more safe, and make it last longer by managing the top voltage and heat in the battery.

I can do this.

I bought a wireless Qi charger to charge the phone because it charges slower. The fast charger can charge the phone crazy fast, but it gets HOT when it does this. Hot is bad. Thus, slow is good. The wireless charger will also reduce wear on the USB C port. A nice side benefit. No phone explosions while I sleep and burn the house down – this is a good thing.

I bought a Belkin WEMO wifi controlled outlet. It is If-This-Than-That (IFTTT.com) capable so I can control it from my phone. There are other smart plugs available that will work, this is simply the one I could find in a store that I could verify would work with IFTTT.

I configured IFTTT to have 2 different actions. One for turning the WeMo on, the other off. I set these up as Maker Channel triggered recipes. There are other triggers that you can use such as email or SMS, but I am a web developer, so web-based triggers are a natural fit for me.

Image of The Rules set up in IFTTT
The Rules set up in IFTTT
Photo of the IFTTT Off rule
The OFF rule in IFTTT. It uses the Maker Chanel for the trigger, which means a web request will trigger this. It turns off the WeMo controlling the wireless phone charger.

I installed Tasker on the phone and configured it to monitor charge state and battery temperature.

I created 3 tasks, one to turn the charger on, and two to turn it off.

photo of Tasker rules
The rules in Tasker to control the phone charging.

The ON trigger looks for the battery to be below 80% charged, and below 35 degrees Celsius. This will make a request to the IFTTT.com Maker Chanel URL for ON.

One OFF trigger looks at the battery temperature. 35.1 degrees or higher. The other OFF trigger looks for the battery charge to be 90% or higher. These two both make a web request to the IFTTT.com Maker Chanel OFF URL I set up.

So now as the phone battery heats up or gets close to full, the phone tells the charger to turn off. I let the phone have a 10% charge window so I am not toggling the switch and charger on and off all night long.

Tasker with both OFF rules turned on. The phone is both charged to 90% or more as well as running hotter than I would like.
Tasker with both OFF rules turned on. The phone is both charged to 90% or more as well as running hotter than I would like.

I also programed the WeMo to turn itself on a little while before my alarm is set to go off. This is to let the battery be closer to 90% charged rather than 80% charged when I wake up. I haven’t found the right time for this yet. I still need to play with it a bit.

I know there are other ways to make a smart phone charger. This is what I came up with. I will be getting an additional smart plug and building one for at the office so I don’t over-charge my phone when at work. I will try a different brand likely to see if I can come up with a cheaper way.

I recently picked up a used CNC Router

It's a big machine for the hobby side of things. I think they call it a 60150. It will hold a 2 foot by 4 foot piece. 220v water cooled spindle. It's a solid machine.

It had been suffering from disuse – not neglect, just simple not getting used enough. Rust pitting on the important bits and some rusting on the threaded rods. A couple of years in an unheated garage without being used to re-coat all the parts in oil will do this.

Not too much work to clean it up. It took a couple of evenings over a couple of weeks. Last night I got the electrical stuff all sorted and got it to move!

So I dug up a bucket, and connected water and electricity to the same spot on the machine. This is generally a bad idea in my experience.

It cuts! A little bit of tweaking, and it cuts correctly!

About an hour into running it, it gave an error and shut down. Not really sure why, but I think it's because the controller got hot. There was a reading of 75c on the screen when I was pushing buttons. I think I found why the controller box was open.

Next project is to improve the airflow in the controller box. I have a plan for this. I will install rubber grommets around the holes the wires poke through too.

I also need to learn about "Speeds and Feeds". CNC Routers have an ideal window where they work well for a given material. The 3D printing methodology of slowing down, sorting things out, then speeding back up does NOT apply to CNC Routing it appears.

Lots of photos in the album. Each one is captioned.

CNC Router Refurb
27 new photos · Album by Mike Creuzer

I got a mosquito hammock this week for $30 from woot

This is pretty cheap. After I ordered it, I realized how short it was – it's six inches shorter than the one I already have. Short hammocks and tall people make for an uncomfortable night's sleep. So I decided to try to cheat the length a bit. I converted it to a Mini bridge hammock. Some amsteel rope dogbones, a pair of spreader bars, and it's a non-damaging modification. I think it worked. I slept in it as it came, and after the modification and I like the mod. It's much more comfortable. Not perfect, I find my feet tend to rest against the netting.

Next project. Down underquilt.

In album Miniature Bridge Hammock modification

My girls hanging out in my new Yukon Outfitters Mosquito Hammock

It’s a clear tarp for me for the hammocks. Window winterizing film, duck tape & patience to make one.

This is how the hammock came. A rope (which stretches a lot the first night you use it) fed through the channel and closed on itself. Here, I’ve had to run it back up to the metal connector so tighten the hammock at 3 am so I wasn’t dragging on the ground anymore. Notice how tightly it bunches the end of the hammock up. The thin line is the stretch cord for holding up the bug net part of the hammock.

This is a miniature bridge hammock. The idea is to make the ends wider so it squeezes against the shoulders less. It is also supposed to reduce the tightness up the center under the legs that can cause discomfort.

I made 4 amsteel dogbones. These are just short ropes with eyes on both ends. I sized these so they are short as they can be and have the right length bury that nearly touches in the center.

Try to make all 4 the same length.

The amsteel dogbone is fed through the hole in the wood, fed through the hammock and  the loop slipped over the end of the wood. Do this from each side.

It’s easier to pull the new rope through as you are pulling the old rope out. (trust me  I know)

But it’s easier to untie if you put the old rope to the new, and not the new rope to the old. Oohps.

The hammock is clipped into the rope that it hangs from.

The offset in the carabiner can be used to advantage in counteracting any differences in the length of the amsteel dogbones.

This is with the original mounting method.

This is the girls swinging in the new method. Notice how the end of the hammock forms a gentile curve.

The hanging hardware that came with the hammock – both sides.

The new hanging hardware weighs 2 grams more. Now, this is a cheating weight, as it doesn’t include the carabiners.