# Arduino Automated Habitat Control



## spatte88 (Jun 29, 2009)

Hi everybody, unfortunately due to a busy life style lately I've not had chance to post much on the forum! Anyway I thought I'd tell you what I've been up to in case anyone else is interested :whistling2:

Well I'm not sure if any of you saw this POST about my epic stack build, if not have a quick look at how I wired the whole rack up! At the time a lot of people were interested in how I had tidied up the wiring and moved away from horrible timer plugs. Unfortunately the system I used was very expensive, though perfect for automating the environment of my reptiles.

Anyway that rack moved on to a new owner once I moved away from keeping Bearded dragons and I now focus more on Fatties/Cresties. So earlier on this year I decided I wanted to create a similar automated system for my current stack and luckily stumbled across this POST which gave me the idea of using a micro controller! With a bit of research I managed to figure out how to create a simple setup for my reptiles. To reduce the cost of the electronic parts (mainly PCB's) I sold a setup to another member of the community which via a few YouTube videos he got up and running also.

Anyway enough typing, time for a few photos and a few links to videos showing what I've managed to put together so far and what you could implement into your own setups.

*YouTube* video of system getting testing after being soldered together HERE

*YouTube* video of a basic setup HERE

*PROTOTYPE STAGE*



*SIMPLE LCD DISPLAY ADDED*



*PCB DESIGNED TO REMOVE ALL THE WIRES*



*MK1 SETUP*


----------



## Whosthedaddy (Nov 29, 2009)

Wish I was clever.



Wires are the bane of this hobby and need to be eradicated!


----------



## SublimeSparo (May 1, 2013)

Awesome mate :mf_dribble:, i was thinking about Aduino for automating Vivs, need to get me a kit and start learning!


----------



## spatte88 (Jun 29, 2009)

Whosthedaddy said:


> Wish I was clever.


Same here :lol2:

You'd be surprised how easy it is to use an Arduino once you get in to it!


----------



## SublimeSparo (May 1, 2013)

got a microclimate prime2 for an early christmas pressie... that'll tide me over for a while... although I should have got an arduino kit instead :lol2:
Did Electronics at school so I should be alright at it... assuming I can remember things... oh well:bash:

Definitely keep us updated with this project! will have to watch those videos later


----------



## Diamondback (Aug 29, 2009)

Have you thought of how to provide a dimable control rather than an on off one for heat sources such as ceramics etc. 

This is something I have been looking at doing for a while started testing using one wire sensors.


----------



## philipniceguy (Mar 31, 2008)

I got a similar unit up and running myself but it's being added to all the time, very useful things arduino stuff. However I didn't design my one a good friend Stivali on here done all the AMAZING hard work but it's such a useful knowledge to learn so I am slowly learning.

here is it with the temperature, humidity and IR sensors running :2thumb:


----------



## spatte88 (Jun 29, 2009)

Diamondback said:


> Have you thought of how to provide a dimable control rather than an on off one for heat sources such as ceramics etc.
> 
> This is something I have been looking at doing for a while started testing using one wire sensors.


I myself am just moving over to one wire sensors, really nice and stable readings so far! Also attempting to control the system via wifi and upload information automatically to Exosite. Looking promising so far : victory:

Reference dimable control I've not ventured that way currently, will look in to that one shortly, though I know relays won't work as they'll burn out!


----------



## spatte88 (Jun 29, 2009)

philipniceguy said:


> I got a similar unit up and running myself but it's being added to all the time, very useful things arduino stuff. However I didn't design my one a good friend Stivali on here done all the AMAZING hard work but it's such a useful knowledge to learn so I am slowly learning.
> 
> here is it with the temperature, humidity and IR sensors running :2thumb:
> image


Nice, what do you have the IR sensor setup for, camera or is it for temperature?


----------



## Stivali (Apr 9, 2012)

It's running a Melexis IR temp sensor - for monitoring the basking temperature for monitor lizards (something we check often).

Unfortunately it's got too wide an angle of view - which means it needs to mounted closer to the basking spot than the bulb does, but I think I've found a suitable replacement that will be much more accurate from a greater distance with just 10 degree's fov.


----------



## paul23 (May 12, 2011)

Diamondback said:


> Have you thought of how to provide a dimable control rather than an on off one for heat sources such as ceramics etc.
> 
> This is something I have been looking at doing for a while started testing using one wire sensors.


Dimming is pretty easy to do. If you know how to do interrupts and delays, then there is very little programming or circuitry required to get something working. Just make sure everything is isolated from your Arduino, otherwise you will fry it.


----------



## Diamondback (Aug 29, 2009)

paul23 said:


> Dimming is pretty easy to do. If you know how to do interrupts and delays, then there is very little programming or circuitry required to get something working. Just make sure everything is isolated from your Arduino, otherwise you will fry it.


I'm a programmer by trade, just not that advanced with circuits. That's why I asked if a dimming circuit had been devised to get some idea of how that would be done.


----------



## Diamondback (Aug 29, 2009)

spatte88 said:


> I myself am just moving over to one wire sensors, really nice and stable readings so far! Also attempting to control the system via wifi and upload information automatically to Exosite. Looking promising so far : victory:
> 
> Reference dimable control I've not ventured that way currently, will look in to that one shortly, though I know relays won't work as they'll burn out!


I used a one wire module from the link below to hook up to a raspberry pi ( was using arduino but the pi gives me the power to run a web server and other software for graph generation etc. without the need for a Pc.)

Sheepwalk Electronics - 1-Wire products and information.

Who did you use for you prototype board production.


----------



## paul23 (May 12, 2011)

Diamondback said:


> I'm a programmer by trade, just not that advanced with circuits. That's why I asked if a dimming circuit had been devised to get some idea of how that would be done.


I´ve just done a long post describing how to do the dimmer and then I just figured out an easier way. If you need to dim less than 200W you can have one of my spare boards. I use Itead studios for the PCB´s (answers your other question there) so you get 10 boards with your order. I only need 2 boards plus 2 spares, so I have 6 left. You´re welcome to one if you want.

My design is modular, so I have a main board that is doing all the processing and the sensors, relays, etc, then I have another board that does the display, then a third board which does the dimming. The dimming board has its own microcontroller just doing the dimming control. 

In my current design, the main microcontroller sends pulses to the dimmer module and the time between 2 pulses determines the level of dimming required. However, If I swap that out for an I2C interface instead, then all you would have to do is send a value between 0-255 from the Arduino to the dimming module via I2C and that´s it. The only problem would be if you have any other I2C devices, I would need to make sure that I address the dimmer board differently. Other than that I don't see why it wouldn't work.


----------



## spatte88 (Jun 29, 2009)

paul23 said:


> I´ve just done a long post describing how to do the dimmer and then I just figured out an easier way. If you need to dim less than 200W you can have one of my spare boards. I use Itead studios for the PCB´s (answers your other question there) so you get 10 boards with your order. I only need 2 boards plus 2 spares, so I have 6 left. You´re welcome to one if you want.
> 
> My design is modular, so I have a main board that is doing all the processing and the sensors, relays, etc, then I have another board that does the display, then a third board which does the dimming. The dimming board has its own microcontroller just doing the dimming control.
> 
> In my current design, the main microcontroller sends pulses to the dimmer module and the time between 2 pulses determines the level of dimming required. However, If I swap that out for an I2C interface instead, then all you would have to do is send a value between 0-255 from the Arduino to the dimming module via I2C and that´s it. The only problem would be if you have any other I2C devices, I would need to make sure that I address the dimmer board differently. Other than that I don't see why it wouldn't work.


Paul have you got any links to your post that you mention or pictures of your system you could share? I agree dimming say an LED is simple enough though it would be interesting to see what you use to control 240V AC! I imagine you would have to use a MOSFET or TRIAC via PWM.


----------



## spatte88 (Jun 29, 2009)

Diamondback said:


> I used a one wire module from the link below to hook up to a raspberry pi ( was using arduino but the pi gives me the power to run a web server and other software for graph generation etc. without the need for a Pc.)
> 
> Sheepwalk Electronics - 1-Wire products and information.
> 
> Who did you use for you prototype board production.


You can create WebServers with Arduinos, yes you would need an Ethernet shield, Ethernet board or an Arduino Yun, but achievable. I'm currently attempting to learn how to do exactly that with a Yun as it has the same pin out as the UNO, so compatible with the shield I made.

As for my PCB's I use Fritzing Fritzing they provide nice easy to use free software to design with. Your designs can also be uploaded to them for production, though be warned it is not cheap to produce only a few at a time! I personally had to get 10 made (still got some left if anyone is interested?) to reduce the price enough.


----------



## spatte88 (Jun 29, 2009)

SublimeSparo said:


> got a microclimate prime2 for an early christmas pressie... that'll tide me over for a while... although I should have got an arduino kit instead :lol2:
> Did Electronics at school so I should be alright at it... assuming I can remember things... oh well:bash:
> 
> Definitely keep us updated with this project! will have to watch those videos later


Would be great to hear what you think of the microclimate prime 2, will be interesting to see what you think it is missing, anything improved/added etc.


----------



## paul23 (May 12, 2011)

spatte88 said:


> Paul have you got any links to your post that you mention or pictures of your system you could share? I agree dimming say an LED is simple enough though it would be interesting to see what you use to control 240V AC! I imagine you would have to use a MOSFET or TRIAC via PWM.


Check out Itead Studios for PCB production, $9.99 for 10 PCBS, There are also seeedstudios and PCBcart who are similar. I had a bad experience with seeedstudios though, so I use Itead. If you can get a few people working on the same thing, then the boards are very cheap. Itead boards are pretty good quality and quite quick, i use them for small production and prototype runs at work.

I'm redoing my dimmer board now after having the I2C idea yesterday, so my schematics will not really be any use to you at the minute. I will put them up when done if you want. I might open source my whole project when its done anyway. 

The control is through a TRIAC but you can't use PWM. You need a zero-cross detector circuit which causes an interrupt on your microcontroller every time the AC waveform crosses the zero point. So 100Hz (2 times every full 50hZ mains cycle). Then you need a delay and then switch the TRIAC on. The delay basically cuts off the start of each waveform, the longer the delay, the more of the waveform is cut off, the dimmer the lights will be. The TRIAC will automatically switch itself off at the zero-cross point. All you have to do is switch it back on at the right time. 

The zero cross detector is just a bridge rectifier to get the AC to DC and an opto-coupler connected to an interrupt on the microcontroller with a pullup resistor. When a zero-cross occurs, the opto-coupler will switch off causing an interrupt by setting that pin high. When the interrupt occurs, start counting the delay for how bright you want the lights and when done switch on the TRIAC (through another isolator). That´s it, a bit harder than LEDs but not a lot and only a few lines of code and a couple of components. If you want one of my spare boards then you can have one.

The only feature difference I can notice between our projects is that I've included a door alarm, so if the door is open for a set amount of a time an alarm goes off. Stops me leaving the door open by mistake. Also I'm not using Arduino, but that doesn't really matter, it´s all more or less the same.


----------



## spatte88 (Jun 29, 2009)

paul23 said:


> Check out Itead Studios for PCB production, $9.99 for 10 PCBS, There are also seeedstudios and PCBcart who are similar. I had a bad experience with seeedstudios though, so I use Itead. If you can get a few people working on the same thing, then the boards are very cheap. Itead boards are pretty good quality and quite quick, i use them for small production and prototype runs at work.


Wow that is mega cheap! Thanks for the information, I will have to look in to that service at that cost!



paul23 said:


> I'm redoing my dimmer board now after having the I2C idea yesterday, so my schematics will not really be any use to you at the minute. I will put them up when done if you want. I might open source my whole project when its done anyway.
> 
> The control is through a TRIAC but you can't use PWM. You need a zero-cross detector circuit which causes an interrupt on your microcontroller every time the AC waveform crosses the zero point. So 100Hz (2 times every full 50hZ mains cycle). Then you need a delay and then switch the TRIAC on. The delay basically cuts off the start of each waveform, the longer the delay, the more of the waveform is cut off, the dimmer the lights will be. The TRIAC will automatically switch itself off at the zero-cross point. All you have to do is switch it back on at the right time.
> 
> The zero cross detector is just a bridge rectifier to get the AC to DC and an opto-coupler connected to an interrupt on the microcontroller with a pullup resistor. When a zero-cross occurs, the opto-coupler will switch off causing an interrupt by setting that pin high. When the interrupt occurs, start counting the delay for how bright you want the lights and when done switch on the TRIAC (through another isolator). That´s it, a bit harder than LEDs but not a lot and only a few lines of code and a couple of components. If you want one of my spare boards then you can have one.


Not tried Triacs yet though thanks for the information, are they expensive?



paul23 said:


> The only feature difference I can notice between our projects is that I've included a door alarm, so if the door is open for a set amount of a time an alarm goes off. Stops me leaving the door open by mistake. Also I'm not using Arduino, but that doesn't really matter, it´s all more or less the same.


I see, so something like a time delayed buzzer/microswitch combination? I'm just trying to sort out the code to upload all my data to the internet to allow two way communication with a website, though pretty new ground for me!


----------



## paul23 (May 12, 2011)

spatte88 said:


> Not tried Triacs yet though thanks for the information, are they expensive?


Less than a pound, depending on how much power you want to switch



> I see, so something like a time delayed buzzer/microswitch combination?!


Sort of yes, but i´m using reed switches and magnets like a burglar alarm system. the only reason being I have a load of reed switches left over from something else. Microswitches would work just as well.


I have never done any of the internet stuff so I can´t help you there, but have a look on iTead´s site, they do loads of shields and expansion stuff. That might help you.


----------



## philipniceguy (Mar 31, 2008)

spatte88 said:


> Nice, what do you have the IR sensor setup for, camera or is it for temperature?


the producer of mine below answered for reading basking temps of my monitors like a temp gun does :2thumb:



Stivali said:


> It's running a Melexis IR temp sensor - for monitoring the basking temperature for monitor lizards (something we check often).
> 
> Unfortunately it's got too wide an angle of view - which means it needs to mounted closer to the basking spot than the bulb does, but I think I've found a suitable replacement that will be much more accurate from a greater distance with just 10 degree's fov.


----------



## philfish66 (Dec 2, 2013)

Hi there i showed my friend your video's and pictures now he said he can make me one *Arduino Automated Habitat Control * of those . what is the price to make one so i know what he will ask off me. thanks 

phil


----------



## spatte88 (Jun 29, 2009)

philfish66 said:


> Hi there i showed my friend your video's and pictures now he said he can make me one *Arduino Automated Habitat Control * of those . what is the price to make one so i know what he will ask off me. thanks
> 
> phil


All depends on what sensors you require really and features you'd like! I would say your looking between £30 (basic temperature sensor) to £100 (240V control, LEDs, display etc) dependant on setup, you obviously could go all singing and dancing which would be more! My setup cost about £120 off the top of my head, that controls heating, lighting, moisture, temperature, time and display functions. Just playing with adding Wifi capability to upload data to the internet for easier viewing/analysis.


----------



## philfish66 (Dec 2, 2013)

thanks my mate has started making me one and it will do all my needs with the top quality sensors. and I can keep an eye on it using my phone or pc he sid the hardest thing for him is writing the program which he said he can do. he was going to use a rass pie but he said he found the Ardino better thanks for your help. ill put a list here of the things it will do for me in every viv for my T,s. 

thermometer...... it has to be 27c day time and 20c at night

little laptop fan or computer fan..... to come on ever 3 hours. 5v maybe 

lights to dim....; after 12 hours on 12 hours off

oxygen machine...... to come on and off not sure of the volts it may be a portable one so could be 12v?

fogging machine....... to come on in the morning for half an hour.

misting machine......to come on in the morning one min then 10 hours later.

47w heat mat on the side of the tank...... and a 24w heat bulb in the top hood.

also the light for growing the plants on 12 hours off just be fore the dim light starts to dim.

hope all his makes sense, as it is a rough idea I gave my mate. and it an be up to ten vivs or more.

he did say he would do one for me but I think he would do more if I asked him. £50 with good gear, or £35 for cheap stuff.


----------



## DrChino (Aug 23, 2010)

Great work, was thinking of doing something like this with my Raspberry Pi


----------



## philfish66 (Dec 2, 2013)

I was going to use a Raspberry but I was told they are limited. 

phil


----------



## Jon89 (Apr 5, 2011)

This may be a stupid question but the Arduino is just the control board I take it? 

So you have a programmable Arduino, that you then link to a bespoke PCB of your own design with sensors etc attached? How exactly are the relays controlling the mains power of the parts such as the heater?

I have a very rudimentary understanding of electronics but was thinking about making something like this a project the very same day I found this thread. How hard would it be to learn/design/put together a set up like this? 

Thanks, Jon


----------



## paul23 (May 12, 2011)

You're sort of right. Arduino is a whole platform (hardware and software). Essentially the hardware is just a development board for an ATMEGA microcontroller. The software is a bootloader for the chip and a PC program which is a "dumbed down" version of a C compiler. You can use the software without using Arduino hardware or vice versa. It´s a much easier way to deal with microcontrollers as it removes some of the more complicated programming (like registers and timers, etc), but that also restricts you a bit with the designs.

Relays are easy. Mains through the switch side (so live on one side and load on the other) and the coil controlled through the Arduino or whatever microcontroller. The Arduino can't power the relay coils directly, so you need to connect through a transistor or something.

It depends on your knowledge and how quickly you can learn things. It´s not difficult to make a simple controller to do lights and heaters and stuff, even without the Arduino, but it depends on you really. I´ll help you if you need it, just let me know what you need to know.


----------



## Jon89 (Apr 5, 2011)

I can pick things up pretty quickly when I know what to look for. I think the main problem I'll have is understanding exactly what I need and how to put it together. 

Example: in the initial post in this thread there's a PCB connected to the Arduino. I know what the components I can see do but couldn't tell you specifically why they are there and how it all works. 

So whilst I have a rudimentary understanding of basic electronics I'm not sure where to begin with this. 

I think I'd need walking through it and as much as I appreciate the offer, I wouldn't be happy asking that of you. Some pointers as to where to start, and what I need to research would be good though.


----------



## paul23 (May 12, 2011)

OK, so the first thing you would need to do is decide what platform to use. You probably are better off with the Arduino as that can be quite easily ported to something else later on. So with that in mind, you need one of these Farnell UK
and software from here arduino
There´s quite a few tutorials on there as well. 

Start simple, blink an LED or something first whilst you figure everything out. Then I would split the project into blocks. So for example, timers, light controller, temperature controllers/thermometers. Get each block working, then move to the next one. You can buy ready made boards (known as shields) to do all your separate parts, so a relay board and a temperature measurement board, but i would advise against doing that, build your own and write your own code. That way if it breaks, you know how to fix it, plus it will cheaper and smaller. Seriously, if you get stuck just ask. It can be a bit confusing at first, but honestly it is not as hard as it seems at first. Good luck.


----------



## Jon89 (Apr 5, 2011)

Thanks, I'm going to do as you suggest and start small and basic. I've ordered the Arduino and a few basic components to get started.

I will ask for help, I just wouldn't ask anyone to hand hold me through the project.


----------



## DrChino (Aug 23, 2010)

philfish66 said:


> I was going to use a Raspberry but I was told they are limited.
> 
> phil


Yeah if you haven't got one I'd go for Arduino over the Pi. I already have a Pi anyway as I used to use it as a media centre, although my collection is too large for it to handle now so it's just gathering dust.

I'm thinking along the lines of using it to gather temperatures and then display the information on a webserver, although this is not planned any time soon as I am very new to Python so would need to get to grips better with it first! 

Perfect name for a programming language in this application!


----------



## spatte88 (Jun 29, 2009)

Jon89 said:


> Example: in the initial post in this thread there's a PCB connected to the Arduino. I know what the components I can see do but couldn't tell you specifically why they are there and how it all works.


The PCB attached is what is known as a shield, this basically routes all the I/O pins to the components.



Jon89 said:


> I think I'd need walking through it and as much as I appreciate the offer, I wouldn't be happy asking that of you. Some pointers as to where to start, and what I need to research would be good though.


If you go to Adafruit Learning System you can work your way through some great tutorials. Also most the components this company sell have "how to's" : victory:


----------



## Jon89 (Apr 5, 2011)

spatte88 said:


> If you go to Adafruit Learning System you can work your way through some great tutorials. Also most the components this company sell have "how to's" : victory:


Thanks, I've taken a look and I'm going to work through some of these once my components arrive. 

Are your sensors attached using ribbon cables, that you've cannibalised one end of? I know I don't need this just yet but I like to have ideas in the back of my mind and the ribbon cables are just nice and neat.


----------



## spatte88 (Jun 29, 2009)

Jon89 said:


> Are your sensors attached using ribbon cables, that you've cannibalised one end of? I know I don't need this just yet but I like to have ideas in the back of my mind and the ribbon cables are just nice and neat.


Yes, I've used ribbon cables to extend the length of all the sensors, this then makes it easy and neat to connect to my shield.


----------

