Você está na página 1de 12

#include <LiquidCrystal.

h>
#include <OneWire.h>
#include <Wire.h>
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
#include <PString.h>
#include "Adafruit_Thermal.h"
#include "adalogo.h"
#include <EEPROM.h>
#include "adaqrcode.h"
unsigned long lastAttemptTime = 0;
#include <Wire.h>
#include "RTClib.h"
int buzzer=17;
OneWire ds(16);
boolean mesin=false;
int a,b,c;
RTC_DS1307 RTC;
char buffer[40];
int tahun;
int dayOfWeek, dayOfMonth, month, year;
PString str(buffer, sizeof(buffer));
#include "SoftwareSerial.h"
#define TX_PIN 7
#define RX_PIN 8
int value1,value2,value3,value4,value5,value6;
SoftwareSerial mySerial(RX_PIN, TX_PIN);
Adafruit_Thermal printer(&mySerial);

int hitung=0;
int hours;
int hh;
int mm;
int ss;
int buttonPin = 6;
int but2=9;
int but3=10;
int buttonState,BS2,BS3=0;
int lastButtonState,L2,L3 = LOW;
long lastDebounceTime,D2,D3 = 0;
long debounceDelay = 50;
int relay1=14;
int relay2=15;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(but2,INPUT_PULLUP);
pinMode(but3,INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
value1 = EEPROM.read(0);
value2 = EEPROM.read(1);
value3 = EEPROM.read(2);
value4=EEPROM.read(5);
value5=EEPROM.read(6);
value6=EEPROM.read(7);
value1=value1*100;
value2=value2*10;
hitung=value1+value2+value3;
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("AutoEngine Start");
digitalWrite(buzzer, HIGH);
lcd.setCursor(0,1);
lcd.print(" duwiarsana.com ");
delay(50);
digitalWrite(buzzer,LOW);
delay(100);
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer,LOW);
delay(2000);
Wire.begin();
RTC.begin();

pinMode(buttonPin, INPUT_PULLUP);
pinMode(but2,INPUT_PULLUP);
pinMode(but3,INPUT_PULLUP);
//pinMode(4, OUTPUT); digitalWrite(4, LOW);

mySerial.begin(9600);

printer.begin();
lcd.clear();
Wire.beginTransmission(0X68);
Wire.write(0x07);
Wire.write(0x10);
Wire.endTransmission();

void loop() {
float temperature = getTemp();
awal:
buttonState = digitalRead(buttonPin);
// BS2=digitalRead(but2);
//BS3=digitalRead(but3);
baca();

value4=EEPROM.read(5);
value5=EEPROM.read(6);
value6=EEPROM.read(7);

if(b==LOW){
lcd.clear();

delay(500);
baca();
while(b){
value4=EEPROM.read(5);
lcd.setCursor(0,0);
lcd.print("Set Jam :");
lcd.print(value4);
lcd.print(" ");
baca();
if(a==LOW){
value4+=1;
if(value4>23){
value4=0;
}
EEPROM.write(5,value4);
delay(200);
}
if(c==LOW){
value4-=1;
if(value4<0){
value4=23;
}
EEPROM.write(5,value4);
delay(200);
}

if(!b){
lcd.clear();
delay(500);
baca();
while(b){
value5=EEPROM.read(6);
lcd.setCursor(0,0);
lcd.print("Set Menit :");
lcd.print(value5);
lcd.print(" ");
baca();
if(a==LOW){
value5+=1;
if(value5>59){
value5=0;
}
EEPROM.write(6,value5);
delay(200);
}
if(c==LOW){
value5-=1;
if(value5<0){
value5=59;
}
EEPROM.write(6,value5);
delay(200);
}

if(!b){
lcd.clear();
delay(500);
baca();
while(b){
value6=EEPROM.read(7);
lcd.setCursor(0,0);
lcd.print("Durasi :");
lcd.print(value6);
lcd.print(" ");
baca();
if(a==LOW){
value6+=1;
if(value6>10){
value6=0;
}
EEPROM.write(7,value6);
delay(200);
}
if(c==LOW){
value6-=1;
if(value6<0){
value6=10;
}
EEPROM.write(7,value6);
delay(200);
}
if(!b){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Disimpan!!");
delay(2000);
goto awal;
}
// delay(500);
}
}

// delay(500);

}
}
//delay(500);
}
}

if (digitalRead(but3) == LOW) {
delay(2000);
if(digitalRead(but3)==LOW){
lcd.clear();
lcd.print("menyalakan");
digitalWrite(relay1,HIGH);
delay(2000);
digitalWrite(relay2,HIGH);
baca();
while(!c){
digitalWrite(relay2,HIGH);
delay(100);
baca();

}
digitalWrite(relay2,LOW);
lcd.clear();
lcd.print("get");
delay(1000);
baca();
while(c){
delay(1000);
baca();
lcd.setCursor(0,0);
lcd.print("3 untuk off");
if(!c){
digitalWrite(relay1,LOW);
delay(5000);
goto awal;
}

}
}

else {

}
unsigned long CurrentMillis = millis();
DateTime now = RTC.now();
hours = now.hour();
mm = now.minute();
ss = now.second();
dayOfMonth=now.day();
month=now.month();
year=now.year();
str.begin();
if(!mesin){
delay(1000);
if(hours==value4){
if(mm==value5){
ulang:
mesin=true;
float sementara=temperature;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Kontak On");
digitalWrite(relay1,HIGH);

delay(5000);
lcd.clear();
lcd.print("Start Mesin");
delay(2000);
digitalWrite(relay2,HIGH);
delay(3000);
digitalWrite(relay2,LOW);
delay(10000);
temperature=getTemp();

// if(temperature>(sementara+2)){
// //mesin hidup
// while(mm<=value6)
// {
//
//
// delay(100);
//
// }
// digitalWrite(relay1,LOW);
// mesin=true;
// goto awal;
//
// }
// else{
// //mesin ga idup
// delay(5000);
// lcd.clear();
// lcd.print("Mengulang!!");
// delay(5000);
// goto ulang;
// }
}
}
}
else{
if(mm>=(value5+value6)){
lcd.clear();
lcd.print("Mesin Dimatikan");
delay(2000);
digitalWrite(relay1,LOW);
mesin=false;
delay(5000);
}

}
if(millis()-lastAttemptTime>0&&millis()-lastAttemptTime<5000)
{
str.print(now.day(), DEC);
str.print('-');
str.print(now.month(), DEC);
str.print('-');
str.print(now.year(), DEC);
str.print(' ');
lcd.setCursor(0,0);
lcd.print("Date: ");
lcd.print(str);
lcd.print(" ");
}
else if(millis()-lastAttemptTime>5000&&millis()-lastAttemptTime<10000)
{
str.print(now.hour(), DEC);
str.print(':');
if(mm<10)
{
str.print('0');
}
str.print(mm);
str.print(':');
if(ss<10)
{
str.print('0');
}
str.print(ss);
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(str);
lcd.print(" ");

}
else if(millis()-lastAttemptTime>10000)
{
lastAttemptTime=millis();
}
baca();
if(!a)
{
lcd.clear();
delay(500);
baca();
while(a)
{
lcd.setCursor(0,0);
lcd.print("Set Jam: ");
DateTime now = RTC.now();
hours = now.hour();
mm = now.minute();
ss = now.second();
dayOfMonth=now.day();
month=now.month();
year=now.year();
lcd.print(hours);
lcd.print(" ");
baca();
if(!b){
delay(300);
hours+=1;
if(hours>23)
{
hours=0;
}
//updateRTC();
}
if(!c){
delay(300);
hours-=1;
if(hours<0)
{
hours=23;
}
}
if(!a)
{
delay(500);
lcd.clear();
baca();
while(a)
{
lcd.setCursor(0,0);
lcd.print("Set Menit: ");
DateTime now = RTC.now();
hours = now.hour();
mm = now.minute();
ss = now.second();
dayOfMonth=now.day();
month=now.month();
year=now.year();
lcd.print(mm);
lcd.print(" ");
baca();
//setmm
if(!b){
delay(300);
mm+=1;
if(mm>59)
{
mm=0;
}
//updateRTC();
}
if(!c){
delay(300);
mm-=1;
if(mm<0)
{
mm=59;
}
}
if(!a)
{
delay(500);
lcd.clear();
baca();
while(a)
{
lcd.setCursor(0,0);
lcd.print("Set Tanggal: ");
DateTime now = RTC.now();
hours = now.hour();
mm = now.minute();
ss = now.second();
dayOfMonth=now.day();
month=now.month();
year=now.year();
//mm = now.minute();
//ss = now.second();
lcd.print(dayOfMonth);
lcd.print(" ");
baca();
if(!b)
{
delay(300);
dayOfMonth+=1;
if(dayOfMonth>31){
dayOfMonth=1;
}
}
if(!c)
{
delay(300);
dayOfMonth-=1;
if(dayOfMonth<1)
{
dayOfMonth=31;
}
}
if(!a)
{
delay(500);
lcd.clear();
baca();
while(a)
{
lcd.setCursor(0,0);
lcd.print("Set Bulan: ");
DateTime now = RTC.now();
hours = now.hour();
mm = now.minute();
ss = now.second();
dayOfMonth=now.day();
month=now.month();
year=now.year();
//mm = now.minute();
//ss = now.second();
lcd.print(month);
lcd.print(" ");
baca();
if(!b)
{
delay(300);
month+=1;
if(month>12)
{month=1;}
}
if(!c)
{
delay(300);
month-=1;
if(month<1)
{month=12;}
}
if(!a)
{
delay(500);
lcd.clear();
baca();
while(a)
{
lcd.setCursor(0,0);
lcd.print("Set Tahun: ");
getDateDs1307();

//mm = now.minute();
//ss = now.second();
lcd.print("20");
lcd.print(year);
lcd.print(" ");
baca();
if(!b)
{
delay(300);
year+=1;
if(year>99)
{year=16;}
}
if(!c)
{
delay(300);
year-=1;
if(year<16)
{year=99;}
}
updateRTC();
}
}
updateRTC();
}
}
updateRTC();
}
}
updateRTC();
}
}
updateRTC();
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Disimpan!!");
delay(1000);
lcd.clear();
}
tampil();
}

void tampil(){

lcd.setCursor(0,1);
lcd.print("Suhu : ");
if(getTemp()<0){
lcd.print("Error");
}
else
lcd.print(getTemp());
lcd.print(" ");
if(mesin){
lcd.print("HI");
lcd.print(" ");
}
else{lcd.print("MA");lcd.print(" ");}
value1=(hitung%1000)/100;
value2=(hitung%100)/10;
value3=(hitung%10);
EEPROM.write(0,value1);
EEPROM.write(1,value2);
EEPROM.write(2,value3);
}
byte decToBcd(byte val) {
return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val) {


return ( (val/16*10) + (val%16) );
}
void updateRTC() {
Wire.beginTransmission(104);
Wire.write(0);
Wire.write(decToBcd(ss));
Wire.write(decToBcd(mm));
Wire.write(decToBcd(hours));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
// year=year-2000;
Wire.write(decToBcd(year));
Wire.endTransmission();
}

void getDateDs1307()
{
// Reset the register pointer
Wire.beginTransmission(0x68);
//Wire.write(0x00);
Wire.write(0);
Wire.endTransmission();

Wire.requestFrom(0x68, 7);

// A few of these need masks because certain bits are control bits
ss = bcdToDec(Wire.read() & 0x7f);
mm = bcdToDec(Wire.read());
hours = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour
am/pm
dayOfWeek = bcdToDec(Wire.read());
dayOfMonth = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());

float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {


return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {


return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();


ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes


data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];


byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment


float TemperatureSum = tempRead / 16;

return TemperatureSum;

Você também pode gostar