├── RTClib.rar ├── Wire.rar ├── LiquidCrystal_I2C.rar ├── WATERING-SYSTEM-INTRODUCTION.pdf └── Arduino_Watering_System.ino /RTClib.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arduinobymyself/ArduinoWateringSystem/HEAD/RTClib.rar -------------------------------------------------------------------------------- /Wire.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arduinobymyself/ArduinoWateringSystem/HEAD/Wire.rar -------------------------------------------------------------------------------- /LiquidCrystal_I2C.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arduinobymyself/ArduinoWateringSystem/HEAD/LiquidCrystal_I2C.rar -------------------------------------------------------------------------------- /WATERING-SYSTEM-INTRODUCTION.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arduinobymyself/ArduinoWateringSystem/HEAD/WATERING-SYSTEM-INTRODUCTION.pdf -------------------------------------------------------------------------------- /Arduino_Watering_System.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ##################################################################################### 3 | # File: Arduino_Watering_sustem.ino 4 | # Processor: Arduino UNO, MEGA ou Teensy++ 2.0 5 | # Language: Wiring / C /Processing /Fritzing / Arduino IDE 6 | # 7 | # Objectives: Watering System - Irrigation 8 | # 9 | # Behavior: When the soil is dry, 10 | # 11 | # 12 | # 13 | # Author: Marcelo Moraes 14 | # Date: 12/10/12 15 | # place: Brazil, Sorocaba City 16 | # 17 | ##################################################################################### 18 | 19 | This project contains public domain code. 20 | The modification is allowed without notice. 21 | 22 | */ 23 | 24 | // libraries definition 25 | #include 26 | #include 27 | #include "RTClib.h" 28 | 29 | 30 | 31 | // frequency musical notes 32 | #define NOTE_C6 1047 33 | #define NOTE_C3 131 34 | #define NOTE_G3 196 35 | 36 | // pins definition 37 | int levelSensorPin = 0; 38 | int moistureSensorPin = 1; 39 | int audioPin = 2; 40 | int soggyLEDPin = 3; 41 | int moistsoilLEDPin = 4; 42 | int drysoilLEDPin = 5; 43 | int pumpLEDPin = 6; 44 | int pumpPin = 7; 45 | 46 | // variables 47 | int levelSensorValue; // stores the level sensor values 48 | int moistureSensorValue; // stores the moisture sensor values 49 | int j = 0; 50 | 51 | // system messages 52 | const char *string_table[] = 53 | { 54 | " Welcome! =)", 55 | " Tank LOW level", 56 | " Dry soil", 57 | " Moist soil", 58 | " Soggy soil", 59 | "The water pump is on", 60 | " ArduinoByMyself", 61 | " Watering System", 62 | " Please wait!" 63 | }; 64 | 65 | // objects definition 66 | RTC_DS1307 RTC; 67 | LiquidCrystal_I2C lcd(0x27,20,4); 68 | 69 | 70 | void setup(){ 71 | // serial initialization 72 | Serial.begin(9600); 73 | 74 | // LCD initialization 75 | lcd.init(); 76 | lcd.backlight(); // with Backlight 77 | lcd.clear(); // clearscreen 78 | 79 | // Wire initialization 80 | Wire.begin(); 81 | 82 | // RTC initialization 83 | RTC.begin(); 84 | if (!RTC.isrunning()){ 85 | // date and time adjust as the PC computer date and time 86 | RTC.adjust(DateTime(__DATE__, __TIME__)); 87 | } 88 | 89 | // Arduino pins initalization 90 | pinMode(audioPin, OUTPUT); 91 | pinMode(soggyLEDPin, OUTPUT); 92 | pinMode(moistsoilLEDPin,OUTPUT); 93 | pinMode(drysoilLEDPin,OUTPUT); 94 | pinMode(pumpLEDPin,OUTPUT); 95 | pinMode(pumpPin,OUTPUT); 96 | 97 | // LCD initial messages 98 | lcd.clear(); 99 | lcd.setCursor(0,0); 100 | lcd.print(string_table[6]); 101 | lcd.setCursor(0,1); 102 | lcd.print(string_table[7]); 103 | lcd.setCursor(0,3); 104 | lcd.print(string_table[0]); 105 | // initialization delay 106 | delay(5000); 107 | } 108 | 109 | 110 | void loop(){ 111 | 112 | 113 | // RTC parameters definition 114 | DateTime myRTC = RTC.now(); 115 | int H = myRTC.hour(); 116 | int M = myRTC.minute(); 117 | int S = myRTC.second(); 118 | 119 | // call Clock Function 120 | //RightHour(); 121 | 122 | // reads the sensors 123 | levelSensorValue = analogRead(levelSensorPin); 124 | moistureSensorValue = analogRead(moistureSensorPin); 125 | 126 | // if low water level: plays the low level alarm 127 | if(levelSensorValue > 600){ 128 | // system messages 129 | lcd.clear(); 130 | RightHour(); 131 | lcd.setCursor(0,3); 132 | lcd.print(string_table[1]); 133 | // plays the alarm sound 134 | for(int i=0;i<2;i++){ 135 | tone(audioPin, NOTE_G3, 200); 136 | delay(200); 137 | tone(audioPin, NOTE_C3, 200); 138 | delay(200); 139 | noTone(audioPin); 140 | } 141 | } 142 | 143 | // check the moisture range 144 | if(moistureSensorValue >= 700){ 145 | // in case of dry soil: 146 | // system messages 147 | lcd.clear(); 148 | RightHour(); 149 | lcd.setCursor(0,3); 150 | lcd.print(string_table[2]); 151 | // lights up the correct LED 152 | digitalWrite(drysoilLEDPin,HIGH); 153 | digitalWrite(moistsoilLEDPin,LOW); 154 | digitalWrite(soggyLEDPin,LOW); 155 | // plays the alarm sound 156 | tone(audioPin, NOTE_C6, 100); 157 | delay(250); 158 | noTone(audioPin); 159 | } 160 | if((moistureSensorValue < 700) && (moistureSensorValue >= 300)){ 161 | // in case of moist soil: 162 | // system messages 163 | lcd.clear(); 164 | RightHour(); 165 | lcd.setCursor(0,3); 166 | lcd.print(string_table[3]); 167 | // lights up the correct LED 168 | digitalWrite(drysoilLEDPin,LOW); 169 | digitalWrite(moistsoilLEDPin,HIGH); 170 | digitalWrite(soggyLEDPin,LOW); 171 | delay(250); 172 | } 173 | if(moistureSensorValue < 300){ 174 | // in case of soggy soil: 175 | // system messages 176 | lcd.clear(); 177 | RightHour(); 178 | lcd.setCursor(0,3); 179 | lcd.print(string_table[4]); 180 | // lights up the correct LED 181 | digitalWrite(drysoilLEDPin,LOW); 182 | digitalWrite(moistsoilLEDPin,LOW); 183 | digitalWrite(soggyLEDPin,HIGH); 184 | delay(100); 185 | } 186 | 187 | // if the soil is dry and if it is the right time: turn on the pump for 1 minute 188 | if((H == 16) && (M == 50) && (S == 00)){ 189 | while(moistureSensorValue >= 700){ 190 | // system messages 191 | lcd.clear(); 192 | RightHour(); 193 | lcd.setCursor(0,1); 194 | lcd.print(string_table[8]); 195 | lcd.setCursor(0,3); 196 | lcd.print(string_table[5]); 197 | // turn the pump on 198 | digitalWrite(pumpPin,HIGH); 199 | digitalWrite(pumpLEDPin,HIGH); 200 | delay(10000); 201 | // if the soil is not moist so far 202 | // reads the moisture sensor once more 203 | moistureSensorValue = analogRead(moistureSensorPin); 204 | } 205 | // turn the pump off 206 | digitalWrite(pumpPin,LOW); 207 | digitalWrite(pumpLEDPin,LOW); 208 | } 209 | 210 | } 211 | 212 | // Real Time Clock Function 213 | void RightHour() 214 | { 215 | DateTime Now = RTC.now(); 216 | String clock_date = " Date: "; 217 | String clock_hour = " Time: "; 218 | 219 | int _day = Now.day(); 220 | int _month = Now.month(); 221 | int _year = Now.year(); 222 | 223 | clock_date += fixZero(_day); 224 | clock_date += "/"; 225 | clock_date += fixZero(_month); 226 | clock_date += "/"; 227 | clock_date += _year; 228 | 229 | int _hour = Now.hour(); 230 | int _minute = Now.minute(); 231 | int _second = Now.second(); 232 | 233 | clock_hour += fixZero(_hour); 234 | clock_hour += ":"; 235 | clock_hour += fixZero(_minute); 236 | clock_hour += ":"; 237 | clock_hour += fixZero(_second); 238 | 239 | lcd.clear(); 240 | lcd.setCursor(0, 0); 241 | lcd.print(clock_date); 242 | lcd.setCursor(0, 1); 243 | lcd.print(clock_hour); 244 | 245 | delay(500); 246 | } 247 | 248 | 249 | String fixZero(int i) 250 | { 251 | String ret; 252 | if (i < 10) ret += "0"; 253 | ret += i; 254 | return ret; 255 | } 256 | 257 | 258 | --------------------------------------------------------------------------------