Aplikasi PC dibuat menggunakan Borland Delphi 10.1 Seattle dengan tambahan Komponen TMS Component Pack - TMS Software dan Comport.
Project ini bisa mengendalikan 16 alarm dan sekaligus menyalakan 16 relay yang terhubung dengan rangkaian.
Berikut aplikasi yang dijalankan di PC
Alarm/ Relay akan aktif bila berada diantara Waktu Mulai dan Selesai
Software alarm bisa diunduh di sini Control LED
Ketika pertandingan nilai-nilai yang tersimpan dan nilai saat ini sama, bel alarm akan dipicu. Dalam rangka untuk menghentikan alarm, tombol NEXT ditekan.
Alat dan Bahan yang dibutuhkan :
· 1x Arduino Pro Mini (Compatible)
· 1x LCD 16x2
· 1x Potensiometer 10K Ohm
· 3 x Tombol Push Button
· 1x Tiny RTC DS1307 modul
· 2x 74HC595
· 16x Led 3mm
· 16x Resistor 470 ohm
· Kabel jumper secukupnya
Rangkaian :
Susunlah rangkaian seperti gambar dibawah ini
Copy Paste dan Upload Sketch
#include <Wire.h> #include <EEPROM.h> #include "RTClib.h" #include <LiquidCrystal.h> LiquidCrystal lcd(2, 3, 4, 5, 6, 7); RTC_DS1307 RTC; int NilaiJam, Nilai, Nilai2, NilaiLampuPertama, NilaiLampuKedua, NilaiLampu2, lokasi, hari, bulan, tahun, Jam,Menit,Detik; int mode = 100; //Pin connected to ST_CP of 74HC595 int latchPin = 13; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; void JamLCD () { DateTime now = RTC.now(); if (now.hour() < 10) Serial.print('0'); Serial.print(now.hour()); Serial.print(':'); if (now.minute() < 10) Serial.print('0'); Serial.print(now.minute()); Serial.print(':'); if (now.second() < 10) Serial.print('0'); Serial.print(now.second()); Serial.println(); NilaiJam=now.hour()*60+now.minute(); NilaiLampuPertama = 0; NilaiLampu2 = 1; for (int i=1; i <= 8; i++){ if (i == 1){NilaiLampu2 = 1;} else {NilaiLampu2 = NilaiLampu2 *2;} Nilai = EEPROM.read((6*i)-6)*60+EEPROM.read((6*i)-5); Nilai2 = EEPROM.read((6*i)-3)*60+EEPROM.read((6*i)-2); if (Nilai <= NilaiJam && Nilai2 > NilaiJam){ NilaiLampuPertama = NilaiLampuPertama+NilaiLampu2;} } //for NilaiLampuKedua = 0; NilaiLampu2 = 1; for (int i=9; i <= 16; i++){ if (i == 9){NilaiLampu2 = 1;} else {NilaiLampu2 = NilaiLampu2 *2;} Nilai = EEPROM.read((6*i)-6)*60+EEPROM.read((6*i)-5); Nilai2 = EEPROM.read((6*i)-3)*60+EEPROM.read((6*i)-2); if (Nilai <= NilaiJam && Nilai2 > NilaiJam){ NilaiLampuKedua = NilaiLampuKedua+NilaiLampu2;} } //for digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, NilaiLampuPertama); shiftOut(dataPin, clockPin, MSBFIRST, NilaiLampuKedua); digitalWrite(latchPin, HIGH); } void setup () { Serial.begin(9600); Wire.begin(); //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); RTC.begin(); // Check to see if the RTC is keeping time. If it is, load the time from your computer. lcd.begin(16,2); lcd.clear(); lcd.setCursor(0,0); lcd.print("TIMER SMKN 2 MLG"); lcd.setCursor(0,1); lcd.print(" Alarm Clock "); delay(2000); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // This will reflect the time that your sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } } void loop () { if (Serial.available()) { String perintah = Serial.readString(); Serial.println(perintah); lcd.setCursor(0,0); //lcd.print(perintah); if (perintah == "seting"){mode =2;} if (perintah == "setup"){mode=1;} if (perintah == "ambil"){mode=0;} } DateTime now = RTC.now(); if (mode == 2){ Serial.println("Waktu Jam! "); //Prompt User for input while (Serial.available()==0) { } Jam=Serial.parseInt(); //lcd.print(Jam); Serial.println("Waktu Menit! "); //Prompt User for input while (Serial.available()==0) { } Menit=Serial.parseInt(); //lcd.print(Menit); Serial.println("Waktu Detik! "); //Prompt User for input while (Serial.available()==0) { } Detik=Serial.parseInt(); //lcd.print(Detik); Serial.println("Waktu hari! "); //Prompt User for input while (Serial.available()==0) { } hari=Serial.parseInt(); //lcd.print(hari); Serial.println("Waktu bulan! "); //Prompt User for input while (Serial.available()==0) { } bulan=Serial.parseInt(); //lcd.print(bulan); Serial.println("Waktu tahun! "); //Prompt User for input while (Serial.available()==0) { } tahun=Serial.parseInt(); //lcd.print(tahun); //rtc.adjust(DateTime(2014, 1, 21, 3, 13, 12)); RTC.adjust(DateTime(tahun, bulan, hari, Jam, Menit, Detik)); //lcd.print("ok"); mode=0; } if (mode == 1){ Serial.println("Tentukan Lokasi Alarm! "); //Prompt User for input while (Serial.available()==0) { } lokasi=Serial.parseInt(); Serial.println("Tentukan Jam! "); //Prompt User for input while (Serial.available()==0) { } Jam=Serial.parseInt(); Serial.println("Tentukan Menit! "); //Prompt User for input while (Serial.available()==0) { } Menit=Serial.parseInt(); Serial.println("Tentukan Detik! "); //Prompt User for input while (Serial.available()==0) { } Detik=Serial.parseInt(); Serial.print("Alarm lokasi ke"); Serial.println(lokasi); Serial.print("JamMulai "); //Print out nicely formatted output. Serial.print(Jam); Serial.print(":"); Serial.print(Menit); Serial.print(":"); Serial.println(Detik); EEPROM.update(lokasi*3-3, Jam); EEPROM.update(lokasi*3-2, Menit); EEPROM.update(lokasi*3-1, Detik); mode=0; } if (mode == 0){ Serial.write("bersih"); // kirim string/text Serial.println(); // jam sekarang Serial.print('0'); Serial.print('-'); JamLCD(); // Waktu 1 Mulai for (int i=1; i <= 32; i++){ //analogWrite(PWMpin, i); //delay(10); Serial.print(i); Serial.print('-'); //jam if (EEPROM.read((3*i)-3) > 23) Nilai = 0; else Nilai =EEPROM.read((3*i)-3); if (Nilai < 10) Serial.print('0'); Serial.print(Nilai); Serial.print(':'); //menit if (EEPROM.read((3*i)-2) > 59) Nilai = 0; else Nilai =EEPROM.read((3*i)-2); if (Nilai < 10) Serial.print('0'); Serial.print(Nilai); Serial.print(':'); //detik if (EEPROM.read((3*i)-1) > 59) Nilai = 0; else Nilai =EEPROM.read((3*i)-1); if (Nilai < 10) Serial.print('0'); Serial.print(Nilai); Serial.println(); } //for mode=100; } //if JamLCD(); lcd.setCursor(0,1); lcd.print("Jam = "); if (now.hour() < 10) lcd.print('0'); lcd.print(now.hour()); lcd.print(":"); if (now.minute() < 10) lcd.print('0'); lcd.print(now.minute()); lcd.print(":"); if (now.second() < 10) lcd.print('0'); lcd.print(now.second()); delay(1000); }
Tidak ada komentar:
Posting Komentar