Vous êtes sur la page 1sur 13

Arduino Garden Bed Watering System

Hardware:
For the hardware, I mostly acquired the parts via eBay. I tried to go as
cheap as possible to test the watering system. Although the parts are made
from china and took up to 2wks to arrive, they have lasted till this day. The
only expensive part was the 12v stainless steel ball valve.

Item Quantity Link Price


Arduino Uno 1 http://www.ebay.com/itm/172176663772?_tr $4.43
(Chinese Clone) ksid=p2057872.m2749.l2649&ssPageName
=STRK%3AMEBIDX%3AIT
I2C 20x4 LCD 1 http://www.ebay.com/itm/Yellow-Green- $4.10
Serial-IIC-I2C-TWI-2004-LCD-20X4-
Character-LCD-Module-For-Arduino-
/201013825839?hash=item2ecd5b912f:g:B
HwAAOSwvg9XcPwD
I2C RTC DS3231 1 http://www.ebay.com/itm/Arduino-DS3231- $1.14
ZS042-AT24C32-IIC-Module-Precision-
RTC-Real-time-Clock-Memory-
/401093092939?hash=item5d6302e64b:g:Iu
UAAOSw2zlXhy59
5v 1Ch Relay 1 http://www.ebay.com/itm/1-Channel-5V- $0.99
Relay-Module-Shield-for-Arduino-Uno-
Meage-2560-1280-ARM-PIC-AVR-DSP-
/222453386692?hash=item33cb414dc4:g:T
70AAOSwHMJYCDLA
LM-393 Soil Moisture 1 http://www.ebay.com/itm/Soil-Moisture- $2.30
Sensor Hygrometer-Sensor-Detection-Module-PCB-
For-Arduino-LM393-Chip-
/322383605543?hash=item4b0f8f6f27:g:4ns
AAOSwARZXjkq7
LM-393 Water 1 http://www.ebay.com/itm/Water-Rain-Snow- $1.99
Sensor Detector-PCB-Module-Sensor-For-Arduino-
/172123787447?hash=item28136090b7:g:0
FIAAOSwjDZYiXHH
12vDC ¾” Stainless 1 https://www.amazon.com/BACOENG- $28.99
Steel NPT Ball Valve Stainless-Motorized-Control-
(3-wire) Electric/dp/B0119ZI38U/ref=sr_1_1?ie=UTF
8&qid=1490648968&sr=8-
1&keywords=12v+3+4+valve+switch

Total cost of parts: $43.94


Arduino Garden Bed Watering System
Below are the images of the parts to cross reference.

Arduino Uno

I2C 20x4 LCD

I2C RTC DS3231


Arduino Garden Bed Watering System

5v 1Ch Relay

LM-393 Soil Moisture Sensor

LM-393 Water Sensor

12vDC ¾” Stainless Steel


NPT Ball Valve (3-wire)
Arduino Garden Bed Watering System

PINOUT CONNECTIONS

20x4 LCD Arduino


GND GND
VCC +5v
SDA A4
SCL A5

DS3231 RTC Arduino


GND GND
VCC +5v
SDA A4
SCL A5

LM-393 – Soil Sensor Arduino


GND GND
VCC +5v
D0 – Digital NOT USED
A0 - Analog A1

LM-393 – Water Level Arduino


GND GND
VCC +5v
D0 – Digital NOT USED
A0 - Analog A0

5v Relay Arduino
GND GND
+5v +5v
IN PIN
OUTPUT PIN1 OPEN + on Valve (red wire)
OUTPUT PIN2 TO Battery +12v
OUTPUT PIN3 CLOSE + on Valve (blue wire)

12v Ball Valve FROM RELAY


RED Wire OPEN + Pin1
BLUE Wire CLOSE + Pin3
YELLOW Wire TO 12v Battery GND
Arduino Garden Bed Watering System
Arduino CODE Duel Relays

// libraries definition
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>

// frequency musical notes


#define NOTE_C6 1047
#define NOTE_C3 131
#define NOTE_G3 196

// pins definition
int levelSensorPin = 0; //Analog pin0
int moistureSensorPin1 = 1; //Analog pin1
int moistureSensorPin2 = 2; //Analog pin2
int audioPin = 2; //Digital Pin2
int soggyLEDPin = 3; //Digital Pin3
int moistsoilLEDPin = 4; //Digital Pin4
int drysoilLEDPin = 5; //Digital Pin5
int pumpLEDPin = 6; //Digital Pin6
int pumpPin1 = 7; //Digital Pin7
int pumpPin2 = 8; //Digital Pin8

//int soggyLEDPin = 9; //Digital Pin9


//int moistsoilLEDPin = 10; //Digital Pin10
//int drysoilLEDPin = 11; //Digital Pin11
//int pumpLEDPin = 12; //Digital Pin12

// variables
int levelSensorValue; // stores the level sensor values
int moistureSensorValue1; // moisture sensor value bed 1
int moistureSensorValue2; // moisture sensor value bed 2

int j = 0;

// system messages
const char *string_table[] =
{
" Version 1.0 ", //Table 0
Arduino Garden Bed Watering System
" Tank LOW level ", //Table 1
" Dry soil ", //Table 2
" Moist soil ", //Table 3
" Soggy soil ", //Table 4
" Water Valve1 Open ", //Table 5
" Water Valve2 Open ", //Table 6
" TerraNova Farms ", //Table 7
" Watering System ", //Table 8
" Please wait! " //Table 9
};

// objects definition
RTC_DS1307 RTC;
// LiquidCrystal_I2C lcd(0x27,20,4);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup(){
// serial initialization
Serial.begin(9600);
// LCD initialization
lcd.begin(20,4);
// Wire initialization
Wire.begin();
// RTC initialization
RTC.begin();
if (!RTC.isrunning()){
// date and time adjust as the PC computer date and time
RTC.adjust(DateTime(__DATE__, __TIME__));
}

// Arduino pins initalization


pinMode(audioPin,OUTPUT);
pinMode(soggyLEDPin,OUTPUT);
pinMode(moistsoilLEDPin,OUTPUT);
pinMode(drysoilLEDPin,OUTPUT);
pinMode(pumpLEDPin,OUTPUT);
pinMode(pumpPin1,OUTPUT);
pinMode(pumpPin2,OUTPUT);

// LCD initial messages


Arduino Garden Bed Watering System
lcd.clear();
lcd.setCursor(0,0);
lcd.print(string_table[7]);
lcd.setCursor(0,1);
lcd.print(string_table[8]);
lcd.setCursor(0,3);
lcd.print(string_table[0]);

// initialization delay
delay(4000);

//Turn OFF any power to the Relay channels


digitalWrite(pumpPin1, HIGH);
digitalWrite(pumpPin2, HIGH);
}

void loop(){

// RTC parameters definition


DateTime myRTC = RTC.now();
int H = myRTC.hour();
int M = myRTC.minute();
int S = myRTC.second();

// reads the sensors


levelSensorValue = analogRead(levelSensorPin);
moistureSensorValue1 = analogRead(moistureSensorPin1);
moistureSensorValue2 = analogRead(moistureSensorPin2);

//Output to Serial Testing


Serial.println("Water_level");
Serial.println(levelSensorValue);
Serial.println( );

//Output to Serial Testing


Serial.println("Moisture Value1");
Serial.println(moistureSensorValue1);
Serial.println( );
Serial.println("Moisture Value2");
Arduino Garden Bed Watering System
Serial.println(moistureSensorValue2);
Serial.println( );

// if low water level: plays the low level alarm


if(levelSensorValue > 600){
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[1]);

// plays the alarm sound


for(int i=0;i<2;i++){
tone(audioPin, NOTE_G3, 200);
delay(200);
tone(audioPin, NOTE_C3, 200);
delay(200);
noTone(audioPin);
}
}

// check the moisture range for Sensor1


if(moistureSensorValue1 >= 700){
// in case of dry soil:
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[2]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,HIGH);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,LOW);
// plays the alarm sound
tone(audioPin, NOTE_C6, 100);
delay(250);
noTone(audioPin);
}
if((moistureSensorValue1 < 700) && (moistureSensorValue1 >= 300)){
// in case of moist soil:
Arduino Garden Bed Watering System
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[3]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,HIGH);
digitalWrite(soggyLEDPin,LOW);
delay(250);
}
if(moistureSensorValue1 < 300){
// in case of soggy soil:
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[4]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,HIGH);
delay(100);
}

// check the moisture range for Sensor2


if(moistureSensorValue2 >= 700){
// in case of dry soil:
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[2]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,HIGH);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,LOW);
// plays the alarm sound
tone(audioPin, NOTE_C6, 100);
delay(1000);
Arduino Garden Bed Watering System
noTone(audioPin);
}
if((moistureSensorValue2 < 700) && (moistureSensorValue2 >= 300)){
// in case of moist soil:
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[3]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,HIGH);
digitalWrite(soggyLEDPin,LOW);
delay(1000);
}
if(moistureSensorValue2 < 300){
// in case of soggy soil:
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,3);
lcd.print(string_table[4]);
// lights up the correct LED
digitalWrite(drysoilLEDPin,LOW);
digitalWrite(moistsoilLEDPin,LOW);
digitalWrite(soggyLEDPin,HIGH);
delay(1000);
}

// if the soil is dry and if it is the right time: turn on the pump until moisture
value is >700
if((H == 16) && (M == 30) && (S == 00)){
while(moistureSensorValue1 >= 700){
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,1);
lcd.print(string_table[9]);
lcd.setCursor(0,3);
lcd.print(string_table[5]);
Arduino Garden Bed Watering System
// turn the pump on
digitalWrite(pumpPin1,HIGH);
digitalWrite(pumpLEDPin,HIGH);
delay(10000);
// if the soil is not moist so far
// reads the moisture sensor once more
moistureSensorValue1 = analogRead(moistureSensorPin1);
}
// turn the pump off
digitalWrite(pumpPin1,LOW);
digitalWrite(pumpLEDPin,LOW);
}

if((H == 16) && (M == 40) && (S == 00)){


while(moistureSensorValue2 >= 700){
// system messages
lcd.clear();
RightHour();
lcd.setCursor(0,1);
lcd.print(string_table[9]);
lcd.setCursor(0,3);
lcd.print(string_table[5]);
// turn the pump on
digitalWrite(pumpPin1,HIGH);
digitalWrite(pumpLEDPin,HIGH);
delay(10000);
// if the soil is not moist so far
// reads the moisture sensor once more
moistureSensorValue2 = analogRead(moistureSensorPin2);
}
// turn the pump off
digitalWrite(pumpPin1,LOW);
digitalWrite(pumpLEDPin,LOW);
}

} // End Void Loop


Arduino Garden Bed Watering System
// Real Time Clock Function
void RightHour()
{
DateTime Now = RTC.now();
String clock_date = " Date: ";
String clock_hour = " Time: ";

int _day = Now.day();


int _month = Now.month();
int _year = Now.year();

clock_date += fixZero(_month);
clock_date += "/";
clock_date += fixZero(_day);
clock_date += "/";
clock_date += _year;

int _hour = Now.hour();


int _minute = Now.minute();
int _second = Now.second();

clock_hour += fixZero(_hour);
clock_hour += ":";
clock_hour += fixZero(_minute);
clock_hour += ":";
clock_hour += fixZero(_second);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(clock_date);
lcd.setCursor(0, 1);
lcd.print(clock_hour);

delay(1000);
}

String fixZero(int i)
{
String ret;
Arduino Garden Bed Watering System
if (i < 10) ret += "0";
ret += i;
return ret;
}

Vous aimerez peut-être aussi