Arduino Tutorial #25 How to make Arduino Alarm Clock.

Описание к видео Arduino Tutorial #25 How to make Arduino Alarm Clock.

Arduino Tutorial #25 Arduino Alarm Clock.
Scroll down for code.....
Please like & Subscribe for more videos

LiquidCrystal_I2C library Github link
https://github.com/fdebrabander/Ardui...

Real Time Clock (DS1302) library
http://www.rinkydinkelectronics.com/l...

If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.

LIST OF COMPONENT (affiliate links)

http://amzn.to/2fvSRJq (Arduino)
http://amzn.to/2gRFSiv (RTC DS1302)
http://amzn.to/2zg8aeX (I2C)
http://amzn.to/2yBk7eT (LCD display)
http://amzn.to/2uKfEDf (Piezo buzzer)
http://amzn.to/2vn4IyP (Push button)
http://amzn.to/2vmSK8l (Resistor)
http://amzn.to/2wxPmWz (Breadboard)
http://amzn.to/2vJ3lvo (Jumper wire)

#include (Wire.h) //instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
#include (LiquidCrystal_I2C.h)

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include (DS1302.h)
int Hour;
int Min;
int pset = 8; // pushbutton for setting alarm
int phour = 9; // pushbutton for hour
int pmin = 10; // pushbutton for minutes
int pexit = 11; // pushbutton for exit of set alarm
int buzzer = 6;
int h;
int m;
int buttonforset = 0; // pushbutton state for setting alarm
int buttonforhour = 0; // pushbutton state for hour
int buttonformin = 0;// pushbutton state for minutes
int buttonforexit = 0; // pushbutton state for exit of set alarm
int activate=0;
Time t;

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
pinMode(pset, INPUT);
pinMode(phour, INPUT);
pinMode(pmin, INPUT);
pinMode(pexit, INPUT);
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup LCD to 16x2 characters
lcd.begin();

// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(SATURDAY); // Set Day-of-Week to FRIDAY
//rtc.setTime(10, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(11, 11, 2017); // Set the date to August 6th, 2010
}

void loop()
{
if (activate == 0) {

// Display time on the right conrner upper line
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.setCursor(6, 0);
lcd.print(rtc.getTimeStr());

// Display abbreviated Day-of-Week in the lower left corner
//lcd.setCursor(0, 1);
//lcd.print(rtc.getDOWStr(FORMAT_SHORT));

// Display date in the lower right corner
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
buttonforset = digitalRead(pset);
} // setting button pressed
if (buttonforset == HIGH) {
activate =1;
lcd.clear(); }
while(activate== 1){
lcd.setCursor(0,0);
lcd.print("Set Alarm");
lcd.setCursor(0,1);
lcd.print("Hour= ");
lcd.setCursor(9,1);
lcd.print("Min= ");
buttonforhour = digitalRead(phour); // set hour for alarm
if (buttonforhour == HIGH){
h++;
lcd.setCursor(5,1);
lcd.print(h);
if (h)23){
h=0;
lcd.clear(); }
delay(100);
}
buttonformin = digitalRead(pmin); // set minutes for alarm
if (buttonformin == HIGH){
m++;
lcd.setCursor(13,1);
lcd.print(m);
if (m)59){
m=0;
lcd.clear();}
delay(100);
}

lcd.setCursor(5,1);
lcd.print(h);
lcd.setCursor(13,1);
lcd.print(m);
buttonforexit = digitalRead(pexit); // exit from set alarm mode
if (buttonforexit == HIGH){
activate = 0;
lcd.clear();
}
}

if (Hour== h && Min== m) {
tone(6,400,300);}
delay (500);
}

Комментарии

Информация по комментариям в разработке