Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
403 views

Flowchart Arduino

This document provides code for an Arduino program that uses a DS1302 RTC module to control LEDs based on the time. It defines pin connections for 4 LEDs and the RTC module. The setup function initializes the LED pins and RTC module. The loop function reads the time from the RTC, and if it matches a specific time, it will turn the LEDs on and off sequentially with delays. It also prints the current time and date to the serial monitor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
403 views

Flowchart Arduino

This document provides code for an Arduino program that uses a DS1302 RTC module to control LEDs based on the time. It defines pin connections for 4 LEDs and the RTC module. The setup function initializes the LED pins and RTC module. The loop function reads the time from the RTC, and if it matches a specific time, it will turn the LEDs on and off sequentially with delays. It also prints the current time and date to the serial monitor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

FLOWCHART ARDUINO

PROGRAM ARDUINO
#include <Time.h>
#include <DS1302RTC.h>
int led1 = 2; // pinout 2, dengan id 'led1'
int led2 = 3; // pinout 3, dengan id 'led2'
int led3 = 4; // pinout 4, dengan id 'led3'
int led4 = 5; // pinout 5, dengan id 'led4'
// Set pins: CE, IO,CLK
DS1302RTC RTC(8,7,6);
// Optional connection for RTC module
#define DS1302_GND_PIN 33
#define DS1302_VCC_PIN 35
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
digitalWrite(DS1302_GND_PIN, LOW);
pinMode(DS1302_GND_PIN, OUTPUT);
digitalWrite(DS1302_VCC_PIN, HIGH);
pinMode(DS1302_VCC_PIN, OUTPUT);
}

void print2digits(int number) {


if (number >= 0 && number < 10)
Serial.write('0');
Serial.print(number);}
void loop() {
tmElements_t tm; // membaca elemen waktu
RTC.read(tm); // mengambil data dari RTC DS1302
// if else digunakan untuk apabila kondisi sesuai maka jalankan
// perintah 1, apabila kondisi tidak sesuai jalankan perintah 2
if (tm.Hour==22 && tm.Minute==30 && tm.Second==20){ // ganti angka disamping untuk set
alarm
digitalWrite(led1, LOW);
delay(8000); // durasi perintah dilaksanakan (1000 = 1 detik)
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(8000); // durasi perintah dilaksanakan (1000 = 1 detik)
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(8000); // durasi perintah dilaksanakan (1000 = 1 detik)
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
delay(8000); // durasi perintah dilaksanakan (1000 = 1 detik)
digitalWrite(led4, HIGH);
}else{
digitalWrite(led1, HIGH); // menonaktifkan
digitalWrite(led2, HIGH); // menonaktifkan
digitalWrite(led3, HIGH); // menonaktifkan
digitalWrite(led4, HIGH); // menonaktifkan
}

// mengirim data ke serial


Serial.print("UNIX Time: ");
Serial.print(RTC.get());
if (! RTC.read(tm)) {
Serial.print(" Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.print(", DoW = ");
Serial.print(tm.Wday);
Serial.println();
} else {
Serial.println("DS1302 read error! Please check the circuitry.");
Serial.println();
delay(1000);
}
digitalWrite(led3, HIGH); // untuk mematikan pinout4 karena ketika kondisi normal pin4
digunakan untuk membaca SD card
// Wait one second before repeating :)
delay (1000);
}

You might also like