Pages: [1]   Go Down
Author Topic: Smart Garden with Arduino _ Pump Update (6/13/2014)  (Read 458 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As its Spring here, I'm starting to get into the gardening spirit. I really want to get into bonsai tree gardening, but try as I might every year, I end up killing my plants because of over or under watering them. So, this year I'm combining my love of electronics with my urge to bonsai. I am going to create an Arduino-controlled, bonsai monitoring system. I am working on an nRF24L01 home network that I will incorporate the garden into... eventually.

My initial plan is to use a Soil Hygrometer Sensor and Digital Temperature Sensor to monitor and keep track of the bonsai trees' condition. This will hopefully help me know when to water them. My eventual goal is to have the sensors in a meshed network and also automate watering them, but that will come (much?) later.

I am currently using Arduino Nanos as they are quite small and cheap while still having all the features of the Uno. And hopefully soon I will switch to the DigiSpark Pro once they are shipped out.

I'm still working on getting the nRF node system working, but until then, I have made a standalone module that takes readings and displays them to an OLED display. Code below and images in 2nd post. I will update as I progress.

UPDATE: I finally got my 12V peristaltic pump working correctly without melting my transistor... Its long ,painful story to me, that ended in reversing the direction of a diode smiley-roll-blue. My problem now is that I have acquired another pot with three very young trees in it and splitting the output to now 3 pots is beginning to be too much for this little pump. It should work for the short term, but now I'm looking at possibly getting a valve/servo set up. But again, I won't be able to get to that for some time.

Code:
/*
  Arduino Garden Monitor
 
Test code
____________________________________________________________
Soil Hygrometer
  Attach  VCC to 5V,
          GND to GND,
          A0 to analog input on Arduino.
  Reading of 1023 means that the soil is completely DRY.
  Lower numbers indicate MORE moisture.
_____________________________________________________________
DHT11 Temperature Sensor
  Good reference source: http://learn.adafruit.com/dht/overview
  Pins
    VCC to 3V-5V power
    Data out to 2
    3rd Pin not connected
    Ground to GND
  Use 4.7K or 10K resistor as a pullup from the data pin to VCC
______________________________________________________________
SSD1306 0.96" 128x64 OLED Display (Not from Adafruit)
 - SPI variant (must be SSD1306 Driver to work) http://www.ebay.com/sch/0.96%22+SPI+Serial+128X64
  Pins
    GND to GND
    VCC to 3V-5V power
    SCL to 10
    SDA to 9
    RST to 13
    D/C to 11
   
    Arduino Pin 12 is not connected to anything, but in the adafruit version it is connected to CS
_____________________________________________________________

By Aerospacesmith, May 2014

*/

#include <DHT.h>  //DHT Sensor Library from Adafruit https://github.com/adafruit/DHT-sensor-library

 //OLED
#include <Adafruit_SSD1306.h>  //SSD1306 oled driver library from Adafruit https://github.com/adafruit/Adafruit_SSD1306
#include <Adafruit_GFX.h>  //GFX graphics core library from Adafruit https://github.com/adafruit/Adafruit-GFX-Library
#include <SPI.h>
#include <Wire.h>


// If using software SPI (the default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define charWidth 6  //TextSize 1 pixel size  -for spacing math
#define charHight 8


#define DHTPIN 2     // what pin DHT is connected to
#define DHTTYPE DHT11   // DHT 11 sensor
DHT dht(DHTPIN, DHTTYPE);


int hygroPin = A0;    // Hygrometer Pin
int soilValue = 1023;  // variable to store the value coming from the sensor

int motorPin = 4;   //Digital Pin to Base pin on transistor

int waterMode = 2;  //0=Disabled    1=Startup Watering     2=Sensor Activated


void setup() {
 
  dht.begin();
 
  pinMode(motorPin, OUTPUT);   //to Base pin on transistor
 
    // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);  //must be included
  // init done
 
  display.clearDisplay();   // clears the screen and buffer --else the adafruit logo will appear
  display.display();
 
  if(waterMode == 1){
    digitalWrite(motorPin,HIGH);
    delay(10000);   //configure time to water
    digitalWrite(motorPin,LOW);
  }
 
}

void loop() {
 
  // read the value from the sensors:
 
  soilValue = map(analogRead(hygroPin),1023,0,0,100);    //maps the 1024-0 analog range to 0-100 range for percent
 
  int ambientHumid = dht.readHumidity();
  int ambientTemp = ((9*dht.readTemperature())/5)+32;  // converts to Fahrenheit ((9*C)/5)+32
 
 
  // Draw/refresh the display
 
  display.fillRect(0, 17, display.width(), 64, BLACK); //Clears the lower portion of display
 
  display.setCursor(0,17);
  display.setTextSize(1);
  display.setTextColor(WHITE);
 
  display.print("Soil Humidity = " );
  display.print(soilValue);
  display.write(37);  // % symbol
  display.println();

  display.print("Room Humidity = " );
  display.print(ambientHumid);
  display.write(37);  // % symbol
  display.println();
 
  display.print("Temperature   = " );
  display.print(ambientTemp);
  display.write(247); // degree symbol
  display.println();

  display.display(); //draw evreything buffered to the display
   
 
  if(soilValue < 60){ //if soil is 40% dry        ------ Needs calibrated to determine the correct warning level
    humidWarning(); //call warning function if soil wetness is too low
   
    if(waterMode == 2){
      digitalWrite(motorPin,HIGH);
      delay(10000);   //configure time to water
      digitalWrite(motorPin,LOW);
    }   
  }
  else{display.fillRect(0, 0, display.width(), 16, BLACK); //Clear the warning area if there isn't a warning anymore
  }

  delay(2000);  //wait for next reading
}


void humidWarning(){
  display.fillRect(0, 0, display.width(), 16, WHITE);
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(((display.width()-(10*charWidth*1))/2)-1 , 1);  //centers text
  display.println("Warning!!!");
  display.setCursor(((display.width()-(12*charWidth*1))/2)+2 , 8);  //centers text
  display.print("Water Needed");
  display.println();
  display.display(); //draw evreything buffered to the display
}



More Images at http://imgur.com/a/z3GU4

Any thoughts or ideas? I value input as I'm mainly just experimenting right now.
« Last Edit: June 13, 2014, 02:57:16 am by Aerospacesmith » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[Reserved for future content]

Images so far:
http://imgur.com/a/z3GU4
Logged

Pages: [1]   Go Up
Jump to: