Foundation For A New Tomorrow
Published © CC BY-NC-SA

Automatic Climate-Controlled Organic Garden

Imagine growing any kind of food or crop at home or commercially, year round, in a self-contained system. We could feed the hungry!

IntermediateShowcase (no instructions)24 hours1,609
Automatic Climate-Controlled Organic Garden

Things used in this project

Hardware components

Grove starter kit plus for Intel Edison
Seeed Studio Grove starter kit plus for Intel Edison
×1

Hand tools and fabrication machines

Electric Drill (Generic)
Circular Saw (Generic)

Story

Read more

Code

Automatic Climate-Controlled Garden

Arduino
/************************************************************
 * Automatic Climate-Controlled Organic Garden Control Software
 * Foundation For A New Tomorrow
 * Code By: J. Amin and A. Scott
 * 
 * Self-contained, climate-controlled, automated garden
 * that maintains and regulates lighting, watering, and 
 * temperature via relays, based on constant feedback from 
 * moisture, light, water,and temperature sensors.
 * 
 * 
 ************************************************************/

/**************************
   Sensor Initializations
***************************/
//#include<Time.h>

//LCD Initialization
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
#include <Digital_Light_TSL2561.h> //Digital Light Sensor
#include <math.h>

//All Sensor Init
#define TEMP A3
#define MOISTURE A0
#define UV A1
#define DRY_REED 2
//#define LIGHT 6
#define WATER 3
#define RELAY 5
#define RELAY2 8


void pins(){
  pinMode(TEMP, INPUT);
  pinMode(MOISTURE, INPUT);
  //pinMode(UV, INPUT);
  pinMode(DRY_REED, OUTPUT);
  //pinMode(LIGHT, INPUT);
  pinMode(WATER, INPUT);
  pinMode(RELAY, OUTPUT);
  pinMode(RELAY2, OUTPUT);
}

//Global values

bool lights_on=true;\
unsigned long elapsed_time=43200000;
int m=1;
unsigned long previous=0;

int a;
float temperature;
int B=3975;                  //B value of the thermistor
float resistance;

void setup() {
 // Initialize all pins
 pins();
 TSL2561.init();
 
  //Initialize LCD
 //LCD_setup();
// set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    // initialize the serial communications:
    Serial.begin(9600);
    //time1=millis();
}

void loop() {
 lights();    //RELAY
 water_check();
 moisture();  //DRY_REED RELAY -- water pump
 heat();     //RELAY2  
 disp();
 
 }

/*******************************************
//Functions for All Sensors
********************************************/
//Check if water tank is empty

void lights(){
   //Auto-toggle the lights for 12h intervals
   unsigned long current=millis();

  if(lights_on=true)
  {
   digitalWrite(RELAY, HIGH); //lights on 
  }

  else{digitalWrite(RELAY,LOW);} //lights off
 
 if ((unsigned long)(current - previous) >= elapsed_time) {
  
    if(lights_on=true)
    {
      lights_on=false;
      //digitalWrite(RELAY, LOW); //turn off lights

      //Update timer
      previous=current;
    }

    else if(lights_on=false)
    {
      lights_on=true;
      //digitalWrite(RELAY,HIGH);
      
      //Update timer
      previous=current;
    }
  }
}

void water_check(){
 
  //Check water tank
  if(digitalRead(WATER)==1)
  {
    lcd.setCursor(0,0);
    lcd.print("Water: Empty!");
    lcd.setRGB(100,0,0);
    delay(2000);
    //lcd.clear();
    //lcd.setRGB(50,50,50);  
  }
}

void disp(){

 lcd.clear();
 lcd.setRGB(50,50,50);
 lcd.setCursor(0,0);
 lcd.print("Temp: ");
 a=analogRead(TEMP);
 resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
 temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet&nbsp;;
 lcd.print(temperature);
 lcd.print( "C");
 delay(1000);
 
 //lcd.print(analogRead(Temp)); 
 lcd.setCursor(0,1);
 lcd.print("Lights:");
 if(lights_on==true){lcd.print(" On");}
 else if(lights_on==false){lcd.print(" Off");}
 delay(2000);
 lcd.clear();
}

  void light_diag(){
  //Check Light Sensor (Box#1 lights)
  if((TSL2561.readVisibleLux()==0) && (lights_on=true))
  {
    lcd.setCursor(0,1);
    lcd.setRGB(200,0,0);
    lcd.print("Light Bulb: Out");  
    delay(2000);
    lcd.clear();
    lcd.setRGB(50,50,50);  
  }

}

void moisture(){
  int humid;
  humid=analogRead(A0);
  if(humid<40){
    digitalWrite(DRY_REED,HIGH);
  }

  else
    {digitalWrite(DRY_REED, LOW);}
}

void heat(){

  if(temperature<25.00)
  {
    digitalWrite(RELAY2,HIGH);
  }

  else{digitalWrite(RELAY2,LOW);}
}

Credits

Foundation For A New Tomorrow

Foundation For A New Tomorrow

1 project • 2 followers

Comments