Advertisement
binho575

Sirene com arduino, LCD 16x2, DS1307 e Rele

Jun 12th, 2023
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. /*
  2. Firmware : Placa Disparo sirene fabrica
  3. Autoria : Fabio Oliveira
  4. Placa : FS-1.0
  5. Microchip : Arduino Nano
  6. Compilador : Arduino IDE 2.1.0
  7. Esquemático: FS-1.0
  8. Aplicação : Disparo de sirene com dias e horas programadas
  9. Revisões : 01) Projeto do Firmware - 07/06/23 | 16:14
  10. */
  11.  
  12. //Inclusao das bibliotecas
  13. #include <Wire.h>
  14. #include "RTClib.h"
  15. #include <LiquidCrystal_I2C.h>
  16.  
  17. LiquidCrystal_I2C lcd(0x27,16,2); //Inicializa LCD I2C com o endereço
  18.  
  19. const int PINO_RELE = 2; //pino definido para conexao com o rele
  20. int incomingByte;
  21. int DIA = 0; //Variavel de dia da semana
  22. int HORA = 0; //variavel de hora
  23. int MINUTO = 0; //variavel de minuto
  24. int SEGUNDOS = 0; //variavel de segundos
  25.  
  26. RTC_DS1307 rtc; //Objeto rtc da classe DS1307
  27.  
  28. char diasDaSemana[7][12] = {"Domingo", "Segunda", "Terca", "Quarta", "Quinta", "Sexta", "Sabado"}; //Dias da semana
  29.  
  30. void setup () {
  31.  
  32. lcd.init(); // Inicia o Display
  33. lcd.backlight(); // Inicia o Backlight
  34. Wire.begin();
  35. rtc.begin();
  36.  
  37.  
  38. lcd.begin(16, 2); //Defina tamanho do LCD
  39. Serial.begin(9600); //Inicializa serial
  40.  
  41. if (!rtc.begin()) { //Se o RTC nao for inicializado, faz
  42. lcd.println("RTC COM PROBLEMA"); //Imprime o texto
  43. while (1); //Trava o programa
  44. }
  45. //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Ajuste Automático da hora e data
  46. //rtc.adjust(DateTime(2023, 6, 09, 10, 53, 00)); //Ajusta o tempo do RTC para a data e hora definida pelo usuario.
  47. delay(100); //100 Milissegundos
  48.  
  49. pinMode(PINO_RELE, OUTPUT);
  50. digitalWrite(PINO_RELE, HIGH);
  51.  
  52. if (!rtc.isrunning()) {
  53. }
  54.  
  55. }
  56. /*void printnn(int n) {
  57. // imprime um numero com 2 digitos
  58. // acrescenta zero `a esquerda se necessario
  59. String digitos = String(n);
  60. if (digitos.length() == 1) {
  61. digitos = "0" + digitos;
  62. }
  63. lcd.print(digitos);
  64. }*/
  65.  
  66. void loop ()
  67. {
  68. DateTime agora = rtc.now(); // Faz a leitura de dados de data e hora
  69.  
  70. DIA = (agora.dayOfTheWeek());
  71. HORA = (agora.hour());
  72. MINUTO = (agora.minute());
  73. SEGUNDOS = (agora.second());
  74.  
  75. lcd.setCursor(0, 0); //Defina linha e coluna do LCD
  76. lcd.print(diasDaSemana[agora.dayOfTheWeek()]); //Imprime dia da semana
  77. //lcd.print(' '); //Imprime espaço
  78. lcd.print(' '); //Imprime espaço
  79. lcd.print(agora.day(), DEC); //Imprime dia
  80. lcd.print('/'); //Imprime barra
  81. lcd.print(agora.month(), DEC); //Imprime mes
  82. lcd.print('/'); //Imprime barra
  83. lcd.print(agora.year(), DEC); //Imprime ano
  84.  
  85. lcd.setCursor(0, 1); // Defina linha e coluna do LCD
  86. lcd.print("Horas "); //Imprime texto
  87. lcd.print(agora.hour(), DEC); //Imprime hora
  88. lcd.print(':'); //Imprime dois pontos
  89. lcd.print(agora.minute(), DEC); //Imprime os minutos
  90. lcd.print(':'); //Imprime dois pontos
  91. lcd.print(agora.second(), DEC); //Imprime os segundos
  92. delay(1000);
  93.  
  94.  
  95. // Periodo da manha
  96. if (DIA == 1,2,3,4,5 && HORA == 1 && MINUTO == 00 && SEGUNDOS == 0) {
  97. alarme();
  98. }
  99. if (DIA == 1,2,3,4,5 && HORA == 2 && MINUTO == 00 && SEGUNDOS == 0) {
  100. alarme();
  101. }
  102. if (DIA == 5 && HORA == 4 && MINUTO == 52 && SEGUNDOS == 0) {
  103. alarme();
  104. }
  105. if (DIA == 1,2,3,4,5 && HORA == 5 && MINUTO == 52 && SEGUNDOS == 0) {
  106. alarme();
  107. }
  108. if (DIA == 1,2,3,4,5 && HORA == 7 && MINUTO == 00 && SEGUNDOS == 00) {
  109. alarme();
  110. }
  111. if (DIA == 1,2,3,4,5 && HORA == 9 && MINUTO == 00 && SEGUNDOS == 00) {
  112. alarme();
  113. }
  114. if (DIA == 1,2,3,4,5 && HORA == 9 && MINUTO == 15 && SEGUNDOS == 20) {
  115. alarme();
  116. }
  117. if (DIA == 1,2,3,4,5 && HORA == 12 && MINUTO == 00 && SEGUNDOS == 0) {
  118. alarme();
  119. }
  120.  
  121. //periodo da tarde
  122. if (DIA == 1,2,3,4,5 && HORA == 13 && MINUTO == 00 && SEGUNDOS == 0) {
  123. alarme();
  124. }
  125. if (DIA == 5 && HORA == 16 && MINUTO == 00 && SEGUNDOS == 0) {
  126. alarme();
  127. }
  128. if (DIA == 1,2,3,4 && HORA == 17 && MINUTO == 00 && SEGUNDOS == 0) {
  129. alarme();
  130. }
  131. if (DIA == 1,2,3,4,5 && HORA == 18 && MINUTO == 00 && SEGUNDOS == 0) {
  132. alarme();
  133. }
  134. if (DIA == 1,2,3,4,5 && HORA == 21 && MINUTO == 00 && SEGUNDOS == 0) {
  135. alarme();
  136. }
  137. if (DIA == 1,2,3,4,5 && HORA == 23 && MINUTO == 00 && SEGUNDOS == 0) {
  138. alarme();
  139. }
  140. if (DIA == 1,2,3,4,5 && HORA == 23 && MINUTO == 15 && SEGUNDOS == 0) {
  141. alarme();
  142. }
  143.  
  144. }
  145. void alarme() {
  146. digitalWrite(PINO_RELE, LOW);
  147. lcd.clear();
  148. lcd.setCursor(1, 0);
  149. lcd.print ("PROGRAMACAO");
  150. lcd.setCursor(2, 1);
  151. lcd.print ("SIRENE");
  152. delay(7000);
  153. digitalWrite(PINO_RELE, HIGH);
  154. lcd.clear();
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement