Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor kelembaban tanah atau intensitas air didalam tanah sehingga bisa diketahui apakah tanah tersebut subur ataukah tidak, alat ini menggunakan sensor soil moisture dan bisa dikendalikan manual menggunakan wifi. terdapat pompa yang akan menyala saat terdeteksi tanah tersebut kering. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino dan Ethernet Shield
b. Router
c. Sensor Soil Moisture
d. relay Modul
e. Program Arduino IDE
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2);
String txData="";
int mark = 0;
int counter;
int dryValue = 1023;
int wetValue = 0;
int friendlyDryValue = 0;
int friendlyWetValue = 100;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);
EthernetServer server(80);
String readString;
int buzzerp = 7;
int buzzerm = 9;
int vin;
int relay = 2;
float tegangan;
int x = 1;
int rawValue;
void setup() {
pinMode(buzzerp,OUTPUT);
pinMode(buzzerm,OUTPUT);
pinMode(relay,OUTPUT);
digitalWrite(buzzerp,LOW);
digitalWrite(buzzerm,LOW);
lcd.begin();
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
rawValue = analogRead(A3);
int tegangan = map(rawValue, dryValue, wetValue, friendlyDryValue, friendlyWetValue);
lcd.setCursor(0, 0);
lcd.print("S= ");
lcd.print(tegangan);
lcd.print(" % ");
if(x == 1){
lcd.setCursor(0, 1);
lcd.print("MANUAL ");
}
if(x == 2){
lcd.setCursor(0, 1);
lcd.print("OTOMATIS ");
}
if((tegangan > 0)&&(x == 2)){
digitalWrite(relay,LOW);
digitalWrite(buzzerp,HIGH);
digitalWrite(buzzerm,LOW);
}
if((tegangan <= 0)&&(x == 2)){
digitalWrite(relay,HIGH);
digitalWrite(buzzerp,LOW);
digitalWrite(buzzerm,LOW);
}
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(" ");
client.println("<title> Soil Moisture </title> ");
client.println("<body bgcolor = #000000>");
client.println("<center>");
client.println("<font color = yellow><center><h1>Soil Moisture Monitor</h1></center><br></font>");
client.println("<font color = #FFFFFF>");
if(x == 1){
client.println("<center>");
client.println("<h2>");
client.println("MANUAL");
client.println("</h2>");
client.println("</center>");
client.println("<br>");
}
if(x == 2){
client.println("<center>");
client.println("<h2>");
client.println("OTOMATIS");
client.println("</h2>");
client.println("</center>");
client.println("<br>");
}
client.println("<h2>");
client.println("S= ");
client.print(tegangan);
client.println(" % ");
client.println("<br>");
client.println("</h2>");
client.println("<a href = \"/?lighton\"\"><input type = 'button' value = ' POMPA ON' ></a>");
client.println("<a href = \"/?lightoff\"\"><input type = 'button' value = 'POMPA OFF' ></a> ");
client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = ' MANUAL' ></a>");
client.println("<a href = \"/?lightoff1\"\"><input type = 'button' value = 'OTOMATIS' ></a> ");
client.println("</font>");
client.println("</center>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disonnected");
}
if((readString.indexOf("?lighton") >0)&&(x == 1))
{
digitalWrite(relay,LOW);
}
else{
if((readString.indexOf("?lightoff") >0)&&(x == 1))
{
digitalWrite(relay,HIGH);
}
}
if(readString.indexOf("?lighton1") >0)
{
x = 1;
}
else{
if(readString.indexOf("?lightoff1") >0)
{
x = 2;
}
}
readString="";
delay(200);
}
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2);
String txData="";
int mark = 0;
int counter;
int dryValue = 1023;
int wetValue = 0;
int friendlyDryValue = 0;
int friendlyWetValue = 100;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);
EthernetServer server(80);
String readString;
int buzzerp = 7;
int buzzerm = 9;
int vin;
int relay = 2;
float tegangan;
int x = 1;
int rawValue;
void setup() {
pinMode(buzzerp,OUTPUT);
pinMode(buzzerm,OUTPUT);
pinMode(relay,OUTPUT);
digitalWrite(buzzerp,LOW);
digitalWrite(buzzerm,LOW);
lcd.begin();
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
rawValue = analogRead(A3);
int tegangan = map(rawValue, dryValue, wetValue, friendlyDryValue, friendlyWetValue);
lcd.setCursor(0, 0);
lcd.print("S= ");
lcd.print(tegangan);
lcd.print(" % ");
if(x == 1){
lcd.setCursor(0, 1);
lcd.print("MANUAL ");
}
if(x == 2){
lcd.setCursor(0, 1);
lcd.print("OTOMATIS ");
}
if((tegangan > 0)&&(x == 2)){
digitalWrite(relay,LOW);
digitalWrite(buzzerp,HIGH);
digitalWrite(buzzerm,LOW);
}
if((tegangan <= 0)&&(x == 2)){
digitalWrite(relay,HIGH);
digitalWrite(buzzerp,LOW);
digitalWrite(buzzerm,LOW);
}
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(" ");
client.println("<title> Soil Moisture </title> ");
client.println("<body bgcolor = #000000>");
client.println("<center>");
client.println("<font color = yellow><center><h1>Soil Moisture Monitor</h1></center><br></font>");
client.println("<font color = #FFFFFF>");
if(x == 1){
client.println("<center>");
client.println("<h2>");
client.println("MANUAL");
client.println("</h2>");
client.println("</center>");
client.println("<br>");
}
if(x == 2){
client.println("<center>");
client.println("<h2>");
client.println("OTOMATIS");
client.println("</h2>");
client.println("</center>");
client.println("<br>");
}
client.println("<h2>");
client.println("S= ");
client.print(tegangan);
client.println(" % ");
client.println("<br>");
client.println("</h2>");
client.println("<a href = \"/?lighton\"\"><input type = 'button' value = ' POMPA ON' ></a>");
client.println("<a href = \"/?lightoff\"\"><input type = 'button' value = 'POMPA OFF' ></a> ");
client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = ' MANUAL' ></a>");
client.println("<a href = \"/?lightoff1\"\"><input type = 'button' value = 'OTOMATIS' ></a> ");
client.println("</font>");
client.println("</center>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disonnected");
}
if((readString.indexOf("?lighton") >0)&&(x == 1))
{
digitalWrite(relay,LOW);
}
else{
if((readString.indexOf("?lightoff") >0)&&(x == 1))
{
digitalWrite(relay,HIGH);
}
}
if(readString.indexOf("?lighton1") >0)
{
x = 1;
}
else{
if(readString.indexOf("?lightoff1") >0)
{
x = 2;
}
}
readString="";
delay(200);
}
f. VIDEO HASILNYA
No comments:
Post a Comment