Perancangan Sistem Pengairan Tanaman Otomatis Menggunakan Grove Moisture Sensor Sen0100 Berbasis Arduino Leonardo dan Monitoring Melalui Wifi

84

LAMPIRAN

Universitas Sumatera Utara

90

LAMPIRAN (4) Gambar Skematik Sistem

Universitas Sumatera Utara

91

LAMPIRAN (5) Dokumentasi

Universitas Sumatera Utara

92

LAMPIRAN (6)

#include
#include
#include

Universitas Sumatera Utara

93

#define Wido_IRQ
7
#define Wido_VBAT 5
#define Wido_CS
10
#include "utility/debug.h"
#include
LiquidCrystal lcd(8,9,4,5,6,7);
int sensorPin = A1; // inisiasi Pin input nilai analog sensor
int sensorValue = 0; // variabel mulai sensor
// Tipe Security : WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA
or WLAN_SEC_WPA2


#define WLAN_SECURITY
WLAN_SEC_WPA2
#define WLAN_SSID
"LG"
// Nama SSID Wifi tidak
boleh lebih dari 32 karakter
#define WLAN_PASS
"lglglglglg" // Password WiFi
#define TCP_TIMEOUT
3000
// TCP Timeout
#define TOKEN "oFtshN0z3TIjQwWxH3eTmhV43Hj9dE" // TOKEN
Ubidots
#define VARIABLE_ID
"5730aa3476254206d2899ede" // ID
Variabel pada source yang akan diupload di UBidots

void setup(){
Serial.begin(115200);

Serial.println(F("Hello, CC3000!\n"));
/* Initialise the module */
Serial.println(F("\nInitialising the CC3000 ..."));
if (!Wido.begin())
{
Serial.println(F("Unable to initialise the CC3000! Check
your wiring?"));
while(1);
}
/* Attempt to connect to an access point */
char *ssid = WLAN_SSID;
/* Max 32 chars */
Serial.print(F("\nAttempting to connect to "));
Serial.println(ssid);
/* NOTE: Secure connections are not available in 'Tiny'
mode!
By default connectToAP will retry indefinitely, however you
can pass an
optional maximum number of retries (greater than zero) as
the fourth parameter.

*/

if (!Wido.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));

Universitas Sumatera Utara

94

/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!Wido.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
}
uint32_t ip = 0;

// Store Ubidots ip address
float temp = 0;
// Store temporary sensor data for post
Adafruit_CC3000_Client WidoClient;
void loop(){
static unsigned long RetryMillis = 0;
static unsigned long uploadtStamp = 0;
static unsigned long sensortStamp = 0;
if(!WidoClient.connected() && millis() - RetryMillis >
TCP_TIMEOUT){
// Update the time stamp for reconnecting the ip
RetryMillis = millis();
Serial.println(F("Trying to connect to Ubidots..."));
// Connect to Ubidots
ip = Wido.IP2U32(50,23,124,68);
WidoClient = Wido.connectTCP(ip, 80);
Serial.println(F("Successfully connected to Ubidots."));
}
if(WidoClient.connected() && millis() - uploadtStamp > 1000){
// If the device is connected to the cloud server, upload

the data every 1000ms.
uploadtStamp = millis();
moisture();
saklar2Ubidots(String variable, String value);
if (WidoClient.available())
// if text arrived in from WIDOCLIENT OTA...
{
a=(WidoClient.read());
if (a=='1')
{
int sensorValue = 0;
digitalWrite(13, HIGH);
}
if (a=='2')
{
sensorValue==1023;
digitalWrite(13, LOW);
delay(10000);
}
}

}

Universitas Sumatera Utara

95

// mengirim http data stream ke Ubidots bacaan sensor
sendstream2Ubidots(String variable, String value);
/********** Get the http page feedback and print the
response ***********/
unsigned long rTimer = millis();
Serial.println(F("Reading Cloud Response...\r\n"));
while (millis() - rTimer < 2000) {
while (WidoClient.connected() && WidoClient.available())
{
char c = WidoClient.read();
Serial.print(c);
}
}
delay(1000);

the data stream

// Wait for 1s to finish posting

WidoClient.close();
// Close the service connection
RetryMillis = millis(); // Reset the timer stamp for
applying the connection with the service
}
}
void moisture()
{
sensorValue = analogRead(sensorPin); // membaca nilai
keluaran sensor
if(sensorValue700 ){
lcd.print(“BASAH”);
}
else if(sensorValue >=300 &&sensorValue