Mikrokontroler ATmega328
Pin Analog 6
1
Arus DC tiap pin I/O 50 mA
Memori flash 32 KB
SRAM 2 KB
EEPROM 1 KB
Resistor
IDE Arduino
Buzzer
2
III. HASIL DAN ANALISIS
Tugas teori.
1. Fungsi dari module RTC
RTC (Real Time Clock) merupakan chip IC yang
mempunyai fungsi menghitung waktu yang dimulai dari
detik, menit, jam, hari, tanggal, bulan, hingga tahun
dengan akurat.
2. Fungsi potensiometer
- Sebagai pengatur Volume pada berbagai peralatan
Audio/Video seperti Amplifier, Tape Mobil, DVD
Player.
Potensiometer adalah resistor tiga terminal dengan - Sebagai Pengatur Tegangan pada Rangkaian Power
sambungan geser yang membentuk pembagi tegangan dapat Supply
disetel. Jika hanya dua terminal yang digunakan (salah satu - Sebagai Pembagi Tegangan
terminal tetap dan terminal geser), potensiometer - Aplikasi Switch TRIAC
berperan sebagai resistor variabel atau Rheostat. - Digunakan sebagai Joystick pada Tranduser
- Sebagai Pengendali Level Sinyal
4. Mengapa memakai IC
- Berukuran Kecil.
- Lebih Ringan.
- Harga lebih murah karena dapat diproduksi dalam
jumlah yang banyak dan serentak dalam 1 (satu) wafer.
- Lebih handal karena tidak memerlukan hubungan solder
Relay adalah suatu peranti yang bekerja berdasarkan dan interkoneksi yang sangat sedikit di dalam Internal
elektromagnetik untuk menggerakan sejumlah kontaktor yang komponen IC.
tersusun atau sebuah saklar elektronis yang dapat - Mengkonsumsi daya listrik yang lebih kecil, hal ini
dikendalikan dari rangkaian elektronik lainnya dengan dikarenakan ukuran IC yang kecil sehingga pemakaian
memanfaatkan tenaga listrik sebagai sumber energinya. Pada daya listrik pun lebih kecil.
void loop set buzzer HIGH artinya buzzer akan beroperasi - Lebih mudah diganti dan troubleshooting (perbaikan)
terlebih dahulu dengan mengeluarkan suara, lalu set led jika terjadi kerusakan pada rangkaian Elektronika.
sebagai HIGH, artinya led akan mengeluarkan cahaya setelah - Cocok untuk operasi sinyal rendah.
buzzer mengeluarkan suara, setelah itu beri waktu Dapat melakukan fungsi yang lebih kompleks dan
rumit.
5. Multiplexer
rangkaian logika yang menerima beberapa input data
digital dan menyeleksi salah satu dari input tersebut
3 pada saat tertentu, untuk dikeluarkan pada sisi output.
Demultiplexer #define NOTE_A5 880
rangkaian logika yang menerima satu input data dan #define NOTE_AS5 932
mendistribusikan input tersebut ke beberapa output #define NOTE_B5 988
yang tersedia. #define NOTE_C6 1047
#define NOTE_CS6 1109
Percobaan 1 : lagu supermario dengan buzzer dan LED #define NOTE_D6 1175
diatur volume oleh potensio. #define NOTE_DS6 1245
#define NOTE_B0 31 #define NOTE_E6 1319
#define NOTE_C1 33 #define NOTE_F6 1397
#define NOTE_CS1 35 #define NOTE_FS6 1480
#define NOTE_D1 37 #define NOTE_G6 1568
#define NOTE_DS1 39 #define NOTE_GS6 1661
#define NOTE_E1 41 #define NOTE_A6 1760
#define NOTE_F1 44 #define NOTE_AS6 1865
#define NOTE_FS1 46 #define NOTE_B6 1976
#define NOTE_G1 49 #define NOTE_C7 2093
#define NOTE_GS1 52 #define NOTE_CS7 2217
#define NOTE_A1 55 #define NOTE_D7 2349
#define NOTE_AS1 58 #define NOTE_DS7 2489
#define NOTE_B1 62 #define NOTE_E7 2637
#define NOTE_C2 65 #define NOTE_F7 2794
#define NOTE_CS2 69 #define NOTE_FS7 2960
#define NOTE_D2 73 #define NOTE_G7 3136
#define NOTE_DS2 78 #define NOTE_GS7 3322
#define NOTE_E2 82 #define NOTE_A7 3520
#define NOTE_F2 87 #define NOTE_AS7 3729
#define NOTE_FS2 93 #define NOTE_B7 3951
#define NOTE_G2 98 #define NOTE_C8 4186
#define NOTE_GS2 104 #define NOTE_CS8 4435
#define NOTE_A2 110 #define NOTE_D8 4699
#define NOTE_AS2 117 #define NOTE_DS8 4978
#define NOTE_B2 123
#define NOTE_C3 131 #define melodyPin 3
#define NOTE_CS3 139 //Mario main theme melody
#define NOTE_D3 147 int melody[] = {
#define NOTE_DS3 156 NOTE_E7, NOTE_E7, 0, NOTE_E7,
#define NOTE_E3 165 0, NOTE_C7, NOTE_E7, 0,
#define NOTE_F3 175 NOTE_G7, 0, 0, 0,
#define NOTE_FS3 185 NOTE_G6, 0, 0, 0,
#define NOTE_G3 196
#define NOTE_GS3 208 NOTE_C7, 0, 0, NOTE_G6,
#define NOTE_A3 220 0, 0, NOTE_E6, 0,
#define NOTE_AS3 233 0, NOTE_A6, 0, NOTE_B6,
#define NOTE_B3 247 0, NOTE_AS6, NOTE_A6, 0,
#define NOTE_C4 262
#define NOTE_CS4 277 NOTE_G6, NOTE_E7, NOTE_G7,
#define NOTE_D4 294 NOTE_A7, 0, NOTE_F7, NOTE_G7,
#define NOTE_DS4 311 0, NOTE_E7, 0, NOTE_C7,
#define NOTE_E4 330 NOTE_D7, NOTE_B6, 0, 0,
#define NOTE_F4 349
#define NOTE_FS4 370 NOTE_C7, 0, 0, NOTE_G6,
#define NOTE_G4 392 0, 0, NOTE_E6, 0,
#define NOTE_GS4 415 0, NOTE_A6, 0, NOTE_B6,
#define NOTE_A4 440 0, NOTE_AS6, NOTE_A6, 0,
#define NOTE_AS4 466
#define NOTE_B4 494 NOTE_G6, NOTE_E7, NOTE_G7,
#define NOTE_C5 523 NOTE_A7, 0, NOTE_F7, NOTE_G7,
#define NOTE_CS5 554 0, NOTE_E7, 0, NOTE_C7,
#define NOTE_D5 587 NOTE_D7, NOTE_B6, 0, 0
#define NOTE_DS5 622 };
#define NOTE_E5 659 //Mario main them tempo
#define NOTE_F5 698 int tempo[] = {
#define NOTE_FS5 740 12, 12, 12, 12,
#define NOTE_G5 784 12, 12, 12, 12,
#define NOTE_GS5 831 4 12, 12, 12, 12,
12, 12, 12, 12, 3, 3, 3
};
12, 12, 12, 12,
12, 12, 12, 12, void setup(void)
12, 12, 12, 12, {
12, 12, 12, 12, pinMode(3, OUTPUT);//buzzer
pinMode(5, OUTPUT);
9, 9, 9, pinMode(6, OUTPUT);
12, 12, 12, 12, pinMode(9, OUTPUT);
12, 12, 12, 12, pinMode(10, OUTPUT);
12, 12, 12, 12, pinMode(11, OUTPUT);//led indicator when singing a
note
12, 12, 12, 12, Serial.begin(9600);
12, 12, 12, 12, }
12, 12, 12, 12, int y;
12, 12, 12, 12, void loop()
{
9, 9, 9,
12, 12, 12, 12, //sing the tunes
12, 12, 12, 12, sing(1);
12, 12, 12, 12, sing(1);
}; sing(2);
//Underworld melody
int underworld_melody[] = { }
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, int song = 0;
NOTE_AS3, NOTE_AS4, 0, void sing(int s) {
0, // iterate over the notes of the melody:
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4, song = s;
NOTE_AS3, NOTE_AS4, 0, if (song == 2) {
0, //Serial.println(" 'Underworld Theme'");
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, int size = sizeof(underworld_melody) / sizeof(int);
NOTE_DS3, NOTE_DS4, 0, for (int thisNote = 0; thisNote < size; thisNote++) {
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4, // to calculate the note duration, take one second
NOTE_DS3, NOTE_DS4, 0, // divided by the note type.
0, NOTE_DS4, NOTE_CS4, NOTE_D4, //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
NOTE_CS4, NOTE_DS4, int noteDuration = 1000 / underworld_tempo[thisNote];
NOTE_DS4, NOTE_GS3,
NOTE_G3, NOTE_CS4, buzz(melodyPin, underworld_melody[thisNote],
NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, noteDuration);
NOTE_AS4, NOTE_A4,
NOTE_GS4, NOTE_DS4, NOTE_B3, // to distinguish the notes, set a minimum time between
NOTE_AS3, NOTE_A3, NOTE_GS3, them.
0, 0, 0 // the note's duration + 30% seems to work well:
}; int pauseBetweenNotes = noteDuration * 1.30;
//Underwolrd tempo delay(pauseBetweenNotes);
int underworld_tempo[] = {
12, 12, 12, 12, // stop the tone playing:
12, 12, 6, buzz(melodyPin, 0, noteDuration);
3, }
12, 12, 12, 12,
12, 12, 6, } else {
3,
12, 12, 12, 12, //Serial.println(" 'Mario Theme'");
12, 12, 6, int size = sizeof(melody) / sizeof(int);
3, for (int thisNote = 0; thisNote < size; thisNote++) {
12, 12, 12, 12,
12, 12, 6, // to calculate the note duration, take one second
6, 18, 18, 18, // divided by the note type.
6, 6, //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
6, 6, int noteDuration = 1000 / tempo[thisNote];
6, 6,
18, 18, 18, 18, 18, 18, buzz(melodyPin, melody[thisNote], noteDuration);
10, 10, 10,
10, 10, 10, 5 // to distinguish the notes, set a minimum time between
them. digitalWrite(10, HIGH);
// the note's duration + 30% seems to work well: digitalWrite(11, HIGH);
int pauseBetweenNotes = noteDuration * 1.30; delayMicroseconds(delayValue2);
delay(pauseBetweenNotes); }
else {
// stop the tone playing: digitalWrite(5, LOW);
buzz(melodyPin, 0, noteDuration); digitalWrite(6, LOW);
digitalWrite(9, LOW);
} digitalWrite(10, LOW);
} digitalWrite(11, LOW);
delayMicroseconds(delayValue2);
} }
for (long i = 0; i < numCycles; i++) { // for the calculated
void buzz(int targetPin, long frequency, long length) { length of time...
digitalWrite(13, HIGH); digitalWrite(targetPin, HIGH); // write the buzzer pin
y=map(analogRead(3), 250 , 400 , 0 ,255); high to push out the diaphram
Serial.println(y); delayMicroseconds(delayValue); // wait for the calculated
long delayValue = 1000000 / frequency / 2; // calculate delay value
the delay value between transitions digitalWrite(targetPin, LOW); // write the buzzer pin low
//// 1 second's worth of microseconds, divided by the to pull back the diaphram
frequency, then split in half since delayMicroseconds(delayValue); // wait again or the
//// there are two phases to each cycle calculated delay value111111111
long delayValue2 = 1000001 / frequency / 2;
long numCycles = frequency * length / 1000; // calculate }
the number of cycles for proper timing digitalWrite(13, LOW);
//// multiply frequency, which is really cycles per second, digitalWrite(5, LOW);
by the number of seconds to digitalWrite(6, LOW);
//// get the total number of cycles to produce digitalWrite(9, LOW);
if (y>=40 && y<130){ digitalWrite(10, LOW);
digitalWrite(5, HIGH); digitalWrite(11, LOW);
digitalWrite(6, LOW); delay(0.001);
digitalWrite(9, LOW); }
digitalWrite(10, LOW); Didapatkan hasil bahwa lagu supermario berhasil di
digitalWrite(11, LOW); munculkan dari buzzer dan di dampingi dengan kedipan LED.
delayMicroseconds(delayValue2); Sedangkan volume nya diatur oleh potensio.
}
else if(y>=130 && y<160){ Untuk dokumentasi pada percobaan pertama dapat dilihat di
digitalWrite(5, HIGH); : https://www.youtube.com/watch?v=MweRJrZzChc
digitalWrite(6, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW); Percobaan 2 : jam dan tanggal digital pada LCD 2x16 dan
digitalWrite(11, LOW); buzzer alarm
delayMicroseconds(delayValue2);
} //memanggil library header virtuabotixRTC
else if(y>=161 && y<190){ #include <virtuabotixRTC.h>
digitalWrite(5, HIGH); #include <Wire.h>
digitalWrite(6, HIGH); #include <LiquidCrystal_I2C.h>
digitalWrite(9, HIGH); int alarmJam = 22;
digitalWrite(10, LOW); int alarmMenit = 5;
digitalWrite(11, LOW); int alarmDetik = 0;
delayMicroseconds(delayValue2); int buzzer = 4;
} int timer = 0;
else if(y>=191 && y<220){
digitalWrite(5, HIGH); // Set the LCD address to 0x27 for a 16
digitalWrite(6, HIGH); chars and 2 line display
digitalWrite(9, HIGH); LiquidCrystal_I2C lcd(0x27, 16, 2);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delayMicroseconds(delayValue2);
//Inisialisasi pin (CLK, DAT, RST)
}
virtuabotixRTC myRTC(6,7,8);
else if(y>=220){
void setup(){
digitalWrite(5, HIGH);
digitalWrite(6, HIGH); //Inisialisasi port serial arduino dengan
digitalWrite(9, HIGH); 6komputer
Serial.begin(9600);
lcd.backlight(); Serial.print(":");
lcd.begin (); lcd.setCursor(5, 1); //baris pertama
pinMode(buzzer, OUTPUT); lcd.print(":");
//penulisan data pertama kali dan //fungsi penulisan data untuk detik
disarankan saat transfer Serial.println(myRTC.seconds);
//ke-2 ini tidak digunakan dikarenakan akan lcd.setCursor(6, 1); //baris pertama
menghapus data lcd.print(myRTC.seconds);
//sebelumnya if (alarmJam==myRTC.hours &&
myRTC.setDS1302Time(55,04,22,02,8,10,2019); alarmMenit==myRTC.minutes ){
//detik, menit, jam, hari dalam seminggu, if(timer<10){
tanggal, bulan, tahun digitalWrite(buzzer, HIGH);
// 00:59:23 "Rabu" 7-September-2017 timer= myRTC.seconds - alarmDetik;
} Serial.println(timer);
}
void loop(){ else{
//memanggil fungsi untuk update data waktu digitalWrite(buzzer, LOW);
myRTC.updateTime(); }
}
//penulisan data pada serial monitor else{
komputer digitalWrite(buzzer, LOW);
Serial.print("Current Date / Time: ");
//fungsi penulisan data untuk tanggal }
Serial.print(myRTC.dayofmonth); delay( 1000);
lcd.setCursor(0, 0); //baris pertama
lcd.print(myRTC.dayofmonth); }
//penulisan data "/" sebagai separator Didapatkan hasil bahwa waktu tampil dan berbunyi setelah
Serial.print("/"); mencapai waktu alarm.
lcd.setCursor(2, 0); //baris pertama
lcd.print("/"); Untuk dokumentasi pada percobaan pertama dapat dilihat di
: https://youtu.be/JzwaCXVb_g8
//fungsi penulisan data untuk bulan
Serial.print(myRTC.month);
lcd.setCursor(3, 0); //baris pertama
I. KESIMPULAN
lcd.print(myRTC.month);
Pada tugas praktikum ketiga praktikan berhasil
//penulisan data "/" sebagai separator menyelesaikan pembuatan lagu super mario dari buzzer dan
Serial.print("/"); ditampilkan getarannya di LED sedangkan untuk volume diatur
lcd.setCursor(5, 0); //baris pertama dari potensio.
lcd.print("/");
REFERENSI
//fungsi penulisan data untuk tahun
Serial.print(myRTC.year);
lcd.setCursor(6, 0); //baris pertama [1] Sutanto, Dimas. dkk, Modul Praktikum IF3124 Sistem Tertanam,
lcd.print(myRTC.year); Institut Teknologi Sumatera, V1.0, 2019.
Serial.print(":");
lcd.setCursor(2, 1); //baris pertama
lcd.print(":");