Advertisement
Guest User

timer - using tiny RTC to switch on a relay

a guest
Jul 9th, 2014
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3. #include <LiquidCrystal.h>
  4. #include <Time.h>
  5. #include <TimeAlarms.h>
  6.  
  7. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // for LCD
  8. RTC_DS1307 RTC; // for clock
  9.  
  10. void setup () {
  11. Wire.begin(); // for clock
  12. RTC.begin(); // for clock
  13. lcd.begin(20, 4); // for LCD
  14. pinMode(9, OUTPUT); // Set Pin 9 to Output
  15.  
  16. Alarm.alarmRepeat(8,30,0, MorningAlarm); // 8:30am every day
  17. Alarm.alarmRepeat(17,45,0, EveAlarm); // 5:45pm every day
  18. }
  19.  
  20. void loop () {
  21.  
  22. DateTime now = RTC.now(); // for time diplay to LCD
  23.  
  24. lcd.setCursor(0, 0); // following lines display time on LCD
  25. lcd.print(now.year(), DEC);
  26. lcd.print('/');
  27. lcd.print(now.month(), DEC);
  28. lcd.print('/');
  29. lcd.print(now.day(), DEC);
  30. lcd.setCursor(0, 1);
  31. lcd.print(now.hour(), DEC);
  32. lcd.print(':');
  33. if ( now.minute() < 10) {
  34. lcd.print("0");
  35. }
  36. lcd.print(now.minute(), DEC);
  37. lcd.print(':');
  38. if ( now.second() < 10) {
  39. lcd.print("0");
  40. }
  41. lcd.print(now.second(), DEC);
  42.  
  43. }
  44. void MorningAlarm(){
  45. digitalWrite(9, HIGH); // should turn on pin 9
  46. }
  47.  
  48. void EveAlarm(){
  49. digitalWrite(9, LOW); // should turn off pin 9
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement