Arduino Vivarium Automation

Discussion in 'Projects' started by Ishwhale, Jul 25, 2016.

  1. Ishwhale

    Ishwhale Well-Known Member

    I suppose I'll post this little WIP.
    At the end of August my girlfriend and I are taking the plunge...no not marriage. We are adopting a little baby noodle. There's a reptile expo that comes through town and we went to one last year and fell in love. So we have been planning for this year to get one.
    I have 3d modeled most of the enclosure I'll be building. It is going to be out of wood with stain and sealer. The floor is going to be acrylic or pvc. I will attach heat tape to the bottom for the hot side and there will be routed channels in the ceiling for led strips. This is where Arduino comes in.

    I plan to have temp sensors on the heat tape to read the temp at both ends of the enclosure. It will compare the actual temp with what I want it at and decide whether or not to switch the relay on or off.

    For lighting I will rout channels in the ceiling of the enclosure. I haven't decided whether I want to rout all the way through so there can be some ambient lighting out of the top or just stick with the noodle's light. I will decide that later. Anyways, I will place the led strips with hot glue or something and then pour epoxy into the channel to diffuse the light. I got a RTC board for the Arduino and plan to have the lights fade in based on time of day. So at dawn they very lightly come on and gradually fade in till they are brightest at noon. Then fade out till dusk where they turn off.

    I have started ordering parts and stuff. This is my first time using arduino, but it doesn't seem too hard. I have taken classes on C++ so I know the basics. Now for some images cause tl;dr

    This is my proposed circuit. The temp sensors I have are a bit different but it's the same basic concept. There's a DHT22 to read ambient Humidity and Temp as well. I believe the LCD I got comes as a kit so I can wire it up with the pot and buttons and only use two wires for the Arduino.

    In other news I'm really *Can'tSayThisOnTV*ing annoyed that I couldn't get the data wires perfectly vertical on pins 12 and 11. I messed with it for an hour.

    [​IMG]

    This is my 3d modeled enclosure minus the door. It's a box...a glorified box. I was learning AutoCAD as I did this so it took me way too long. It is 18" X 48" X 15" I think. There's a 4" substrate dam in the front.
    [​IMG]
     
  2. samjc3

    samjc3 #1 Female Member

    Looks like a solid plan to me. My brother has been trying to get me to build him something like that for his noodles for years now, but I can't be arsed.

    What kinda noodle are you gonna get?
     
  3. Ishwhale

    Ishwhale Well-Known Member

    Thanks for the kind words. It's going swimmingly so far seeing as how I've never messed with this stuff before. There's a wealth of tutorials and info that makes it pretty easy to find what you're looking for.

    We are getting a Pied morph Ball Python.
     
  4. ttsgeb

    ttsgeb Breaker of Everything Staff Member

    [​IMG]
    Took like 2 minutes.
     
  5. Ishwhale

    Ishwhale Well-Known Member

    God damnit
     
  6. Ishwhale

    Ishwhale Well-Known Member

    I have made progress in the last couple of days. I have my prototype almost all wired up as far as the temp control. I have the DHT22 Reading ambient temp and humidity and printing to the lcd. Then I have my DSB1820 wired the same way to monitor the heat tape. I wrote an if else statement so that if the temp is below a certain number, the relay powering the LED at the moment will kick on. When it reaches that temp or above it kicks off. I will eventually be wiring the heat tape to the relay and changing the values of the temps I want but as far as testing goes, it's all if working order. I might purchase a Pro Mini board for the final and permanent wiring set up.
    [​IMG]
     
  7. ttsgeb

    ttsgeb Breaker of Everything Staff Member

    I see you gave up entirely on the right angles thing.
     
  8. samjc3

    samjc3 #1 Female Member

    At this point, who hasn't?


    Looking good, right angles notwithstanding. That noodle is gonna have a lovely life, I suspect. And happy noodles are best noodles.
     
  9. Ishwhale

    Ishwhale Well-Known Member

    Alright I've got a question:
    So I referenced the DHT22 example off of Adafruit when I was writing the code for the sensor. I wrote in the two second delay because I know it's a slow sensor. However the DSB1820 temp sensor I am using is faster. I think i remember it only needing 750ms or something. The delay(2000) is at the beginning of the loop function so that means everything is going to update every two seconds. I was wondering if there was a way to bypass the delay when it comes to the DSB1820 so that it updates faster.

    In my live demo with the heat tape it will reach 95 degrees and shut off, but since it delays two seconds before checking to kick on again, the heat tape loses a couple degrees in that time frame. If I can shave that data send down to the 750ms I can get the heat tape to hover closer to my desired temp.
     
  10. samjc3

    samjc3 #1 Female Member

    Well, the "correct" way is to use some global variables, like:

    Code:
    const int DHT22Interval = 2000;     //interval to check the DHT sensor
    const int DSB1820Interval = 750;       // interval to check temp
    
    unsigned long currentMillis = 0;     // store the value of millis() in each run of loop()
    unsigned long PreviousDHT22Millis = 0;   // store the milliseconds last time you checked the sensor
    unsigned long PreviousDSB1820Millis = 0; // ditto for the other sensor
    
    void loop()  {  //this loop just runs the other code blocks and maintains the time in currentMillis
    
       currentMillis = millis();  // captures the latest value of millis()
    
        readDHT22( );
        readDSB1820( );
    }
    
    void readDHT22( ) {
    
         if (currentMillis - previousDHT22Millis >= DHT22Interval) {
           //read the sensor and log your data or whatever here
             previousDHT22Millis = currentMillis // updates the time for the next loop
        }
    }
    
    void readDSB1820( ) {
    
         if (currentMillis - previousDSB1820Millis >= DSB1820Interval) {
           //read the sensor and log your data or whatever here
             previousDSB1820Millis = currentMillis
        }
    }
    
    
    
    
    That way your loop will run, and each time either sensor hits it's update threshold, it'll run it's update routine and you can take whatever action you need to - just add your monitoring or feedback loops into the main loop( ) so they all run with each iteration. It's all still linear, but the code will run fast enough that it doesn't actually matter that it isn't parallel.

    Alternatively, if you're feeling lazy, there is a library called TimedAction that aims to simplify what I've described above so you don't need to think about it.
     
  11. Ishwhale

    Ishwhale Well-Known Member

    This is amazing. Exactly what I was looking for. Thank you!
     
  12. Ishwhale

    Ishwhale Well-Known Member

    Alright. So my code is working. I have five different thermometers monitoring the heat tape to assure that the probe is doing it's job accurately. I have come across another issue. Every once in a while my lcd starts flickering garbage text. I read that this is because of the noise generated from the relay flipping on and off. I have found some people saying to put a cap in parallel with the relay and others have code workarounds. What would be the best way to fix this?
     
  13. samjc3

    samjc3 #1 Female Member

    Well, an inline cap seems the simplest, so it's what I'd try first. Though the more interesting solution is to connect it to the internet instead so you can just check it on your phone. You know, because adding complexity at every turn is always the answer.
     
  14. vskid3

    vskid3 Well-Known Member

    And I thought I was fancy for having my corn noodle's light on a timer.

    How much will the materials for just the enclosure cost? My snake is a little overdue for a bigger tank and I wouldn't mind building if it'll save a little cash.
     
  15. Ishwhale

    Ishwhale Well-Known Member

    I'll try the cap and report back. I have been busy this week so I haven't really had a chance to work on this.

    I'm thinking all materials will cost around $180. Not including tools.
    That's including:
    A big sheet of plexi
    Plywood
    Hinges and Latch
    A sheet of clear glass
    Epoxy Resin with colorant
    Pneumatic staples or nails
    Silicone caulk
    Rubber feet
    Aluminum Tape
    Wood Glue

    I haven't gotten everything yet as I am still setting up the temporary enclosure, but that's my best guess.
     
  16. samjc3

    samjc3 #1 Female Member

    Not sure on final costs or anything, but I know my brother has managed to get some really cheap tanks off craigslist, so it may be worth looking around there too. DIY is great and all, but if you can find a 150 gallon box for $75, DIY can screw off.
     
  17. Ishwhale

    Ishwhale Well-Known Member

    Alright. It's been a while, but I've been working on this the whole time and gotten much more progress.

    I've have the snek for about a month now. He's eaten one live and I finally got him to take one F/T mouse. He has also shed once. Mostly a full piece except for a small bit at the end of his tail past the vent. Got him some new substrate to bump up humidity but that's still proving to be hard to keep up so I ordered a fogger that while run for about 30 minutes a day. That should do the trick.
    The other small issue I've run into is the ambient temps are low cause I only have the heat tape on the hot side. In the meantime I've set up a space heater near the tub to warm it up. The tradeoff is that is gets more dry, hence the fogger.

    I've been prototyping for the dynamic lighting system and for a second probe/heat tape. I'm hoping that with the small volume, having heat tape on the cool side at 80 will warm up ambient air in the enclosure.

    My lighting system got a bit more complicated after a small reddit post I made started giving me more ideas. Instead of the light just fading in at dawn and fading out at dusk, I've switched to an RGB setup that fades in at dawn with a pinkish purple for a half hour, then fades through the orange hues, then through yellow to a cool white for daylight. It basically does the same thing backwards for evening/night.

    I bought a arduino micro to work on this as I would like to have the smaller form factor in the finished product as long as there's enough memory in it. So far my dual temp sketch fills about 50% of the memory and the lighting fills about 30% so I still have some wiggle room.

    Right now I'm monitoring my timing schedules for the colors and writing the dual temps. Also working on peripheral raspi flax but I won't go into that.

    Pictures:
    This first one isn't that exciting as it's basically the same as before but with another DS18B20 hooked up. There's a question about this below.
    [​IMG]

    This is the prototype for the lighting. It's just a regular RGB led right now. I'll be ordering an addressable strip soon. I folded an origami water balloon to diffuse the light. The lcd counts the time and below that it shows which phase the light is in. I like having it next to me while I work on stuff. It lets me know when I've been sitting here too long. There's also a question about this below.
    [​IMG]

    Questions:
    Okay I have two questions.
    First one has to do with the two temp probes. In my code I am using the Onewire and Dallas Temperature libraries. Onewire allows you to hookup multiple DS18B20 probes to a single lead on the arduino. They all have a unique address like a MAC address in a wifi network that allows you to address them individually or as a group.

    I have the addresses and have set them with indexes 0 for the cool end probe and 1 for the hot end probe. I've also created variables for the two ports on the relay called coolRelay and hotRelay.

    There are if then statements for both sides but no matter which order I put them in it always displays the hotEnd first and flips the relay on regardless of the temp.

    This is a block of code for displaying the coolEnd temp:

    lcd.setCursor(0,1);
    lcd.write(byte(0));
    lcd.print(" ");
    lcd.print(sensors.getTempFByIndex(0), 0);
    lcd.print((char)223);
    lcd.print("F");

    I'm calling the temp by the index 0 which ive set to be the cool end but is still shows the hot end there. I feel like my indexing or something is wrong. If someone wants to look at my whole sketch let me know and I can PM it.

    My second question is about the lighting.
    I am using a tailored version of crossFade from adafruit. There is an option built in to change the speed of the fade from one color to the next. However if I change that to anything above zero, it causes my clock to not update because it's hung up in the for loop of the crossfade. I know you can't run two things at once but is there a way to prevent my clock display from freezing while it's in the loop?

    Sorry for the wall of text and flax. I had a lot to share.

    Cheers
     
  18. Ishwhale

    Ishwhale Well-Known Member

    I finished this and it's been running for about six months now with few hiccups. I have decided to do away with the color changing aspect which is a bit sad cause I spent more money on the strips than I needed to, but it's okay. Aldrich has only refused one meal since and that was because he was going into shed and was virtually blind and agitated at that. One of these days I'll get all the photos and things together for it.
     
    ttsgeb likes this.
  19. ttsgeb

    ttsgeb Breaker of Everything Staff Member

    RIP the most important part of it all.
    Is it really worth it if you don't have light effects? I think not.
     
  20. Ishwhale

    Ishwhale Well-Known Member

    After observing it over the period of a few days, I've decided to keep it as is. It's obvious that he recognizes the color changes as a sunrise/sunset. He always makes sure to be in a hide by the time it comes on in the morning. As soon as it starts to move into the eve colors he pokes his little head out and yawns. He comes further out the darker it becomes. It works as intended so I'll just leave it.
     
    ttsgeb likes this.