Thursday, November 18, 2010

this is my favorite pun

a kid is watching tv and sees a man being sentenced to 20 years hard labor on some beautiful pacific island.
"dad", he says, "what'd that guy do to spend so much time in jail?"

"Well son," says the man, "it all started out like this.

That man is Dr Franklin, a world renown genetic engineer. He has a lab out in the pacific, on some crazy little island country where they don't give him trouble about stem cells. It's an interesting little island, ruled by a dwarf king. The king's a nice enough guy, but he's got a real napoleon complex. He's even got a mangy old pet lion he lets roam around, because it makes him feel tough. Actually, he's got such a weak grasp on power there that in order to keep the people from revolting when he showed up with the lion (they all thought it was dangerous), he had to tell them that they could legally kill it if they ever had to.
Anyway, Dr. Franklin was working with a bunch of dolphin research subjects, because even on this crazy little island, you can't go around performing experiments on people. He was working on keeping the dolphins from ever aging, and was doing a pretty good job. The only thing wrong with them at the moment was that they needed a specific enzyme that they couldn't produce, and the Dr. Franklin could only get from seabird eggs, less than a day before the eggs hatch.

Unfortunately, on this particular day, Franklin's lab monkey knocked over the rack of eggs kept in the lab, and they shattered all over the floor. So, in order to keep from losing his life's work, Dr. Franklin jumped in his truck and hauled ass across the island to where the local sea bird population roosts, on the other side of the island. He makes it there and runs around the cliffs, picking up eggs and listening to them, trying to find ones that are just about to hatch. Once he'd gathered about 20, he tossed tehm in a crate in his car and started driving home, quickly but carefully, so as not to crack the eggs.

Well, about half way back, the eggs start hatching left and right, I guess teh vibration in the car or the change in temperature triggered them, but Dr. Franklin flips out and floors it, screaming down the road to make it home in time to extract the enzyme from a few of the eggs before they hatch. Almost home, he slides his truck around a corner and just FLATTENS the king's lion, which happened to be standing in the middle of the road. The truck was trashed, the eggs all smashed, and about 10 minutes later the constable and the king showed up and took Dr Franklin away."

"But dad, didn't you say that it was legal for people to kill the lion if they had to? what did they get Dr. Franklin for?"

"Well son, it may be legal to kill a lion, but it's still against the law to transport young gulls across a state lion for immortal porpoises"

Thursday, October 28, 2010

testing pachube stuff

this is a test. here's the temperature in amsterdam



Thursday, January 28, 2010

Repurposing an infusion pump for aquarium supplement dosing

So, one of the biggest hassles in day to day reef tank maintenance is dosing of alkalinity and calcium solutions. In any tank with a relatively high load of stony corals, you need to add these supplements to keep the water chemistry in line. Our current tank requires something on the order of 20ml of each per day. Missing a few days here and there isn't a HUGE problem, but in general, it's a bad thing. Also, adding all 20ml of each at once introduces instability as well, in the form of concentration pulses, which isn't awesome.

A much better solution is to have a very slow, well-metered pump constantly adding each solution. You can't mix the concentrated solutions, because they will form a percepitate. The normal way to do this is with a purpose-built aquarium peristaltic dosing pump. This is fine, but a 2 channel pump can easily cost north of $300!

A couple years ago I decided to try to find a cheaper solution. I ended up buying a gemini pc2tx 2 channel infusion pump off of ebay for about $50. It looks like this:

It's a very nice unit, but it is CRAMMED with safety features (which makes sense, since it's a medical device). The problem is, it's also fairly old, and either it's damaged, or some of the safety sensors are gunked up, or who knows what, but basically I have never been able to get it to work on its own. It powers up, but as soon as I actually try to start it pumping, it just gives me errors, beeps loudly, and stops working. I have tried for HOURS on several occasions to figure out what was wrong, to no avail.

In the end, I popped it open, and realized that the pump trains are driven by 2 pretty standard 6 volt bipolar stepper motors. This is great, because you can control stepper motors with an arduino!

Thus this project was born. First I gutted the machine, removing all of the (now unnecessary) control circuitry, power supply (unfortunately the machine's power supply puts out 6 volts, which is too low for the arduino, and I don't know enough about power supplys to try to change it), and other parts. Most of this went into a pile for later parts scavenging.

Then I went to the electronics store and bought a pair of NTE2013 darlington arrays
to drive the 2 motors (i hoped i would be able to scavenge these from the existing control boards, but i wasn't able to find any. part of that might be because "darlington array" is only one (perhaps the simplest) of a couple of different names for this kind of chip, apparently.) Most tutorials refer to the darlington arrays as ULN2003, but my electronics store stocks NTE parts, and the 2013 has built in protection diodes, which is nice.

In order to hook the motors up correctly I had to determine which of the 6 wires goes to what in each motor. This javascript page was a huge help:

With the motor wires sorted, and the driver chips in hand, it was pretty much a snap to get the 2 pump trains running.

One additional item I had to modify was a little unexpected. The pump trains are held together by springs, i suppose to let you use different diameter tubes or something. But my springs aren't strong enough, and don't allow the peristaltic actuators to completely close off the tubing. To solve this, I just wired the spring perches together, so the actuator can't move as much. If you make the wires too tight the motors stall intermittently, so it's a bit of trial and error to get them right.

The red wires in this picture show what I mean:

The remaining steps are to figure out the right motor speeds to get me the pump rates that i need, but that should be pretty easy.

The biggest current stumbling block is that in the arduino code each call to a stepper motor is blocking. Which means until the motor reaches the end of the called-for run, the program is halted. So if you call one motor for 200 steps (one revolution) then the other motor for 200 steps, they each run one revolution, then stop and wait for the other motor to run.

This can be partly solved by only calling for a few steps from each motor at a time, so they effectively are alternating back and forth very fast. The only problem here is that now the speed of one motor is dependent on the speed of the other. If I have both motors going 1 step at a time, and I switch one of them to 3 steps, this speeds up the 3 step motor, but it slows down the 1 step motor, because it now has to wait for the 3 step to finish it's (now longer) call before it steps again.

There is probably a way around this, and it's not a HUGE problem, but for the moment it's not quite a perfect solution.

by operating on a minute-long cycle and with the pumps running at a speed of 30rpm, I can get up to a total of 6ml/minute (between both pumps, divided any way i like) of dosing while keeping the rates completely independent. This is WAY more that I will need (something closer to .1-.2ml/minute will likely be the actual rate), so that problem is more or less taken care of.

A new problem is that I was trying to run the motors (6v) off of the arduino's 5.5v power. Unfortunately, they draw too much current (no big surprise there) and would cause the board to reset. At the moment I have them powered by a 9v battery, but will pick up a wall-wart style power supply shortly. An interesting aside, this device came with a big 6volt sealed lead acid backup battery, so if I wanted to make it keep running in a power outage, and I was a little smarter about leaving the old power system intact, I probably could have done that.

UPDATE: ended up putting the old power supply back together and using it. Should have done that to begin with. Also, after some overnight testing, it seems like the first and ladt couple of steps (say, 5 on each end) of the stepper motor are relatively high-error, in terms of volume delivery. this means that if you call of 14 steps every minute, you get 10 bad steps and 4 good ones, which was killing my overall delivery accuracy. So i changed the software to dose once an hour instead of once a minute. This way you still get 10 "bad" steps, but instead of 4 good steps between them, you get 830 good steps. It seems to be working much better. I also added a 5 minute delay between dosing channel 1 and channel 2 to prevent the solutions from mixing with eachother at high concentrations (before they have time to mix well with the water).

Monday, January 11, 2010

RODI auto-shutoff

So, the RODI (reverse osmosis deionization) water filter we have set up in the basement to make nice clean water for the fish tanks has a simple but significant drawback. It runs VERY slowly (making 5 gallons of water takes from 4 to more than 10 hours, depending on input pressure). So, you generally have to turn it on, then come back later and shut it off. But you have no real idea WHEN to come shut it off, and it's very easy to forget about it entirely. Because of this, we tend to overflow it, which is a waste of water, a waste of filtration capacity (which is fairly expensive), and it means we have to run it with the bucket sitting in the sink to catch overflow. Unfortunately, the washing machine drains into that sink, and if the bucket is less than about half full, the washing machine will cause the bucket to tip over, wasting all of the filtered water, and contaminating the bucket and tubing with soap. It's really a pain in the ass.

SO, the obvious solution was to put together a system to shut the flow of water off when the bucket is full. That way it will be a simple "set it and forget it" system, and we can keep the bucket on the floor.

This is the circuit we came up with:

(thanks to this bit about latching relay circuits and this bit about how to set up the amplifier/water-controlled-relay part)

It's basically a simple amplifier that trips a latching relay when a very small current passes between the 2 contacts. (and yes, I know I draw and write like a 5th grader)

the solenoid valve we are planning to use is the polycarbonate one at the bottom of this page: mcmaster-carr

I ended up using a switch instead of the NC pushbutton (so the thing is harder to turn on by mistake), and using bc123 and 128 transistors instead of the ones in the drawing, because that's what You Do It had in stock. I built the majority of the circuit the other day and it works, just need to box it up and add the 120v. relay and solenoid valve (we are going to use the 120v solenoid valve instead of the 24v one on the diagram) . And maybe a transformer to power it (it runs off a 9v battery at this point).

One thing I was curious about was if the RODI was going to conduct enough electricity to trip the circuit, but I tested it on a glass of RODI water, and it seemed to work fine. Should have the rest of the system put together maybe by the end of this week...

added some diodes to the relays to protect the transistors. also added a circuit breaker and plugged the whole thing into a GFCI outlet. I ended up using a 120v solenoid, so some extra protection seemed like a good idea. Boxed it all up, added a flashing status led, and so far it works like a charm. Will post a few more pics soon.

UPDATE 2: Pics!
here's the box. the switch is power, the blue button starts the system. The LED flashes while it's running, and the black button is a circuit breaker.

here's the solenoid valve:

and here's the whole setup sitting on a shelf in the basement:
One thing to note is that the control box is zip-tied to a pipe ABOVE all water sources, so hopefully in the event of a drip or leak, no water will enter the box.

still need to make a bracket for the water tube and the shutoff contact wire, but other than that, it's running well!

UPDATE 3: Ok, so this thing has been up and running for close to a year now, and i works great. @ more modifications I did since the last update were one: i added about 3 megohm of resistors to the sensor circuit, to cut the current put through the bucket of water and reduce corrosion on the probes. The other was to use some titanium rod (from for probes, again, to limit corrosion, and because it's cooler with titanium bits.

We use it on a day to day basis now, and it just works like a charm, really couldn't be happier. Might add an hour meter some day, to help keep track of the age of the various filter cartridges.