# Easy $20 Arduino Vivarium Controller



## 55105 (Jan 27, 2015)

Hi!

Now that work has slowed down a bit I'm attempting to integrate a wireless solution for RasPiViv using the Arduino Uno. I thought I'd share this quick prototype. 

I'm still waiting for a LCD display to ship but if you want a insanely easy, super cheap vivarium controller this would work nicely. Just no display yet!

All you need is a Arduino Uno (I used the $5 clone from Ebay) a DHT22 sensor, a 5 volt fan, a 2N222 Transistor & 2 10K Resistor.

I built this in less than an hour. You can modify it to control anything... Relays or build your own circuits. Currently it turns on/off a 5v blower fan to cool and/or lower humidity.



Sketch


```
#include "DHT.h"
     
    #define DHTPIN 2     // what pin we're connected to
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    #define fan 4
     
    int maxHum = 80;
    int maxTemp = 27;
     
    DHT dht(DHTPIN, DHTTYPE);
     
    void setup() {
      pinMode(fan, OUTPUT);
      Serial.begin(9600); 
      dht.begin();
    }
     
    void loop() {
      // Wait a few seconds between measurements.
      delay(2000);
     
      // Reading temperature or humidity takes about 250 milliseconds!
      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      float h = dht.readHumidity();
      // Read temperature as Celsius
      float t = dht.readTemperature();
      
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }
      
      if(h > maxHum || t > maxTemp) {
          digitalWrite(fan, HIGH);
      } else {
         digitalWrite(fan, LOW); 
      }
      
      Serial.print("Humidity: "); 
      Serial.print(h);
      Serial.print(" %\t");
      Serial.print("Temperature: "); 
      Serial.print(t);
      Serial.println(" *C ");
     
    }
```


----------



## terraruums.eu (Feb 17, 2013)

I have made an Ardiono temp/humidity logger. I will soon try to integrate temperature and humidity control, but its kind of hard, not used to this kind of code


----------



## Mr.Frog (Sep 30, 2015)

This is so cool. Can you control multiple vivs with one of these?


----------



## Alan (Jan 12, 2005)

terraruums.eu said:


> I have made an Ardiono temp/humidity logger. I will soon try to integrate temperature and humidity control, but its kind of hard, not used to this kind of code


What are you using for a cheap humidity sensor?


----------



## terraruums.eu (Feb 17, 2013)

Same as the Original Poster. They work great.


----------



## 55105 (Jan 27, 2015)

Mr.Frog said:


> This is so cool. Can you control multiple vivs with one of these?


This is my first Arduino project, so I'm not too knowledgeable of its capabilities.

A sensor and fan only use 2 i/o pins... The are 12 total

So for example you could have 6 DHT22 & 6 fans.


----------



## Mr.Frog (Sep 30, 2015)

port_plz said:


> This is my first Arduino project, so I'm not too knowledgeable of its capabilities.
> 
> A sensor and fan only use 2 i/o pins... The are 12 total
> 
> So for example you could have 6 DHT22 & 6 fans.


Great thanks.


----------



## terraruums.eu (Feb 17, 2013)

Every IO deducts pins. A display will cost you like 3 or 4... Ethernet shield another 4 - 5. I basically ended up with 3 digital and all the analog (which are digital as well). But each relay will cost a pin as well.


----------



## 55105 (Jan 27, 2015)

Finally got the LCD last night. I'm still amazed how easy Arduinos are to work with. Took less than an hour to rig the LCD up.

I've had the prototype running on my desk all week. Not a single issue what so ever.






```
#include "DHT.h"
    #include <LiquidCrystal.h>
 
 
    LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

    #define DHTPIN 2     // what pin we're connected to
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    #define fan 4
     
    int maxHum = 80;
    int maxTemp = 27;
     
    DHT dht(DHTPIN, DHTTYPE);
     
    void setup() {
      pinMode(fan, OUTPUT);
      Serial.begin(9600); 
      dht.begin();
      // set up the LCD's number of columns and rows: 
      lcd.begin(16, 2);
    
    }
     
    void loop() {
      // Wait a few seconds between measurements.
      delay(2000);
     
      // Reading temperature or humidity takes about 250 milliseconds!
      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      float h = dht.readHumidity();
      // Read temperature as Celsius
      float t = dht.readTemperature();
      
      // Check if any reads failed and exit early (to try again).
      if (isnan(h) || isnan(t)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }
      
      if(h > maxHum || t > maxTemp) {
          digitalWrite(fan, HIGH);
      } else {
         digitalWrite(fan, LOW); 
      }
      
      Serial.print("Humidity:  "); 
      Serial.print(h);
      Serial.print(" %");
      Serial.print("Temperature: "); 
      Serial.print(t);
      Serial.println(" *C ");
      lcd.setCursor(0, 0);
      lcd.print("HUM : ");
      lcd.print(h);
      lcd.print(" %");
      lcd.setCursor(0, 1);
      lcd.print("TEMP: ");
      lcd.print(t);
      lcd.print(" *C ");
    }
```


----------



## terraruums.eu (Feb 17, 2013)

A quick note:
Do not delay the CPU like that. During that 2000 ms delay, it cant do anything.
Make a loop with a timer like so:
How to write Timings and Delays in Arduino
This will not stop the cpu from doing other tasks for example:
Send data via Ethernet to an Api while still being able to control a relay and measuring from the sensor.

I managed to make a working temperature and humidity logger that writes data to my website with accounts, authentication and everything. It is my Thesis for the University. When i`m ready, I may show it. (though without the api server it is not that usable).
The benefit is that you can check on the vivariums from any where in the world, without the need to connect to the home network.

Great little gadgets those arduinos indeed.


----------



## 55105 (Jan 27, 2015)

Thanks for the tips! Didn’t you message me about your project? I was wondering how things where going.

I don’t plan on much more for this... Hoping to use some 433 RF modules to transmit data to the raspberry pi.

Just checked out your website translated

Very cool stuff!


----------



## terraruums.eu (Feb 17, 2013)

Yep. 
Its embarrassing that I`m a really good web developer, and yet my website looks like that  No time to redo it ... Any way the project is going great, currently trying to figure out why my latest code freezes after 2 requests


----------

