Tag Archives: Aquariums

My Workspace

My Workspace

This was my workspace on 2-5-2010. Click for a humongous version (1.9mb).

Items of note:

  • Ohm’s Law
  • Medicine Man balsa wood glider (half finished)
  • Make:Electronics book, Maker’s Notebook
  • Woolly Mammoth clone guitar pedal, nearly done
  • 2.5 gallon fishtank, testing out temperature logging via LM34 and Arduino (see FishApp) for more details.
  • There are no less than five computers on/around my desk. Not all are visible.
  • Small cheap telescope
  • Printing plate of some old ship
  • Guitars.
  • More guitars.

The mess?  Oh, that just means I’m getting work done.

FishApp – Water Change Detection

The other day, I went to the mall with Kristin.  I usually finish up quicker than her, and this time being in possession of a shiny tiny netbook, I was able to code and tweak the water change detection algorithm for the FishApp while sitting on a bench outside of Macy’s.  I had a couple rather confused onlookers.  I may or may not be on a “do-not-fly” list now.

To refresh your memory, the FishApp keeps track of water changes, and gives you a graph showing weighted-age values for the water in your fish tank.  This requires you to pay attention while you’re doing the water change, and to log in to the website and report how much water you changed when.  Well, I want to have the FishApp sense, measure, and publish water changes for me.  To those ends, I designed a system that can measure the water level in the tank over time, report it to a computer, figure out when and how much water was changed, and report that back to the main fishapp web application.  The measurement is done using a Ping))) ultrasonic rangefinder, and data from that (and other sensors) is fed into a computer.

But just how is the computer supposed to figure out when a water change happened?  It’s input is just a string of numbers, and it’s gotta be smart enough to filter out random noise from tank cleanings, frisky fish, the water filter starting and stopping for one reason or another, or any of a hundred other situations.  What to do?

If you’ve read the last post about the FishApp, you know where to start – smooth out the data.  To recap, I have the sensor set to read the water level every half-second, and report it to the computer.  The raw data is pretty noisy:

but if we make new data points from the median of  every 20 samples, things smooth out pretty quickly:

The system should be able to handle this muuuch easier.

The algorithm works by keeping a queue of recent (smoothed) samples.  By comparing the oldest sample with the newest sample, you can get a “slope” value.   On the graph above, for example, it doesn’t take very many samples until the oldest will be just over 600 but the most recent will be around 800 or so, and you’ll have a large positive slope.  Once the algorithm sees this large positive slope (above a certain trigger value), it knows that a water change is beginning, and notes the water level beforehand.  At some point in the process of a water change, I start filing the tank up again, and we see a large negative slope (around 55-60 on the graph above).  The algorithm notes the capitulation and the minimum water level.  If the absolute value of the slope stays low enough for long enough, the algorithm detects a steady state, and calls it the end of the water change.  The “steps” you see on the graph are because I do my water changes bucket-by-bucket, but because the algorithm is using a slope from a queue maybe 10 samples long, it already does a pretty good job of smoothing these steps out, and not getting too confused.

After running the algorithm against the data above, it worked flawlessly.  Take a look at this graph:

The gray lines are where the important steps in the process were detected.  For example, the first gray line @ x=10 is where the algorithm first noticed we were emptying water out of the tank.  It looks late – and it is, but that’s merely a consequence of using a queue of 10 samples to generate the slope.  The actual “before” water level value it uses is not the one at the gray line, but the minimum one in the queue – which is correct (enough for rock and roll).  Then, at x=54, the algorithm detected a large negative slope and decided that we were filling the tank up again.  It started looking for the start of a steady state, which it found at x=121, and it stayed steady long enough that at x=150, the algorithm wrapped up and decided that we’ve done a water change.  NIFTY!

If you think about what is going on here, it’s really calculus, under the covers.  The slope value is the derivative of the function, and we look for the points that derivative changes sign.  But the function we’re using isn’t perfect, and isn’t continuous, and so we’ve got to build in a little extra wonkitude-resistance.  The algorithm has inputs for the size of the queue, the trigger value for large positive/negative slopes, a tolerance value to ignore noise during steady states, and the number of samples to go during a steady state before deciding we’re really done with the water change – so in theory, this algorithm could be adapted and tuned for a wide range of input sources with little-to-no modification.

Right now, the algorithm is coded in python, but I think it might even be possible to do the crunching on the Arduino.  If I did that and wired the Arduino up to an ethernet shield, I could ALMOST eliminate the computer altogether.  I still need the computer to run the webcam, however, so there’s no point in trying to run this code on the chip or anything like that.  But I think it would be possible in theory, if you don’t want the cam server running.

What A Water Change Looks Like to the FishApp

One of the goals of the FishApp is to have automatic water change detection available in phase 1. In order to do this, I have a Ping))) ultrasonic distance sensor pointed down at my fishtank. This little guy works by producing a sound above human hearing range, and listening for it to bounce back. If you know the speed of sound, you can calculate how far away the object was that caused the reflection. The sensor I am using is mounted above the tank in a piece of 1/4 inch wood to help shield it from the moisture, and samples the water level at predetermined intervals, sending its data over a serial connection to a host computer via an Arduino controller.

The host computer gets this stream of numbers, and has to have some way of determining when I’ve done a water change, and how much water I’ve changed. I got the feeling that random variation (noise) in the data from the sensor could throw off whatever method I use to compute all of this, so I needed to figure out exactly what the data looks like coming in to the computer, preferably saving it so I can test my algorithms against it without having to do a water change after each revision – that would be a heck of a lot worse than just waiting for the code to recompile.

So I fired up Arduino and Python did a water change, saving the raw data from the Ping))) sensor to a file. Without further ado, this is what a water change looks like to a computer:

Pretty cool, huh?  When I do a water change, I siphon water out of the tank into a 3 gallon bucket, and empty it a bucket at a time, until I’ve taken out as much as I like, and then I re-fill the think 3 gallons at a time.  You end up with the very visible “steps” on the graph.  While the data looks mostly consistent, you can see some wonkiness in some of the steps – which almost looks like thick lines.  The sensor isn’t quite reading the distance regularly in this case.  This looks to me like the kind of data which could really throw of my detection algorithm.  So I had the bright idea of taking a median of 5 samples for each data point and using that series for detection.  Here’s what a median-of-five graph looks like:

Median of Five Graph

Median of Five Graph

You should notice two things: 1) there are fewer datapoints by an order of five, because of the median, and 2) the curve is smoother.  I could prove this by computing the standard deviation on some of those trouble spots from above, but I don’t think it’s necessary: it’s plain to see when graphed.  The data could still be better though – look at the jaggies around 100.  We’ve got plenty of data, so we should be able to create a very smooth line and still have enough resolution to see each step, etc.

I’ll spare you all the gory details, but suffice it to say that the larger the median used, the better.  A median of 10 was better, but still not good.  A median of 15 was nearly perfect, but there was still just a little weirdness.  A median of 20 was perfect:

Median of 20 graph

Median of 20 graph

That’s more like it.  We’ve still got enough data there to see the water change in detail, but smoothed out all the ugliness that could throw off the computer.  Cool stuff.

More details on the detection algorithm’s implementation to follow.  Charts generated with my new favorite tool, Python.

Make-ing Things

I’ve been busily  making stuff.  Here’s what’s been keeping me busy:

This is my version of a Woolly Mammoth guitar pedal I’m going to call “Mastodon Dave.” This is the test wiring.  Yet to be done is to get Kristin to paint the case, and then I’ll do the final wiring.

I’m working on a balsa glider with plans I got from (the incomparable) Make Magazine.  Here I am working on the critical step of joining the two sides of the fuselage together.

You can see that the two sides are more or less straight.  After doing some more finicky work, sanding, gluing, tweaking, and fussing, it looks even a little better now.  In the background of the above photo, you can see my new telescope – the latest accoutrement for my long series of intellectual obsessions.

The fuselage nearing completion.  Shaping the nose cone was a little hard.

Here’s a little trick I picked up from this guy’s photoset – bevel the edges of the equipment bay hatch so it will slide in and out rather than tack-gluing it or using tabs like the plans said.  I am really happy with the job I did on it, too, and when it is closed, you can barely tell there are two seams there.

I’m also working on the physical hardware for the sensors for my Fishapp. It’s coming along well, but slowly, as the mounting and hardware is the hardest thing about those kinds of projects for me.

Happy Making!

Moving the Fish

Here’s a few pics from our move to NC.  As most of you will know, we have a 55 gallon fish tank that we love, and we wanted to move the tank and all the fish to their new home in NC.  Here’s the fish in coolers, getting ready for the move:

And here we are, in the car, with the fish loaded, gassing up, about to move.

The fish were troopers and here there are in their coolers, waiting for us to be able to set up the main tank and send them home again.

If you’re interested in the details, here’s what we did: We bought two large coolers, lined them with large trash bags, and bought cheap batter operated air pumps and a digital submersible thermometer.  We poked 2 holes into each trash bag and stuck airline tubing in them, one tube for the airpump, one for exhaust.  The idea is that the airpump will continually pump fresh air into the water, the bubbles will agitate the surface for gas exchange, and the exhaust will vent off any “old” air.  Left some air space up, sealed the backs, threw them in the back (wedging pens under the lid so the tubing will not get crimped).  All worked great!  Thinking of starting a business moving rich people’s fish.

FishApp Update – It’s Doing Stuff

It looks like the FishApp is already providing me with some really neat and useful insights into my aquarium.  I recently added the ability to overlay and toggle multiple series on the graphs it displays, to make it easy to see if one parameter has an effect on another.  Take a look at this snapshot I took today:

Water age & nitrate levels over time

Water age & nitrate levels over time

This chart shows the average age (in days) of the water in my tank compared with the levels of Nitrate I measure using an aquarium test kit.  I compute the water age using information I record about water changes I do to my tank (a more detailed explanation can be found in the original FishApp post), and Nitrate is a mildly-bad chemical the can build up in your tank over time.  It’s the end-product of the Nitrogen Cycle in most fish tanks, and can only be removed by water changes or chemical absorption (which some plants and special filter media can do).

At least that’s the theory.  What this chart is showing me is that the theory seems to actually work out in practice, and that my tests are precise enough to actually be useful – always a good thing.  Even though I only have five data points for the nitrate series (because I don’t always test as much as I should), it is easy to see the nitrate curve following the water age curve.  They actually track pretty well, I think. You can see an ugly spike in the water age when I wasn’t paying enough attention to the tank, and the resulting high nitrate levels, which backed down after a series of regular water changes.  When the water age started creeping back up again, so did Nitrate levels, and then both went down again after we moved from Tennessee to North Carolina (and changed out about 2/3 of the tank water for fresh in the process).  Very cool.

Since nitrate is the last state that fish poo reaches in the nitrogen cycle, it would not surprise me if there were a delay between water age and its effects on nitrate levels.  I don’t really have the data to support that right now, but I will try to be more diligent in my testing, and perhaps we can figure that out soon.

If there are any aquarium owners out there who are interested in the FishApp, you can sign up free and track your own fish tank in a similar fashion.  Here’s a link to sign up.

Naughty Rams, Caught on Video!

Caught my German Blue Rams spawning:

Get the Flash Player to see this player.


Check out what happens when one of the Cory’s gets too close. They are so oblivious to their surroundings sometimes… We had heard horror stories about Rams getting aggressive when mating and corys losing their eyes… Luckily none of that here.
I also got some stills.

More Tetras

Kristin and I were finally able to track down more tetras on the other side of the city tonight, so after getting lost and turning around several times, we finally cleaned out the cardinal tetra stock at the 2nd petsmart in nashville. Now there are none in like a 30 mile radius. jeeeezz they are hard to find sometimes. But they are cool little suckers.

Fish are very sensitive to their water conditions, and these fish are kinda sensitive in particular. Sudden changes in things like ph, chemical composition, temperature, hardness, and cleanliness can stress fish out, even if its a change “for the better.” So its best to slowly adjust the fish to their new water.

The most commonly-suggested way to do this is to float the bag that the fish come in at the top of your aquarium for about 15 minutes and then add the fish. The theory here is that the temperatures will be equalized and that is the most important part. That may be true, but it is a much less than perfect method. The water can be heated by the florescent lamps and this method does nothing to adjust for chemical differences which can really freak fish out. If they aren’t used to the water chemically, they can have a hard time breathing (through their gills, ya know?) and that’s not good for anybody.

We did this last time with our cardinal tetras and the fish had a rough time making the transition. A couple of them actually were belly-up for a few seconds before they came to. Not what you like to see.
We found a better way of doing it. You put the fish in a small quarantine container and slowly take out some of the old water and replace it with the new water. Badda-bing, badda-boom, your fish are a WHOLE LOT LESS FREAKED when you add em.

After we added the new guys, they immediately started schooling with the old guys. They’re super-cute. There’s one guy, we call him “Lemon,” he’s the littles of the bunch and when we added him, his dorsal was clamped down a bit, and he had like no red or blue/green color – he was all pale yellow. In like three minutes though, he started getting some color back and perking up. He’ll always be little Lemon, though.
Oh, and here’s some more pictures of the corys feeding.

See the one in the front here?

That one’s ol’ blackeyes. Or blackie. He seems to be the smartest, least psycho of the bunch. All the other corys will be freaking out, swimming up and down the side of the tank, and blackie will be eating excess food off the log. Good ol’ blackeyes. What a good fish

That’s all I got for now. The [submersible] fish cam will be coming soon[-ish].

New Fish – Corys

We added four more fish to our tank… slowly, we’ll have it fully stocked. The four new guys are cute little Corydoras (C.trilineatus). They are little catfish-like schooling dudes that come from peru and ecuador. Here’s what one looks like:
Cory close up
The pet store had them incorrectly labeled as Corydoras Julli, but they are apparently commonly mislabled this way. When we first put them in, for the first few days, all they did was swim up and down and up and down along the right side of the tank, like a dog chasing its tail. They were acting all crazy.
They’ve calmed down a bit now, and spend most of their time looking for food along the bottom, or on the driftwood, or on plants.
They scurry about very cutely. And when they get spooked (which happens easily, sensitive little dudes), they kinda play dead.. they just go real still along the bottom of the tank and wait it out for a bit. kinda neat i guess.
all four corys hanging out
Anyway, for those of you who are actually nice enough to have read this far, i’ve got a little treat for you, i think. Assuming it works, I’ve posted a video of me feeding our tetras. They zip and zoop like crazies when there’s food in the water… its pretty cool. Check it out.

Fish Tank

[WARNING: If you're not interested in reading a sorta long and maybe boring story about how kristin and I set up a fish tank, you may want to skip to the bottom of the post to see some neat pictures. If you remain undaunted, you may proceed...]
Kristin and I decided we needed a pet – but a really low-maintenance one. My dad has a fish tank with two beautiful discus in it and when we were home, we always liked to look at the fish happily, gracefully swimming around. So – we decided fish were for us.
There are a number of reasons for this. Next time kristin and I decided to randomly leave for a week or so, the fish may not even need food, and if they do, there are automatic feeders. Kristin and I are also Zoo Nerds (we’re members of the Nashville Zoo and hang out there now and then. We also have buddies in our cubbies), and like learning about the natural world. I’m sort of a science geek. So a fish tank (which is more-or-less a small ecosystem) is an interesting thing to learn about. It’s not as simple as just dumping fish in (see the nitrogen cycle, for instance), so its perfect for those of us who are still interested in a little science now and then.
We settled on a 55 gallon tank kit from Walmart. It’s actually a kit made by Marineland, a respected name, and just rebranded for Walmart. The kit included a filter, heater, thermometer, lid, lights, and some small packets of dechlorinator and food to get you started. Pretty nice kit.
Of course, take into account that water weighs somewhere in the neighborhood of 8 lbs per gallon… And you realize you’ve got to get a fairly heavy-duty stand for the sucker. So we bought a nice black stand. Another chunk of change.
Then I heard from my dad that I could get like 30% anything from this online store for a while, so I loaded up on supplies from them… We actually were able to score an upgraded filter, usually $70-$80, for $30. This was a good score.
We bought some books and read a ton on what fish go with what, what kind of water certain fish like, all about the nitrogen cycle, beneficial bacteria, planted aquariums, and the like… Ph, hardness, buffering, diseases, water changes, and the like. I like to thoroughly research my hobbies :-)
We set it all up, put in a mixture of plain gravel and plant substrate (flourite) in the bottom, and bought some mopani wood (like driftwood, but does not decompose. a two-color dried african wood), and planted some aquarium plants (Amazon Swords and Java Ferns). We ran the sucker for a few days, and then it was time to get some FISH!!!
There were a couple options for us… We really liked my dad’s Discus fish, but we also read about this one particularly awesome kind of fish called Oscar Cichlids. They are cute in a very homey sort of way, with huge mouths and a mixture of drab and bright colors. They get to be over a foot long, and are very inteligent social animals. They recognize their owners, wagging their fins when you approach. If they get bored, they’ll tear apart the decorations in teh tank and rearrange them to their liking. Some of them even like to be petted. They can live to be 8 years old. They’re like a small dog – albeit one that has to be kept underwater all the time. We really kinda wanted one, but a 55 gallon tank was a little small for them (we couldn’t really put any other fish in it), and we will probably be moving at some point, perhaps selling our fish, and it would be hard to find someone willing to take such a large pet-like fish at the last minute. So we decided on discus. We’ll have an Oscar at some point, though…
Usually discus aren’t recommended for beginners. But my dad did it, and Kristin and I probably do a lot more research than most beginners, so we figured all would be well. We started to think of what kind of fish to stock with the discus. Turns out they really like to have schools of cardinal tetras around – it makes them feel relaxed. We decided to start stocking the tank with some of those. Petsmart only has four at a time, pretty much, so we bought them out. They are about an inch long, and grow to be up to two inches…. So these four tiny fish have this huge tank to themselves currently. Lucky little guys. We’ll be buying a few more tomorrow, to bump up the size of the school.
I’ve been doing water testing nearly every day to check for buildups of ammonia (to track the progress of the tank’s cycling) – but there is just not enough fish in the tank to register anything on my tests yet… However, somehow the ph jumped .4 after it got in the tank… The water is also cloudy, due to the fact that the substrate we used needs to be washed just ridiculously well (and we only washed it well). I think the two are related. The particulate in the water could be adding to whatever the ions are that make a high ph, and once i get the cloudiness down, with more water changes and gravel-vac’ing, the ph should come back down too. As the water comes out of the faucet, its 7, but the tank always reads 7.4-7.6 – this is pretty high for both discus and cardinal tetras – so something’s gotta come down sooner or later.
Without any further ado, here are some pictures!!
Fish tank, no fish.
Fish tank all set up, no fish yet. Note the cubbies at top left.
Cardinal Tetras by the Java Fern
A couple tetras, hanging out by the Java Fern. The Java Fern is currently tied to the mopani wood with string. The string will keep it in place until the roots take hold.
another shot of a Cardinal Tetra
Another shot of our cute little Cardinal Tetras. Soon there will be a whole school of these suckers in our tank.