Blogger Jateng

Arduino Control automatic alarm device from android app

Berikut kodingannya:

#define namaSekolah "JAMBI"

#define SQWPin A3
#define pinRelay 3
#define relay2 7
#define relay3 4
#define positif 13
#define buzzer A0
#define ledMerah A2
#define ledHijau A1
#define relayOn LOW

#include <avr/sleep.h>
#include
#include
#include "RTC.h"
#include
#include
#include

#define tokenEEPROM 0x83
SoftwareSerial bluetooth(10, 9); // RX, TX
SoftwareSerial mp3Serial(11, 12); // RX, TX
LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

struct Waktu
{
byte jam;
byte menit;
};

struct TabelMataPelajaran
{
byte aktif;
Waktu waktu;
byte hariAktif;
byte mingguAktif;
byte kegiatan;
};

const char kegiatanText[][17] PROGMEM = {
"- ",
"Jam Pelajaran 1 ",
"Jam Pelajaran 2 ",
"Jam Pelajaran 3 ",
"Jam Pelajaran 4 ",
"Jam Pelajaran 5 ",
"Jam Pelajaran 6 ",
"Jam Pelajaran 7 ",
"Jam Pelajaran 8 ",
"Jam Pelajaran 9 ",
"Jam Pelajaran 10",
"Jam Pelajaran 11",
"Jam Pelajaran 12",
"Jam Pelajaran 13",
"Jam Pelajaran 14",
"Jam Pelajaran 15",
"Masuk ",
"Upacara ",
"Istirahat ",
"Istirahat1 ",
"Istirahat2 ",
"Istirahat3 ",
"Selesai istiraht",
"Kepramukaan ",
"Khusus ",
"Pulang ",
"Pulang Jum'at ",
"Pulang Sabtu ",
"Pulang Akh Pekan",
"Costum1 ",
"Costum2 ",
};

enum _kegiatan
{
TidakAda,
JamPelajaran1,
JamPelajaran2,
JamPelajaran3,
JamPelajaran4,
JamPelajaran5,
JamPelajaran6,
JamPelajaran7,
JamPelajaran8,
JamPelajaran9,
JamPelajaran10,
JamPelajaran11,
JamPelajaran12,
JamPelajaran13,
JamPelajaran14,
JamPelajaran15,
Masuk,
Upacara,
Istirahat,
Istirahat1,
Istirahat2,
Istirahat3,
SelesaiIstirahat,
Kepramukaan,
Khusus,
Pulang,
PulangJumat,
PulangSabtu,
PulangAkhPekan,
Costum1,
Costum2,
};
enum PengaturanAndroid
{
cekAses,
pengaturanJadwal,
pengaturanWaktu,

};

char karakterMusik[8] = {
0b00000,
0b00100,
0b00110,
0b00101,
0b00101,
0b00100,
0b11100,
0b11100
};
byte karakterDetik1[8] = {
0b00000,
0b00000,
0b00000,
0b00100,
0b00000,
0b00000,
0b00000,
0b00000
};
byte karakterDetik2[8] = {
0b00000,
0b00000,
0b00100,
0b01010,
0b00100,
0b00000,
0b00000,
0b00000
};
byte karakterDetik3[8] = {
0b00000,
0b00100,
0b01010,
0b10001,
0b01010,
0b00100,
0b00000,
0b00000
};
byte karakterSetting[8] = {
0b00100,
0b00100,
0b00100,
0b01110,
0b00100,
0b10001,
0b01010,
0b00100
};

volatile bool interupsiDetik;
byte indexMataPelajaran;
RTC_DS3231 rtc;
DateTime now;
bool rtcValid;
byte indexPengaturanJadwal = 0;

#define hariAktifSenin 1<<6
#define hariAktifSelasa 1<<5
#define hariAktifRabu 1<<4
#define hariAktifKamis 1<<3
#define hariAktifJumat 1<<2
#define hariAktifSabtu 1<<1
#define hariAktifMinggu 1<<7

char namaHari[][7] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jum'at", "Sabtu"};
#define _hariAktif(Sen,Sel,Rab,Kam,Jum,Sab,Mgu) (Mgu<<7)|(Sen<<6)|(Sel<<5)|(Rab<<4)|(Kam<<3)|(Jum<<2)|(Sab<<1)
//#define _mingguAktif(Mgu1,Mgu2,Mgu3,Mgu4,Mgu5) (Mgu1<<7)|(Mgu2<<6)|(Mgu3<<5)|(Mgu4<<4)|(Mgu5<<3)
#define _waktu(Jam, Menit) {Jam, Menit}
#define Aktif 1
#define TidakAktif 0

TabelMataPelajaran jadwalBelajar[40];
Waktu waktu;

char bufWaktu[40];
byte detikSebelumnya = 60;
byte menitSebelumnya = 60;
byte tanggalSebelumnya = 0;
Waktu jadwalBerikutnya;
byte menitBel;
bool statusBel;
bool statusPengingat;

byte jadwalBerikutnyaKegiatan;

void setup() {
digitalWrite(pinRelay, !relayOn);
pinMode(pinRelay, OUTPUT);
pinMode(SQWPin, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
pinMode(ledHijau, OUTPUT);
pinMode(ledMerah, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(positif, OUTPUT);

digitalWrite(positif, HIGH);
digitalWrite(ledMerah, LOW);
digitalWrite(ledHijau, HIGH);
digitalWrite(buzzer, HIGH);
digitalWrite(relay2, LOW);
delay(500);
digitalWrite(ledMerah, LOW);
digitalWrite(buzzer, LOW);

Serial.begin(9600);
Serial.println(F("Bel Sekolah Dengan Kontrol Android"));
Serial.println(F("https://www.semesin.com/project"));
Serial.println();

Wire.begin();
Wire.beginTransmission(0x3F);
if (Wire.endTransmission())
{
lcd = LiquidCrystal_I2C(0x27, 16, 2);
}
lcd.begin();

lcd.command (0x40 | (0 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterDetik1[i]);

lcd.command (0x40 | (1 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterDetik2[i]);

lcd.command (0x40 | (2 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterDetik3[i]);

lcd.command (0x40 | (3 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterDetik2[i]);

lcd.command (0x40 | (4 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterMusik[i]);

lcd.command (0x40 | (5 << 3));
for (byte i = 0; i < 8; i++)
lcd.write (karakterSetting[i]);

lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("SMKS DB 1");
lcd.setCursor(0, 1);
lcd.print(namaSekolah);

mp3Serial.begin(9600);
bluetooth.begin (9600);
bluetooth.listen();

mp3_set_serial (mp3Serial);
mp3_set_volume (30);//full volume 0x30

rtc.begin();

if (rtc.lostPower())
{
Serial.println(F("RTC lost power, lets set the time!"));
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

rtc.writeSqwPinMode(DS3231_SquareWave1Hz);

if (EEPROM.read(sizeof(jadwalBelajar)) != tokenEEPROM)
{
nilaiAwal();
EEPROM.write(sizeof(jadwalBelajar), tokenEEPROM);
Serial.println("setting awal");
}

EEPROM.get(0, jadwalBelajar);
cekJadwalHariIni();

delay(1000);

lcd.clear();

Serial.println(F("Sistem bel sekolah dimulai"));

}

void loop() {
if (digitalRead(SQWPin))
{
if (rtcValid)
{
rtcValid = false;

now = rtc.now();

uint16_t unixJadwalBerikutnya = (jadwalBerikutnya.jam * 60) + jadwalBerikutnya.menit;
uint16_t unixWaktu = (now.jam * 60) + now.menit;

if (!now.detik)
{
if (jadwalBerikutnyaKegiatan && (jadwalBerikutnya.jam == now.jam) && (jadwalBerikutnya.menit == now.menit))
{
lcd.setCursor(6, 1);
lcd.print((char)4);
lcd.setCursor(0, 0);
lcd.print((__FlashStringHelper *)kegiatanText[jadwalBerikutnyaKegiatan]);

mp3_play (jadwalBerikutnyaKegiatan);
Serial.println((__FlashStringHelper *)kegiatanText[jadwalBerikutnyaKegiatan]);
menitBel = jadwalBerikutnya.menit;
statusBel = true;
statusPengingat = false;
}
else if (jadwalBerikutnyaKegiatan && (unixWaktu == unixJadwalBerikutnya - 1))
{
statusPengingat = true;
digitalWrite(pinRelay, relayOn);
Serial.println("Pengingat bel masuk 1 menit lagi");
}
}

if (menitBel != now.menit)
{
if (statusBel)
{
lcd.setCursor(6, 1);
lcd.print(' ');

digitalWrite(pinRelay, !relayOn);

cariJadwal();
statusBel = false;
tanggalSebelumnya = 0;
}
}

//tampilan
if (statusPengingat)
{
lcd.setCursor(1, 1);
if (now.detik % 2)
{
sprintf(bufWaktu, "%02d:%02d", jadwalBerikutnya.jam, jadwalBerikutnya.menit);
lcd.print(bufWaktu);
}
else
{
lcd.print(" ");
}
}

if (detikSebelumnya != now.detik)
{
sprintf(bufWaktu, "%02d:%02d:%02d", now.jam, now.menit, now.detik);
lcd.setCursor(8, 1);
lcd.print(bufWaktu);
lcd.setCursor(0, 1);
lcd.print((char)(now.detik % 4));

sprintf(bufWaktu, "%02d:%02d:%02d %s, %02d/%02d/%02d", now.jam, now.menit, now.detik, namaHari[now.hari - 1], now.tanggal, now.bulan, now.tahun - 2000);
Serial.println(bufWaktu);
}

//---------------------------
if (menitSebelumnya != now.menit)
{
menitSebelumnya = now.menit;
{
for (byte i = 0; i < sizeof(jadwalBelajar) / sizeof(TabelMataPelajaran); i++) { if(jadwalBelajar[i].aktif) { if ((jadwalBelajar[i].waktu.jam == now.jam) && (jadwalBelajar[i].waktu.menit == now.menit)) { switch(jadwalBelajar[i].kegiatan) { case JamPelajaran1: Serial.println("Jam Pelajaran 1"); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(1000); mp3_play(1); break; case JamPelajaran2: Serial.println("Jam Pelajaran 2"); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); mp3_play(2); break; case JamPelajaran3: Serial.println("Jam Pelajaran 3"); mp3_play(3); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran4: Serial.println("Jam Pelajaran 4"); mp3_play(4); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran5: Serial.println("Jam Pelajaran 5"); mp3_play(5); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran6: Serial.println("Jam Pelajaran 6"); mp3_play(6); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran7: Serial.println("Jam Pelajaran 7"); mp3_play(7); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran8: Serial.println("Jam Pelajaran 8"); mp3_play(8); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran9: Serial.println("Jam Pelajaran 9"); mp3_play(9); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case JamPelajaran10: Serial.println("Jam Pelajaran 10"); mp3_play(10); digitalWrite(relay3, HIGH); digitalWrite(relay2, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledHijau, LOW); delay(2000); break; case Masuk: Serial.println("Masuk"); break; case Upacara: Serial.println("Upacara"); break; case Istirahat: Serial.println("Istirahat"); mp3_play(11); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); delay(2000); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledMerah, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); digitalWrite(ledMerah, LOW); delay(2000); digitalWrite(ledMerah, HIGH); digitalWrite(ledHijau, LOW); delay(10000); break; case Pulang: Serial.println("Jam pelajaran telah selesai, sampai jumpa esok hari"); mp3_play(12); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); delay(7000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); delay(10000); break; case PulangJumat: Serial.println("Jam pelajaran telah selesai, sampai jumpa minggu depan"); mp3_play(13); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); delay(10000); break; case PulangSabtu: Serial.println("Jam pelajaran telah selesai, sampai jumpa minggu depan"); mp3_play(14); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); digitalWrite(relay2, HIGH); delay(2000); digitalWrite(relay2, LOW); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(ledMerah, LOW); digitalWrite(ledHijau, LOW); delay(2000); digitalWrite(relay2, HIGH); digitalWrite(relay3, HIGH); digitalWrite(buzzer, HIGH); digitalWrite(ledHijau, HIGH); digitalWrite(ledMerah, HIGH); delay(2000); digitalWrite(buzzer, LOW); digitalWrite(relay3, LOW); digitalWrite(relay2, LOW); delay(10000); break; default: Serial.println("Lainnya"); break; } } } } } } //--------------------------------------------------------- if (tanggalSebelumnya != now.tanggal) { tanggalSebelumnya = now.tanggal; lcd.clear(); lcd.print(namaHari[now.hari - 1]); lcd.print(','); sprintf(bufWaktu, "%02d/%02d/%02d", now.tanggal, now.bulan, now.tahun - 2000); lcd.setCursor(8, 0); lcd.print(bufWaktu); cariJadwal(); } } } else { rtcValid = true; } cekBluetooth(); } void cekBluetooth() { uint8_t tokenMulai; uint8_t perintah; uint8_t parameter; uint8_t panjang1; uint8_t panjang2; char c; uint8_t i, j; uint8_t tokenSelesai; byte bufferSerial[100]; byte *alamat; if (bluetooth.available()) { tokenMulai = bluetoothRead(); if (tokenMulai == 0xFD) { panjang1 = bluetoothRead(); panjang2 = bluetoothRead(); if (panjang2 == 254 - panjang1) { if (panjang1 >= sizeof(bufferSerial))
{
panjang1 = sizeof(bufferSerial);
}

uint16_t timeOut = 0xFFF;
i = 0;
do
{
if (bluetooth.available())
{
c = bluetoothRead();
bufferSerial[i++] = c;
}
} while ((i < panjang1 + 3) && (timeOut--));

perintah = bufferSerial[0];
parameter = bufferSerial[1];

tokenSelesai = bufferSerial[i - 1];
if (tokenSelesai == 0x00)
{
delay(10);
bluetooth.write(254);
switch (perintah)
{
case cekAses:
bluetooth.write(1);
bluetooth.write(254);
break;
case pengaturanJadwal:
lcd.setCursor(6, 1);
lcd.print((char)5);

memcpy((byte*)&jadwalBelajar[parameter], bufferSerial + 2, sizeof(TabelMataPelajaran));
if (parameter == (sizeof(jadwalBelajar) / sizeof(TabelMataPelajaran)) - 1)
{
EEPROM.put(0, jadwalBelajar);
Serial.println("Jadwal diterima");

lcd.setCursor(6, 1);
lcd.print(' ');

tanggalSebelumnya = 0;
}
break;
case pengaturanWaktu:
memcpy((byte*)&now, bufferSerial + 2, sizeof(DateTime));
rtc.adjust(now);
tanggalSebelumnya = 0;
Serial.println("Setting waktu diterima");
break;
}
}
else
{
bluetooth.write(252);//data tidak benar
}
}
}
}
}
byte bluetoothRead()
{
uint16_t timeOut = 0xFFF;
while (!bluetooth.available() && timeOut--);
return bluetooth.read();
}

void nilaiAwal()
{
byte i = 0;
jadwalBelajar[i++] = {Aktif, _waktu( 7, 20 ), hariAktifSenin , Upacara};
jadwalBelajar[i++] = {Aktif, _waktu( 7, 20 ), _hariAktif(0, 1, 1, 1, 1, 0, 0), JamPelajaran1};

jadwalBelajar[i++] = {Aktif, _waktu( 7, 50 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran2};
jadwalBelajar[i++] = {Aktif, _waktu( 8, 30 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran3};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 5 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran4};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 45 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), Istirahat};
jadwalBelajar[i++] = {Aktif, _waktu( 10, 0 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran5};
jadwalBelajar[i++] = {Aktif, _waktu( 10, 35 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran6};
jadwalBelajar[i++] = {Aktif, _waktu( 11, 10 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), Istirahat};
jadwalBelajar[i++] = {Aktif, _waktu( 11, 45 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran7};
jadwalBelajar[i++] = {Aktif, _waktu( 12, 25 ), _hariAktif(1, 1, 1, 1, 0, 0, 0), JamPelajaran8};
jadwalBelajar[i++] = {Aktif, _waktu( 13, 0 ), _hariAktif(1, 1, 1, 0, 0, 0, 0), JamPelajaran9};
jadwalBelajar[i++] = {Aktif, _waktu( 13, 25 ), _hariAktif(1, 1, 1, 0, 0, 0, 0), JamPelajaran10};
jadwalBelajar[i++] = {Aktif, _waktu( 13, 30 ), _hariAktif(1, 1, 1, 0, 0, 0, 0), Pulang};

jadwalBelajar[i++] = {Aktif, _waktu( 7, 50 ), hariAktifJumat, JamPelajaran2};
jadwalBelajar[i++] = {Aktif, _waktu( 8, 30 ), hariAktifJumat, JamPelajaran3};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 25 ), hariAktifJumat, Istirahat};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 35 ), hariAktifJumat, JamPelajaran5};
jadwalBelajar[i++] = {Aktif, _waktu( 11, 15 ), hariAktifJumat, PulangJumat};

jadwalBelajar[i++] = {Aktif, _waktu( 7, 55 ), hariAktifSabtu, JamPelajaran2};
jadwalBelajar[i++] = {Aktif, _waktu( 8, 35 ), hariAktifSabtu, JamPelajaran3};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 25 ), hariAktifSabtu, JamPelajaran4};
jadwalBelajar[i++] = {Aktif, _waktu( 9, 40 ), hariAktifSabtu, Istirahat};
jadwalBelajar[i++] = {Aktif, _waktu( 10, 15 ), hariAktifSabtu, JamPelajaran5};
jadwalBelajar[i++] = {Aktif, _waktu( 10, 50 ), hariAktifSabtu, JamPelajaran6};
jadwalBelajar[i++] = {Aktif, _waktu( 12, 15 ), hariAktifSabtu, PulangSabtu};

EEPROM.put(0, jadwalBelajar);
}

void cekJadwalHariIni()
{
Serial.println("Jadwal hari ini");
for (byte i = 0; i < sizeof(jadwalBelajar) / sizeof(TabelMataPelajaran) ; i++)
{
Serial.print(jadwalBelajar[i].aktif);
Serial.print('\t');
Serial.print(jadwalBelajar[i].waktu.jam);
Serial.print('\t');
Serial.print(jadwalBelajar[i].waktu.menit);
Serial.print('\t');
Serial.print(jadwalBelajar[i].hariAktif, HEX);
Serial.print('\t');
Serial.print(jadwalBelajar[i].mingguAktif, HEX);
Serial.print('\t');
Serial.print(jadwalBelajar[i].kegiatan);
Serial.print('\t');
char buf[20];
memcpy_P(buf, kegiatanText[jadwalBelajar[i].kegiatan], sizeof(kegiatanText[0]));
Serial.print(buf);
Serial.println();
}

}

void cariJadwal()
{
uint16_t unixWaktu = (now.jam * 60) + now.menit;
byte hariKeDiTanggal1 = ((now.hari + 7 - (now.tanggal % 7)) % 7) + 1;
byte SeninKe = ((now.tanggal + ((hariKeDiTanggal1 + 4) % 7)) / 7); //senin pertama
byte mingguKe = ((now.tanggal + hariKeDiTanggal1 + 6 - 1) / 7);

Serial.print("SeninKe = ");
Serial.println(SeninKe);
Serial.print("mingguKe = ");
Serial.println(mingguKe);

uint16_t unixTerkecil = UINT16_MAX;
jadwalBerikutnyaKegiatan = 0;
Waktu waktuTerkecil;

for (byte i = 0; i < sizeof(jadwalBelajar) / sizeof(TabelMataPelajaran); i++)
{
if (
(jadwalBelajar[i].aktif) &&
(jadwalBelajar[i].hariAktif & (1 << (8 - now.hari))) &&
(jadwalBelajar[i].mingguAktif & (1 << (8 - mingguKe)))
)
{

//----------------------------------

//-------------------------------------

uint16_t unixJadwal = (jadwalBelajar[i].waktu.jam * 60) + jadwalBelajar[i].waktu.menit;
if (unixWaktu < unixJadwal) { if (unixTerkecil > unixJadwal)
{
unixTerkecil = unixJadwal;
jadwalBerikutnya.jam = jadwalBelajar[i].waktu.jam;
jadwalBerikutnya.menit = jadwalBelajar[i].waktu.menit;
jadwalBerikutnyaKegiatan = jadwalBelajar[i].kegiatan;
}
}
}
}
if (jadwalBerikutnyaKegiatan)
{
Serial.print("Bel berikutnya : ");
Serial.print((__FlashStringHelper *)kegiatanText[jadwalBerikutnyaKegiatan]);
Serial.print(" ");
Serial.print(jadwalBerikutnya.jam);
Serial.print(":");
Serial.println(jadwalBerikutnya.menit);

lcd.setCursor(1, 1);
sprintf(bufWaktu, "%02d:%02d", jadwalBerikutnya.jam, jadwalBerikutnya.menit);
lcd.print(bufWaktu);
}
else
{
lcd.setCursor(1, 1);
lcd.print("--:--");
}

}

Silahkan download file modul yang dibutuhkan

Dfplayer download

LCd L2C download

RTC download

Skets rangkaian gambar download

Aplikasi APK download

File Bell suara mp3 Otomatis download


 Lihat langkah pemasangan pada video di bawah ini 



Posting Komentar untuk "Arduino Control automatic alarm device from android app"