ATO Using Microcontroller & Float Switch

Discussion in 'I made this!' started by wildblue, May 2, 2009.

to remove this notice and enjoy 3reef content with less ads. 3reef membership is free.

  1. wildblue

    wildblue Astrea Snail

    Joined:
    Mar 15, 2009
    Messages:
    52
    Location:
    Denver, CO
    ATO Using Microcontroller & Float Switch Part I

    Preface: This won't cover all of the things needed to understand exactly how this works, such as basic electronics and programming. However, even without this knowledge, anyone should be able to copy this without much trouble. There will be no soldering involved, though it would be preferable to solder this circuit together on a protoboard. If you are not comfortable with working with mains power, do not attempt this. Ensure that the relay you purchase is rated for the voltage and amperage you will draw. Follow all safety precautions when playing with electricity and water. This works well for me. But I can't replace any fish, inverts, children or equipment if something horrible happens.

    Materials:

    • 1 x pump/powerhead capable of moving water from topoff container to sump(with hose).
    • 1 x topoff container to hold water.
    • 1 x Float Switch (Example). (Consider getting a few in case of failure,shipping damage, etc. Seven bucks.
    • 1 x 10k Resistor(1/2 or 1/4 Watt is fine) (Radioshack, jameco.com) A Few bucks.
    • 1 x Arduino Dicemilla/Duemilanove(Adafruit, Sparkfun, Arduino.cc) Adafruit has a starter pack that comes with a mini-breadboard, some assorted leds&resistors,usb cable and a wall wart. This is the way to go if you don't already have a breadboard and a 9-12vdc adapter. It will jack up the cost from around $40 to $65, but the breadboard sticks on to the protoshield which plugs onto the arduino. Self contained and cleaner. And it comes with everything this project requires except the float switch and SSR.
    • 1 x Breadboard If you don't buy the starter kit.
    • 1 x 9V DC Power Adapter (2.1mm barrel, positive tip) If you don't buy the starter kit.
    • 1 x Solid State Relay. (Picture), Ebay, Jameco.com. If you are serious about playing with the arduino, buy a few of these. You can use the Leds that come with the starter kit/buy some and make a sunrise/sunset routine, using the arduino to control more SSRs attached to your normal lighting.
    • 1 x 1"x1" Acrylic square Will be drilled and glued in sump as a mount for the float switch. You can get creative here. The important points are that it will be stable and that you can set it up to the height you need.
    • 1 x Extension Cord Hardware store/Wallmart,etc. You will be cutting this, don't use one you need elsewhere. If your pump/powerhead has a grounded plug, make sure this does as well.
    • 1 x Project Enclosure The one I'm using is a 6x3x2. links
    • Solid Core Wire (Radioshack, hardware store, etc). Breadboards suck without this.

    Preparation:

    Once you have all the materials, you will need the software which allows you to program the arduino. You can download it here. Once it is installed, you're ready to start wiring things up.

    Hardware:

    For simplicity (and because I don't feel like unhooking the current setup), I'm going to use the starter kit. If you opt to use a normal breadboard, skip the next few steps where we throw the protoshield together.

    [​IMG]

    Take the arduino out of the anti-static bag and look at it. You should see something similar to this. Notice the pins on the top, 1-13. These are the slots you can use to control LEDs & relays as well as take inputs from switches and buttons. The 'Analog in' pins on the bottom can be used for things like photoresistors, PH meters, etc. This project will use the slots on the top (Specifically pins 11 & 12).

    Next, take the protoshield out of its bag and plug it into the arduino.
    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    After you're plugged in, stick the breadboard in the middle.

    [​IMG]

    Wiring:

    To start off, we're going to wire the power and grounds up from the arduino.Look at the base of the black rails and you will see that they are labeled. Look for the 5v and GND. Wire up like so:

    [​IMG]

    [​IMG]

    Now do the same to pins 11 & 12 on the opposite side.

    [​IMG]


    Snip your 10K resistor down and bend it.

    [​IMG]

    [​IMG]

    Plug resistor in like so, and run a wire from 11s row to it. This is called a pull down resistor and is required for the circuit to work properly.

    [​IMG]

    [​IMG]

    We're actually nearly finished. Next to hook up the float switch. The wiring on the switch isn't solid core (it has a bunch of strands of copper instead of a single larger one), so it is a pain to plug in to the breadboard. You can either splice a short piece of solid core to the ends, or not. The best way would be to follow this instructible using solder. As this tutorial is solder-less, you may follow it, but not use solder. The connections won't stand up to tugging or much motion though. So use caution when moving wires around.

    [​IMG]

    [​IMG]

    Now to plug the float switch in, The switch will be connected between the 5v rail and pin 11(the one already hooked up to the pull down resistor).

    [​IMG]

    Last part of wiring up the arduino is going to be for the relay. To test, we are going use an led. After confirming it works, we'll wire up the relay itself. Make a connection between the GND rail to one next to Pin 12s rail. Plug in an led from your kit between the two rails, the longest wire from the led goes to pin 12s rail(longest wire is always positive), the shorter to the GND rail.

    [​IMG]

    [​IMG]

    More after the break...
     
    Last edited: May 2, 2009
    1 person likes this.
  2. Click Here!

  3. Matt Rogers

    Matt Rogers Kingfish

    Joined:
    Dec 31, 2000
    Messages:
    13,466
    Location:
    Berkeley, CA
    Outstanding! :thumbs_up:clapping:

    GREAT DIY!
     
    1 person likes this.
  4. wildblue

    wildblue Astrea Snail

    Joined:
    Mar 15, 2009
    Messages:
    52
    Location:
    Denver, CO
    ATO Using Microcontroller & Float Switch Part II

    The Float Switch

    Waterproofing the switch is next, when the return pump is off, you know what the water level does. ;D These switches aren't meant to be submerged. The epoxy where the wires go in isn't guaranteed to be waterproof. Just snip some 1/4" air hose and slip it over the wires all the way down to where then enter the switch itself. Silicone around the end of the hose/switch with your finger. Ensure that the piece of hose is long enough so that it will always be higher than the water in your sump. Mine is about even with the top of the sump.

    Allow the silicone to begin curing, after it's no longer tacky, re attach it to the breadboard and move on the the next steps. When you go to install the float in your sump, mount the switch however you see fit. When the water level is full, the float should be midway up the shaft. I just drilled a hole in my square piece of acrylic and used superglue & silicone to attach it to the side.

    [​IMG]


    [​IMG]

    [​IMG]



    Software:

    With the switch wired up, we're ready to test. Make sure you have downloaded and installed the arduino software from the link given earlier. Next download and install the USB driver from This page


    Plug in the arduino to your computer using the USB cable.

    Run the arduino software. If you have trouble use This Guide.

    Once you're up, you should see a screen that looks like this:

    [​IMG]

    Copy and paste the code from Here into the main text area.

    [​IMG]

    Next go to the menu at the top: File->Save As Name it TopoffTest.

    [​IMG]

    Now click the Upload to Board button.

    [​IMG]


    If you get a 'Serial Port 'COM1' not found error, check the Tools->Serial port selection to make sure you've selected the correct serial port. The setup page linked above goes into more detail.

    Once you've uploaded to the board, you should be able to play with the float switch and see the led come on and off. Try moving the float from about mid position to the bottom. The led should light up for two seconds and then turn off. Moving the float back to midway up should stop the led from turning on.

    If you see the above behavior, congratulations. You're ready to upload / tweak the final code, if not then recheck your wiring and make sure the arduino is hooked up properly and running.


    Wiring up the SSR

    If you've made it this far, there are really only a few things left to do: Wire up the SSR to the extension cord & arduino, upload the non test code, secure the float switch and run it.


    Wiring up the SSR is pretty easy. If you look at yours, it will have an input side and a line side. In this picture here, terminals 3 & 4 will be wired to the arduino, 1 & 2 are wired up to the extension cord.

    [​IMG]

    Cut some more solid core wire, unplug the led on your circuit and plug the wires in. The wire coming from pin 12 ( same rail the longer wire on the led was plugged in to) goes to the positive input on the relay (terminal 3 in the pic). The ground wire goes to the negative terminal (4).

    This is a good place for the obligatory warning. This relay and the splicing you will be doing will deal with 120 volt AC current. The relay isn't waterproof or resistant. The terminals are exposed. This should not be left this way. It needs to be enclosed and placed where pets/children/water/curious people who like to touch random things cannot get to it.

    Whatever you enclose it in needs to be non-conductive and mounted/screwed in place.

    Never mess with the relay while the extension cord from the wall is plugged in. The arduino side is 5v dc at a very low current and won't hurt you. No guarantees though if you drop it in your sump for some reason and the stray current fries your inverts.


    Now, take your extension cord and split the two halves length-wise. You are going to cut one(and only one) wire. The other wire is left completely intact. Be careful when separating the two halves that you do not cut into the insulation on the side you *won't* cut.

    Once you've cut the wire, strip 1/4-1/2" of insulation off of the ends and screw those into the AC side (terminals 1 and 2 in the picture).

    When finished it should be similar to this:

    [​IMG]


    If this didn't make sense, or my pictures just sucked. Here is a page with diagrams. Notice the electrical wiring to the pump.


    Upload Final Software.

    The software you ran while testing won't work well for the real deal, so go get a modified version Here and follow the same steps you did with the test version. Name it Topoff instead of TopoffTest when saving. You will probably need to change a few things at the top to tweak it for your particular sump capacity and powerhead/pump rate. onTimeout and offTimeout in particular. onTimeout is how long the pump can run at one time. offTimeout is how much time must elapse before the pump can run again. Everything is measured in tenths of a second. So if you only want to allow your pump to be able to run for two seconds at a time, onTimeout is set to 20. Four seconds is 40. offTimeout is the same, in tenths of a second. I've had to tweak the values a number of times. Start with longer offTimeouts and shorter onTimeouts. My offTimeouts dropped from five hours to 1 hour. I'd rather barely keep up with the evap than have water on the floor and low salinity because of a float switch malfunction. ;)

    After every tweak, upload the saved code and unplug the USB cable from the arduino. If you have a laptop, this is much easier as you can go the tank and do this.

    The following only applies to the dicemilla, the
    Duemilanove switches power sources automagically
    Unplug the protoboard from the arduino and look next to the USB plug, you'll see a jumper labelled USB / EXT. This tells the board where to get its power, usb or the power cord.

    [​IMG]

    [​IMG]


    Switch the plastic jumper so that it looks like so:

    [​IMG]

    Plug your protoboard back in.

    *** End of dicemilla only instructions. ***

    Enclosure:

    Cut out some holes for the USB,power and wiring in the side.

    [​IMG]

    [​IMG]


    Run wiring through for float switch and relay, connect as before.

    [​IMG]


    Final check. Code uploaded, everything wired correctly, relay secure, float switch mounted, pump/powerhead in water with hose going to sump(secured and above high water line when return is off), topoff pump lower than water level in sump?

    If everything looks good, plug in the extension cord and the arduino(using power adapter). It's nice to have your water on the low side so you can verify the pump,flow and turn off at this time. If not, just push down on the float for half a second to verify pump turns on and off when you release it.

    Watch carefully to make sure that the pump shuts off and water stops flowing when it does. There should be no possibility of a siphon to or from the topoff container. Doesn't work? Check the arduino, is the power led on? How's your wiring? Check both the arduino wiring as well as the relay. Pin 11 is to the float switch, 12 is to the relay. Make sure your power jumper on the arduino is set correctly.

    If all looks good, congratulations! Keep an eye on the level for a few days. It should neither fall behind nor overfill. If either of these are happening, adjust your timeouts. Version 2 will have more floats for safety. I'll post a link to that when finished.


    Here is a schematic of the wiring for those it may help.




    Hopefully this will help someone looking to do the same thing. There are many possibilities for improvement, just be cautious and try to think about all the what-ifs. Plugged overflows, bad switches, empty topoff containers. The more you anticipate, the less you'll be surprised.



    Links
    Arduino Basics
    Good basic tutorials and explanations
    Language Reference
    ATO Example
    Float Switches
    Float Submerge Instructions



     
    Last edited: May 2, 2009
    2 people like this.
  5. Otty

    Otty Giant Squid

    Joined:
    Nov 20, 2006
    Messages:
    6,467
    Location:
    Elizabethtown, IN
    Good DIY....karma for that one.
     
  6. Matt Rogers

    Matt Rogers Kingfish

    Joined:
    Dec 31, 2000
    Messages:
    13,466
    Location:
    Berkeley, CA
    Can we pick a pic of the final product? Maybe one in action too?
     
  7. insanespain

    insanespain Ocellaris Clown

    Joined:
    May 3, 2011
    Messages:
    1,479
    Location:
    Illinois
    All these links are broken, does anyone have this code? Or has anyone else written ATO code for an Arduino they'd like to share? Would love to glance at some for ideas.
     
  8. Click Here!

  9. Seano Hermano

    Seano Hermano Giant Squid

    Joined:
    Apr 7, 2010
    Messages:
    10,056
    Location:
    Northwest Ohio
    I noticed that too. I wish we could see the pictures.
     
  10. insanespain

    insanespain Ocellaris Clown

    Joined:
    May 3, 2011
    Messages:
    1,479
    Location:
    Illinois
    Yeah, pics would be cool, but I just mainly wanna see some code examples. I will probably write my own from scratch anyways, but would like to see how he did the pump timeout feature.
     
  11. dinki

    dinki Plankton

    Joined:
    Jan 16, 2012
    Messages:
    2
    Does anyone have the code for this project or know where I can find a similar arduino based ATO?