Perancangan Sistem Pemanasan Mesin Sepeda Motor Secara Otomatis Berbasis Arduino

60

LAMPIRAN
1. Source code Arduino.
#include "Wire.h"
#include
#include
#define DS3231_I2C_ADDRESS 0x68
SoftwareSerial sim800l(11, 10);
int dLine[28];
byte *cacah=0;
String
stringPARA
"AT+HTTPPARA=\"URL\",\"http://autobike.pe.hu/input.php?fuel=";
String stringend = "\"";
String stringPARA2 = "";
String bt = "&battery=";
String en = "&engine_st=";
String tr = "&transmission_st=";
float fuel;
float battery;

String engine;
String transmission;
int power = 8;
int start = 9;
int pul = 3;
int net = 2;

=

byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}

void setup()
{
Wire.begin();
sim800l.begin(19200);
// the GPRS baud rate
Serial.begin(19200);

// the GPRS baud rate
delay(500);
pinMode(power,OUTPUT);
pinMode(start,OUTPUT);
pinMode(pul,OUTPUT);
pinMode(net,INPUT);
digitalWrite(power,HIGH);
delay (100);
digitalWrite(start,HIGH);
delay (100);

Universitas Sumatera Utara

61

cacah = 0;
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,

byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void SubmitHttpRequest()
{


stringPARA2 = stringPARA + fuel + bt + battery + en + engine + tr +
transmission + stringend;
//Serial.println(stringPARA2);
sim800l.println("AT+CSQ");
delay(1000);
ShowSerialData();
// this code is to show the data
from gprs shield, in order to easily see the process of how the gprs shield
submit a http request, and the following is for this purpose too.
sim800l.println("AT+CGATT?");
delay(1000);
ShowSerialData();
sim800l.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();

//setting


Universitas Sumatera Utara

62

sim800l.println("AT+SAPBR=3,1,\"APN\",\"internet\"");
APN, the second need you fill in your local apn server
delay(1000);
ShowSerialData();
sim800l.println("AT+SAPBR=1,1");
for detail you can refer to the AT command mamual
delay(2000);
ShowSerialData();
sim800l.println("AT+HTTPINIT");
delay(2000);
ShowSerialData();

//setting the

//setting the SAPBR,


//init the HTTP request

sim800l.println(stringPARA2);
// setting the httppara, the
second parameter is the website you want to access
delay(1000);
ShowSerialData();
sim800l.println("AT+HTTPACTION=0");//submit the request
delay(3000);
//the delay is very important, the
delay time is base on the return from the website, if the return datas are very
large, the time required longer.
ShowSerialData();
sim800l.println("AT+HTTPREAD");// read the data from the website you
access
delay(300);
ShowSerialData();
checkForResponse();

sim800l.println("AT+HTTPTERM");

delay(100);
}
void ShowSerialData()
{
while(sim800l.available()!=0)
Serial.write(sim800l.read());
}
void checkForResponse()
{
sim800l.println("AT+HTTPREAD");// read the data from the website you
access
delay(300);

Universitas Sumatera Utara

63

//ShowSerialData();
for (int i = 0; i < 50; i++)
{

dLine[i] = sim800l.read();
//Serial.println(dLine[i]);
}
Serial.println(dLine[28]);
if (dLine[28] != 97)
{
SubmitHttpRequest();
}
}

void sensor()
{
read_engine();
float Sensor1 = analogRead(A1);
delay (1000);
Serial.println(Sensor1);
fuel =(65.00 - Sensor1) *1.85;
if (fuel>100 || fuel10)
{
engine = "ON";

}
else
{
engine = "OFF";
}
Serial.println(engine);

// membaca staus mesin

}
void start_engine()
{
digitalWrite(power,LOW);
delay (4000);
sensor();
if(fuel>31.45 && battery > 10 && transmission == "NEUTRAL" && engine
== "OFF")
{
cacah = 0;
while (engine == "OFF" && cacah













c. Kelas Config.java
package com.example.harry.bikeauto;
/**
* Created by Harry on 1/30/2017.
*/
public class Config
{
public static final String DATA_URL =

"https://autobike.pe.hu/getdata.php";
public static final String KEY_BATTERY = "battery";
public static final String KEY_FUEL = "fuel";
public static final String KEY_ENGINE_ST = "engine_st";
public static final String KEY_TRANSMITION_ST = "transmition_st";
public static final String KEY_DATE = "date";
public static final String KEY_TIME = "time";
public static final String JSON_ARRAY = "result";
}

Universitas Sumatera Utara