Académique Documents
Professionnel Documents
Culture Documents
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.
Arduino Uno
5v 1Ch Relay
PINOUT CONNECTIONS
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)
// libraries definition
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
// 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
// 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__));
}
// initialization delay
delay(4000);
void loop(){
// 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);
}
clock_date += fixZero(_month);
clock_date += "/";
clock_date += fixZero(_day);
clock_date += "/";
clock_date += _year;
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;
}