So I'm back after being long gone. Sick of internships hehehe
Anyways a friend just asked me to build him a greenhouse.
Now it seemed cool to automate it with Arduino.
So for some requirements:
*Measure temperature, humidity and soil moisture
*Control lights, fan and watersupply
*Simple overview of current conditions
*Graph conditions in Excel
Measuring temperature and humidity is simple with an SHT71 sensor
Controlling with a few relays
I'll be pulling log data over the serial connection and using Gobetwino to store them in as a .csv file
I had most schematics in my head but I drew them up for you guys.
Here are the two sensors, and yes the nail trick I "borrowed" from the Garduino instructable.
Here is the control panel which shows power, status of temperature, humidity and soil moistness. Whether lights, fan or pump are on and mains switches for lights, fan and pump.
And the relay board, and yes I have forgotten about the diodes in this drawing.
I also came up with some code
#include <Sensirion.h>
#include <Time.h>
//Temperature and Humidity sensor
const uint8_t dataPin = 2;
const uint8_t clockPin = 3;
float temperature;
float humidity;
float dewpoint;
Sensirion tempSensor = Sensirion(dataPin, clockPin);
//Temperature and Humidity interval time
long previousMillis = 0;
long interval = 300000;
//Soil moisture
int moistureSensor = 0;
int moisture_val;
//Serial stuff
char buffer[5];
//Relay output pins
const int lightPin = 4;
const int waterPin = 5;
const int fanPin = 6;
//Status LED pins
const int tempgoodPin = 7;
const int tempbadPin = 8;
const int soilgoodPin = 9;
const int soilbadPin = 10;
const int humgoodPin = 11;
const int humbadPin = 12;
////Lightstatus
int lightstatus = 0;
int lastlightstatus = 0;
//Fanstatus
int fanstatus = 0;
int lastfanstatus = 0;
//Watering
int watertime = 1000; //In milliseconds
int waterstatus = 0;
int lastwaterstatus = 0;
void setup()
{
Serial.begin(9600);
setTime(20,7,0,17,5,2011);
pinMode(lightPin, OUTPUT);
pinMode(waterPin, OUTPUT);
pinMode(fanPin, OUTPUT);
pinMode(tempgoodPin, OUTPUT);
pinMode(tempbadPin, OUTPUT);
pinMode(soilgoodPin, OUTPUT);
pinMode(soilbadPin, OUTPUT);
pinMode(humgoodPin, OUTPUT);
pinMode(humbadPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
time_t t = now();
//Check Temperature.... and report every 5 minutes
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
tempSensor.measure(&temperature, &humidity, &dewpoint);
moisture_val = analogRead(moistureSensor);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Dewpoint: ");
Serial.print(dewpoint);
Serial.print(" C, Soil Moisture: ");
Serial.println(moisture_val);
Serial.print("#S|TEMPLOG|[");
Serial.print(itoa((temperature), buffer, 10));
Serial.print(";");
Serial.print(itoa((humidity), buffer, 10));
Serial.print(";");
Serial.print(itoa((dewpoint), buffer, 10));
Serial.print(";");
Serial.print(itoa((moisture_val), buffer, 10));
Serial.println("]#");
}
/////Light trigger
if(0 <= hour(t)) {
if(18 > hour(t)) {
lightstatus = 1;
}
};
if(18 <= hour(t)) {
if(24 >= second(t)) {
lightstatus = 0;
}
};
//Light compare, set status and report
if(lightstatus != lastlightstatus) {
if(lightstatus == 1) {
Serial.println("#S|ACTIONLOG|[Light On]#");
};
if(lightstatus == 0) {
Serial.println("#S|ACTIONLOG|[Light Off]#");
};
digitalWrite(lightPin, lightstatus);
lastlightstatus = lightstatus;
}
/////Fan trigger
if(temperature <= 25) {
fanstatus = 0;
}
if(humidity <= 60) {
fanstatus = 0;
}
if(temperature > 28) {
fanstatus = 1;
}
if(humidity > 80) {
fanstatus = 1;
}
//Fan compare, set status and report
if(fanstatus != lastfanstatus) {
if(fanstatus == 1) {
Serial.println("#S|ACTIONLOG|[Fan On]#");
}
if(fanstatus == 0) {
Serial.println("#S|ACTIONLOG|[Fan Off]#");
}
digitalWrite(fanPin, fanstatus);
lastfanstatus = fanstatus;
}
/////Water trigger
if(moisture_val > 1000) {
waterstatus = 0;
}
if(moisture_val < 850) {
waterstatus = 1;
}
//Fan compare, set status and report
if(waterstatus != lastwaterstatus) {
if(waterstatus == 1) {
Serial.println("#S|ACTIONLOG|[Pump On]#");
digitalWrite(waterPin, waterstatus);
delay(watertime);
waterstatus = 0;
Serial.println("#S|ACTIONLOG|[Pump Off]#");
digitalWrite(waterPin, waterstatus);
lastwaterstatus = waterstatus;
}
}
/////Status LEDs
//Temperature
if(temperature < 22) {
digitalWrite (tempgoodPin, LOW);
digitalWrite (tempbadPin, HIGH);
}
else if(temperature > 28) {
digitalWrite (tempgoodPin, LOW);
digitalWrite (tempbadPin, HIGH);
}
else {
digitalWrite (tempbadPin, LOW);
digitalWrite (tempgoodPin, HIGH);
}
//Humidity
if(humidity < 60) {
digitalWrite (humgoodPin, LOW);
digitalWrite (humbadPin, HIGH);
}
else if(humidity > 80) {
digitalWrite (humgoodPin, LOW);
digitalWrite (humbadPin, HIGH);
}
else {
digitalWrite (humbadPin, LOW);
digitalWrite (humgoodPin, HIGH);
}
//Soil
if(moisture_val < 850) {
digitalWrite (soilgoodPin, LOW);
digitalWrite (soilbadPin, HIGH);
}
else if(moisture_val > 1000) {
digitalWrite (soilgoodPin, LOW);
digitalWrite (soilbadPin, HIGH);
}
else {
digitalWrite (soilbadPin, LOW);
digitalWrite (soilgoodPin, HIGH);
}
}
I'm going to order all the parts this week so I'll be keeping you guys posted.
And ofcourse all suggestions are welcome!!