DIY Raspberry PI Tank Monitor Project

Discussion in 'Equipment / DIY / Reviews' started by Rob, Jun 5, 2012.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Users Viewing Thread (Users: 0, Guests: 2)

  1. Simon Simpson

    Simon Simpson Member

    Messages:
    3
    Ratings:
    +0
    Country:
    United Kingdom
    State:
    west yorkshire
    That Looks Cool Would you share the code :)
    Be nice to be able to get the pi to run this and monitor the tank :)
  2. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    Just seen these new enclosures they come in three sizes however the smaller one is great for RPi or arduino style projects. the lower section has cutouts for cable glands etc and the door swings open. http://www.altronics.com.au/p/h9306-ip65-industrial-control-box-166w-x-93w-x-161h/

    they look soo good and perfect for a sump cabinet being Ip65. aimages.altronics.com.au_prod_h_H9309.jpg

    I think I will mount my RPi and an arduino board inside one of these and put it in my sump compartment.
    • Love It! Love It! x 1
  3. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    • Like Like x 1
  4. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    Purchased a small wireless bridge for the aquarium to replace a large unit which I had been using. Slowly trying to organise my wiring and equipment. My cable router is too far away from the aquarium thus I need to use wifi to connect my RPi and GHL 3.1N

    This unit was 40.00 from ebay, netgear Trek. It has two ethernet ports and wifi enabled. plugs directly into the 240VAC so is compact and it also provdes 5VDC out of a USB port which could be good for an arduino or the like. Cannot find the specs of how much current it can supply, so will have to keep looking.

    I have installed this buried deep within the mess of 240VAC wires and it still gets a great signal. I have the rasberrypi and the profilux 3.1N aquarium controller connected to its 2 ethernet ports. Configured as a bridge this device is transparent on the network. The unit can also be pwoered from 5VDC mini usb port on the back of it so I eventually will power this from my 12VDC power supply through a converter (12VDC -> 5VDC) to try and remove alot of plug packs etc we all seem to accumulate on our power boards.

    trek.jpg
    Last edited: Jul 9, 2014
    • Like Like x 1
    • Love It! Love It! x 1
  5. Kypeli

    Kypeli Member

    Messages:
    6
    Ratings:
    +2
    Country:
    Other
    State:
    N/A
    Hi Rob!

    I've been watching with interest this forum and how your project goes on. It has gathered some nice and well deserved attention!

    One small question though: how did you connect the Atlas Scientific pH probe to the RPi? And did you use this kit? Update: Oh well, cannot post a link to their website. But they sell a pH sensor for $60 and I was wondering did you buy directly that or assembled the sensor some other way, yourself?

    AFAIK that comes with a BNC connector and I can't understand how to connect that do the RPi.
  6. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    Hi

    one of these will connect directly to the RPI GPIO as it runs on 3.3V which is what the RPI tx rcv pins are.
    awww.atlas_scientific.com__images__embedded_images_ph_circuit_01.jpg


    If you want to expand and add more sensors your can use this device, serial port connector.
    awww.atlas_scientific.com__images__top_photos_components_mux_demux.jpg

    I would start out simple and use pH. to make sure it all works before adding more sensors.


    The ph sensor board just needs +(3.3), GND, tx and rcv pins connected to the pi
    • Like Like x 1
  7. Kypeli

    Kypeli Member

    Messages:
    6
    Ratings:
    +2
    Country:
    Other
    State:
    N/A
    Thanks Rob for your quick reply! I do not have much of a electronics background, hence it's difficult for me to grasp how each component connects to each other, even though I would understand what the components do :)

    But I think your reply cleared things out for me. In case others are wondering about similar things, I would summorize the components that I need in order to measure pH as follows:
    • pH sensor circuit from Atlas-Scientific (as pictured by Rob). Connects the pH data signal from the pH circuit to the Raspberry Pi's serial connectors.
    • Pre-assembled female BNC connector from Atlas-Scientific to hook the BNC connection from the pH probe to and connect the BNC connection to the breakout board. Connects the pH probe to the pH circuit I mentioned above.
    • Finally the pH probe itself from Atlas-Scientific. BNC connection from the probe is connected to the BNC connector I mentioned above and the probe itself is submerged in the tank.
    I do realize this is self-explanatory for many :) But for me it was not clear how all the components fit together - or what components are even needed in the end.

    And I hope I did get this correct :)

    Thanks Rob! In my case, I would be more than happy to get temperature and pH readings from my tank, as I only have a freshwater tank. I already have the temperature working, so how to get pH readings has been the next mystery for me.
  8. Kypeli

    Kypeli Member

    Messages:
    6
    Ratings:
    +2
    Country:
    Other
    State:
    N/A
    Oh - on that note (from the previous reply): I am also struggling to find a proper breakout board to solder the necessary components on to. I now only have a breadboard to test things out with, and I don't think that's going to hold in the end.

    If I may ask, what kind of breakout board for soldering the components on to would you recommend? Sorry for this novice question, but I don't even know what to ask for if I go to the local electronics store...
  9. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    You do not need a circuit board

    1. The BNC connector is directly soldered to the atlas board.
    2. The atlas board has 4 pins to connect to a jumper wires
    3. Simple wiring using 4 female jumper wires

    Atlas------ RPi
    Vcc -- > 3.3V
    GND -- > GND
    Tx -- > RCV
    Rcv --> Tx

    Thats all there is 4 wires.

    I can give you the code snippet to use for the pH device

    You say you already have temperature running, have you direct connected a 1wire DS18B20 to the RPi GPIO ?
    Last edited: Jul 16, 2014
    • Like Like x 1
  10. Kypeli

    Kypeli Member

    Messages:
    6
    Ratings:
    +2
    Country:
    Other
    State:
    N/A
    That would be of course very helpful and kind of you!

    Yes, exactly like that. The RPi w1-gpio and w1-temp kernel modules work like a charm.
  11. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    This will be good information for me to further develop as documentation for our raspberryPI hackers day we are trying to get together here in Melbourne Australia this year

    Serial port setup for atlas devices....

    Disable Console Messages as per this post. this will free up the serial port so that the shell can use it.
    Reference: abelectronics.co.uk

    Script to read serial port

    Code:
    #!/bin/bash
    #title       :AquaPi Read Script
    #description :Read sensor data, range test then write data to file
    #author      :R Conway
    #date        :July 2013
    #version     :23
    #usage       :Start script in background [nohup /var/script/DataScan >/dev/null &]
    #notes       :if you kill the script you also kill the cat process left behind
    #=======================================================================
    
    stty -F /dev/ttyAMA0 raw 38400 cs8 -ignpar -cstopb eol 255 eof 255
    (pkill -x cat)
    
    while true ;do
    
    ###  Read pH and ORP from Atlas Scientific Devices ###
    ( cat < /dev/ttyAMA0 > ./serial_in ) &
    bkgPID=$!; disown $PID
      sleep 2
       printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 1
       printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 2
      kill $bkgPID >/dev/null
      read ReefPH  <./serial_in
    ReefPH=$(echo "$ReefPH" | sed 's/.\{1\}$//')  # Delete Trailing Carriage return
    
    This is how it works.

    I could of used python and the serial library however this worked for me and never bothered changing it. I know programmers hate doing things in shell scripts especially serial port stuff but I had all the rest of my program already running in bash.

    Some more comments on the code above

    Sets up the serial port for baud rate and communications suitable for the atlas devices
    stty -F /dev/ttyAMA0 raw 38400 cs8 -ignpar -cstopb eol 255 eof 255


    If the script terminates it can leave open a previous cat command. If this happens the script will not run. So on startup of this script we simply kill any processes called cat that maybe running
    (pkill -x cat)

    OK here comes the spot you would start a continuous loop (I show it commented out (##) as this is just a part of the overall script.
    ## while true ;do

    ### Read pH and ORP from Atlas Scientific Devices ###


    Start up a process and CATenate the serial port and store it in a file called serial_in in the current directory
    ( cat < /dev/ttyAMA0 > ./serial_in ) &

    The cat process started above has to be disowned from this script so it can be killed further down
    bkgPID=$!; disown $PID

    sleep 2

    OK here we go send out a read command to the serial port. x72 is hex for the ascii character r xOD is carriage return. The Atlas manual states you send the board “r” and it responds with the value. I have found I needed to do this twice to get reliable data thus the two lines the same.
    printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 1
    printf "\x72\xff\x0D" >/dev/ttyAMA0 ; sleep 2



    Whilst we have sent the character r to the atlas device it has responded with the actual value. That’s why we started uop the “cat process at the start. Cat has captured the serial rcv port and placed it in a file called serial_in. before we can read what in the file we have to kill the cat process as the process has locked the file and we cannot read it until we kill the cat.
    kill $bkgPID >/dev/null

    This line simply reads whatever is in the serial_in file into a variable called ReefPH
    read ReefPH <./serial_in


    The data from the atlas device contains an annoying carriage return. We have to strip the carriage return from the value so that you can use the data as a floating point number. If you do not do this ReefPH contains ASCII letters and the script cannot do any calculations etc on an ASCII data so basically this turns an ascii data into a floating point number.
    ReefPH=$(echo "$ReefPH" | sed 's/.\{1\}$//') # Delete Trailing Carriage return


    You are now free to do whatever you want to do with the variable ReefPH

    I will post up my entire script however may confuse you at this stage. So lets see if you get the idea above before I go onto error checking and logging for you.

    Oh just remembered we have a code manager Ill try and find this feature and post my entire logging file there.
    Last edited: Jul 16, 2014
    • Like Like x 2
    • Love It! Love It! x 1
  12. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    Seems to be a new 1wire USB adapter on the block. I know RPI has now within the kernel support for the 1wire temperature probe 9DS18B20) however a USB implementation has a couple of advantages:

    1. No wiring to GPIO or soldering resistors. This unit is just USB.
    2. The unit seems to have stereo plugs for the wire devices so easy to wire. You can even use a stereo splitter. 1wire deices all simply connect in parralel, as they all have a unique address. they have a $10 temp probe with plug already on it.
    3. USB 1wire adapter supports all 1wire devices, thus easy to add pulse inputs from flow meters etc using the 1wire dual input counter module.
    I ahve not tried this unit however very tempted to buy one and give it a shot. In my case Im after measruing RO and NSW flow lines into my tank.

    $18.00 New 1wire USB dongle (have not tested as yet) you need to use OWFS running on the PI. There are other usb 1wire adapters that I know work however this is cost effective and has 2 x stereo plugs for the device connections.

    aencrypted_tbn3_gstatic_com_images_b30bf925acbf29a36cdef079fdf6446d._.jpg

    $8.00 Flow meter 1-8 L/min , I have 2 of these and they provide a pulse output proportional to the flow

    upload_2014-7-19_23-26-54.jpeg


    1wire dual input counter module, it even has a battery backup. simply stores the pulses from each channel.. Then over 1wire you just read the accumulative number and multiply by a flow factor.
    aencrypted_tbn0_gstatic_com_images_da0e925d8988d29845a6fbce6adcc4e5._.jpg


    Ill keep you posted when I test it..

    Oh.. forgot to provide some background.... A flow meter provides a pulse output, its really just a switch that turns on/off as the flow passes over a paddle wheel within the flow meter. It would be tedious to count these pulses directly on the RPI GPIO pins so 1wire provides a solution. Just like a 1wire temp probe there are many different 1wire devices. they ahve a 2 channel counter module that simply counts how many times a contact is closed and stores this within its memory. So the flow meter & counter module run independently. Using 1wire to gather the data from the memory of the counter module say every 1 minute allows you to read the accumulated number, subtract from the last reading then you multiply this by a flow meter factor. each flowmeter has a factor which is simply pulses per L.
    Last edited: Jul 19, 2014
  13. Kypeli

    Kypeli Member

    Messages:
    6
    Ratings:
    +2
    Country:
    Other
    State:
    N/A
    • Like Like x 2
  14. Mahesh

    Mahesh Member

    Messages:
    1
    Ratings:
    +2
    Country:
    United States
    State:
    TX
    Hello,
    I am working on an exact similar project. I just found this thread while searching for some information on i2c. I am looking at the atlas scientific pH sensor and the new model is i2c capable. Some basic information:
    The system I am designing is for a freshwater planted tank with pressurized CO2 system.

    1. Raspberry Pi
    2. DS18b20 waterproof temperature probe for the tank (1-wire)
    3. Temperature pressure module for external temperature
    4. RasClock RTC (i2c)
    5. SainSmart 8 channel SSR relay to control outlets
    6. The core program is in Java ME.

    At this point the following things are outstanding:
    1. Custom board design to solder all the devices to one board (except the relay). Working on eagle.
    2. Front end website (php) to graph the data (time vs pH, time vs Temp x 2)
    3. Front end to display outlet status.
    4. Dosing pump system (3 pumps with simple on-off)

    At present I am using a generic project box to put all the electronics into. If the circuit and code work well, I will look into redesigning the circuits so that all of them (RTC/sensor inputs/outlet control outputs) are in one generic RPi shield and have a custom enclosure made. I believe this will be sometime next year.

    Also, If all goes well, I will be designing a similar system for my saltwater nano-reef but will be using Beagle Bone Black as it has more GPIO and PWM pins (LED control)
    • Like Like x 2
  15. exofish

    exofish Member

    Messages:
    1
    Ratings:
    +0
    Country:
    United Kingdom
    State:
    yorkshire
    Hi

    I am also building / built this same setup as Mahesh, for the same reasons :D My planted tank.... (Great minds think alike)
    my last piece of the hardware puzzle for my setup was monitoring PH to control my co2 wanted to know if the ph sensor would run plug into the PI directly now i have!

    I've been running a setup now for a couple of months building a system Based on arch and some other goodies. Ive managed to get a working setup.:stop wait! I say working but its nothing more than a glorified timer control system using python scripts. That can tell me how warm my tank is and email me if there a parameter i don't like. With a basic web front end with on off and temp display.

    so not wanting to reinvent the wheel i though i would see if anyone built anything software wise that i could use / manipulate for my needs. :reading

    Was So happy to see a thriving community in the world looking to PI up there tanks! :worshipwell done Rob it looks grand. its piecing together nicely.

    just have a question for you really do you see any issues in getting this up and running on arch.
    will there be a github? or a google code can get the font end working.

    I Also built the
    8 channel relay
    PI Model A
    DS18b20 One wire Waterproof x 4
    (on the shopping list PH probe and board ) finally should be able to grab the pH data and shut off the co2 accordingly

    Once this system is finished and working i want it to control my nano tanks one maire one planted.

    Mahesh it looks like were trying to achieve the very same thing so if you like to collaborate please get in touch...

    Happy tanking everyone..
  16. onkel.paul

    onkel.paul Member

    Messages:
    16
    Ratings:
    +0
    Country:
    Germany
    State:
    NRW
    Hi Rob,
    I come from Germany apologize for my bad Google-English!

    I have your Raspberry PI Tank Monitor Project recreated for my koi pond.

    A class project of you !!!!

    Unfortunately, I'm with the RRD Toll not, I can not programieren it but after construction of your web page: rjconway.homeip.net

    I miss the files to the cgi script or graph.pl.

    Can you please help me there.

    Thank you from Germany.:worship
    Last edited: Nov 25, 2014
  17. MagicJ

    MagicJ Moderator

    Messages:
    10,033
    Ratings:
    +5,710
    Country:
    Australia
    State:
    Tasmania
  18. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    @onkel.paul The files were up on the raspberrypi early ftp site for a while although I think we have now changed how files can be stored. Anyhow I will get my www directory from my running RPi and send you the link to them and post some instructions. You WILL get this running :)
    • Like Like x 1
    • Love It! Love It! x 1
  19. The Reefuge

    The Reefuge Administrator

    Messages:
    4,199
    Ratings:
    +2,332
    Country:
    Australia
    State:
    Victoria
    • Like Like x 1
  20. Rob

    Rob Member

    Messages:
    875
    Ratings:
    +703
    Country:
    Australia
    State:
    Victoria
    Ill post back when I have uploaded my files to the Reefuge Code manager.
    • Love It! Love It! x 1

Share This Page