└── hujan.ino /hujan.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define Select_PIN A5 5 | #define Sensor 8 6 | int Select_PINState; // variable for reading the pushbutton status 7 | int Sensor_State; // variable for reading the pushbutton status 8 | int sensorReading; 9 | int j,Status,Menit,Jam,Kategori; 10 | int Curah_Hujan,I,Intensitas,TotalCurahHujan; 11 | 12 | // initialize the library with the numbers of the interface pins 13 | LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 14 | 15 | // Enter a MAC address and IP address for your controller below. 16 | // The IP address will be dependent on your local network: 17 | byte mac[] = { 18 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 19 | IPAddress ip(192,168,1, 177); 20 | 21 | // Initialize the Ethernet server library 22 | // with the IP address and port you want to use 23 | // (port 80 is default for HTTP): 24 | EthernetServer server(80); 25 | 26 | void setup() { 27 | 28 | pinMode(Select_PIN, INPUT); 29 | digitalWrite(Select_PIN, HIGH); 30 | pinMode(Sensor, INPUT); 31 | digitalWrite(Sensor, HIGH); 32 | 33 | 34 | lcd.begin(16, 2); 35 | // Print a message to the LCD. 36 | lcd.print("Rain Gauge E-86"); 37 | lcd.setCursor(0, 1); 38 | lcd.print(" by VERONICA"); 39 | delay(3000); 40 | lcd.clear(); 41 | 42 | Intensitas = 0; 43 | 44 | Select_PINState = digitalRead(Select_PIN); 45 | if (Select_PINState == LOW) {LCDMonitor();} 46 | 47 | Ethernet.begin(mac, ip); 48 | server.begin(); 49 | } 50 | 51 | void Read_Sensor() { 52 | for (j=0;j<6000;j++){ //loop hingga 60 detik 53 | Sensor_State = digitalRead(Sensor); //baca sensor jungkit 54 | if ((Sensor_State == LOW)&&(Status == 0)) {I++;Status = 1;} //jika sensor berlogika 0 maka naikkan hitungan I 55 | if (Sensor_State == HIGH) {Status = 0;} //reset status setelah jungkitan ke posisi awal 56 | 57 | if(j < 3000){ 58 | lcd.clear(); 59 | lcd.setCursor(0, 0); 60 | lcd.print("Intens: mm/J "); 61 | lcd.setCursor(8, 0); 62 | lcd.print(Intensitas); 63 | 64 | lcd.setCursor(0, 1); 65 | lcd.print("Total: mm "); 66 | lcd.setCursor(8, 1); 67 | lcd.print(TotalCurahHujan); 68 | } 69 | if(j > 3000){ 70 | lcd.clear(); 71 | lcd.setCursor(0, 0); 72 | lcd.print("CrhHjn: mm/J "); 73 | lcd.setCursor(8, 0); 74 | lcd.print(Curah_Hujan); 75 | 76 | if (Intensitas >= 1){lcd.setCursor(0, 1);lcd.print(" Hujan Ringan ");} // "Hujan Ringan" 77 | if (Intensitas >= 50) {lcd.setCursor(0, 1);lcd.print(" Hujan Sedang ");} // "Hujan Sedang" 78 | if (Intensitas >= 100) {lcd.setCursor(0, 1);lcd.print(" Hujan Lebat ");} //"Hujan Lebat" 79 | if (Intensitas >= 200) {lcd.setCursor(0, 1);lcd.print(" Sangat Lebat ");} // "Sangat Lebat" 80 | } 81 | 82 | delay(10); //tunda 10mS 83 | } 84 | } 85 | 86 | void Read_Sensor1() { 87 | for (j=0;j<6000;j++){ //loop hingga 60 detik 88 | Sensor_State = digitalRead(Sensor); //baca sensor jungkit 89 | if ((Sensor_State == LOW)&&(Status == 0)) {I++;Status = 1;} //jika sensor berlogika 0 maka naikkan hitungan I 90 | if (Sensor_State == HIGH) {Status = 0;} //reset status setelah jungkitan ke posisi awal 91 | 92 | delay(10); //tunda 10mS 93 | } 94 | } 95 | 96 | void LCDMonitor() { 97 | while (Select_PINState == LOW){ 98 | Select_PINState = digitalRead(Select_PIN); 99 | 100 | Read_Sensor(); 101 | 102 | Intensitas = Intensitas + (I/6); //Intensitas/menit 103 | 104 | I = 0; 105 | 106 | if (Menit == 60){ 107 | TotalCurahHujan = TotalCurahHujan + (Intensitas/10); 108 | Jam++; 109 | Curah_Hujan = (TotalCurahHujan/Jam); 110 | Menit=0; 111 | Intensitas = 0;} //setelah 1 jam hitung curah hujan dan reset intensitas 112 | 113 | Menit++; 114 | } 115 | } 116 | 117 | 118 | void Web() { 119 | 120 | // listen for incoming clients 121 | EthernetClient client = server.available(); 122 | if (client) { 123 | boolean currentLineIsBlank = true; 124 | while (client.connected()) { 125 | if (client.available()) { 126 | char c = client.read(); 127 | Serial.write(c); 128 | 129 | if (c == '\n' && currentLineIsBlank) { 130 | // send a standard http response header 131 | client.println("HTTP/1.1 200 OK"); 132 | client.println("Content-Type: text/html"); 133 | client.println("Connnection: close"); 134 | client.println(); 135 | client.println(""); 136 | client.println(""); 137 | // add a meta refresh tag, so the browser pulls again every 5 seconds: 138 | client.println(""); 139 | 140 | client.print(" "); 141 | client.println("
"); 142 | client.print(" Sistem Monitoring curah hujan berbasis WEB "); 143 | client.println("
"); 144 | client.print(" "); 145 | client.println("
"); 146 | client.println("
"); 147 | 148 | client.print("--- Intensitas : "); 149 | client.print(Intensitas); 150 | client.print(" mm/jam"); 151 | 152 | client.println("
"); 153 | client.println("
"); 154 | 155 | client.print("--- Total Curah Hujan : "); 156 | client.print(TotalCurahHujan); 157 | client.print(" mm"); 158 | 159 | client.println("
"); 160 | client.println("
"); 161 | 162 | client.print("--- Curah hujan : "); 163 | client.print(Curah_Hujan); 164 | client.print(" mm/jam"); 165 | client.println("
"); 166 | client.println("
"); 167 | 168 | client.print("--- Jam : "); 169 | client.print(Jam); 170 | client.print(" : "); 171 | client.print(Menit); 172 | client.println("
"); 173 | client.println("
"); 174 | client.print("--- Kategori : "); 175 | 176 | if (Kategori == 1){client.print(" Hujan Ringan");} 177 | if (Kategori == 2){client.print(" Hujan Sedang");} 178 | if (Kategori == 3){client.print(" Hujan Lebat");} 179 | if (Kategori == 4){client.print(" Hujan Sangat Lebat");} 180 | 181 | client.println("
"); 182 | client.println("
"); 183 | client.println(""); 184 | 185 | break; 186 | } 187 | if (c == '\n') { 188 | // you're starting a new line 189 | currentLineIsBlank = true; 190 | } 191 | else if (c != '\r') { 192 | // you've gotten a character on the current line 193 | currentLineIsBlank = false; 194 | } 195 | } 196 | } 197 | // give the web browser time to receive the data 198 | delay(1); 199 | // close the connection: 200 | client.stop(); 201 | Serial.println("client disonnected"); 202 | } 203 | } 204 | 205 | 206 | 207 | void loop() { 208 | 209 | Web(); 210 | 211 | Read_Sensor1(); 212 | Intensitas = Intensitas + (I/6); //Intensitas/detik 213 | 214 | if (Intensitas >= 1){Kategori = 1;} // "Hujan Ringan" 215 | if (Intensitas >= 50) {Kategori = 2;} // "Hujan Sedang" 216 | if (Intensitas >= 100) {Kategori = 3;} //"Hujan Lebat" 217 | if (Intensitas >= 200) {Kategori = 4;} // "Sangat Lebat" 218 | 219 | I = 0; 220 | Menit++; 221 | 222 | if (Menit == 60){ 223 | Jam++; 224 | TotalCurahHujan = TotalCurahHujan + (Intensitas/10); 225 | Curah_Hujan = (TotalCurahHujan/Jam); 226 | Menit=0; 227 | Intensitas = 0;} //setelah 1 jam hitung curah hujan dan reset intensitas 228 | 229 | } 230 | 231 | 232 | --------------------------------------------------------------------------------