Components and supplies
Grove - Buzzer - Piezo
Arduino uno
arduino uno
push buttons
16x2 LCD display with I²C interface
1 relay module 5 Vdc 10A (assembled)
High brightness LED red
LED Matrix Module 8x8
DS1307 RTC Module (2 pcs)
12V Power Supply
Tools and machines
Arduino IDE
Solder Soldering Wire
wires
The open-source Arduino Software (IDE)
Arduino UNO
Digital Multimeter
Apps and platforms
Arduino IDE
Project description
Code
Automatic School Bell
c
Automatic School Bell
1// constants won't change. They're used here to set pin numbers: 2const int ledPin = 7; // the number of the LED pin 3const int st = 2; // Setup for date and time setup 4const int up = 3; // increase the counter 5const int dn = 4; // decrease the counter 6const int bk = 5; // Back to the button 7int buttonState = 1; // variable for reading the pushbutton status 8const int buzzer = 9; //buzzer to arduino pin 8 9int count = 0; // variable for reading the pushbutton status 10int preset=0; 11int addr = 0; 12#include <Wire.h> 13#include <LiquidCrystal_I2C.h> 14int cnt=0; 15LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 16#include <I2C_RTC.h> 17#include <EEPROM.h> 18static DS1307 RTC; 19int bellcounter=0; 20const int RELAY_PIN = 8; 21 22#include "LedControl.h" 23/* 24 pin 12 is connected to the DataIn 25 pin 11 is connected to the CLK 26 pin 10 is connected to LOAD 27 28 */ 29LedControl lc=LedControl(12,11,10,1); 30const byte Matrix_font [35] [8]= { 31 {0x3c,0x7e,0x66,0x66,0x66,0x66,0x7e,0x3c}, //0 32 {0x08,0x18,0x38,0x78,0x18,0x18,0x7e,0x7e},//1 33 {0x3f,0x7f,0x63,0x66,0x0c,0x18,0x3f,0x7f},//2 34 {0x7e,0x7e,0x06,0x3e,0x3e,0x06,0x7e,0x7e},//3 35 {0x06,0x0e,0x1e,0x36,0x66,0xff,0xff,0x06},//4 36 {0x7e,0x7e,0x60,0x7e,0x7e,0x06,0x7e,0x7e},//5 37 {0x7e,0x7e,0x60,0x7e,0x7e,0x66,0x7e,0x7e},//6 38 {0xfe,0xfe,0xc6,0x06,0x06,0x06,0x06,0x06},//7 39 {0x7e,0x7e,0x66,0x7e,0x7e,0x66,0x7e,0x7e},//8 40 {0x3c,0x7e,0x66,0x7e,0x3e,0x06,0x7e,0x7c},//9 41 {0x26,0x69,0xa9,0x29,0x29,0x29,0x29,0xf6},//10 42 {0x22,0x66,0xaa,0x22,0x22,0x22,0x22,0xf7},//11 43 {0x46,0x49,0xc9,0x41,0x42,0x44,0x4c,0xef},//12 44 {0xdf,0xdf,0xc1,0xcf,0xcf,0xc1,0xdf,0xdf},//13 45 {0x00,0x82,0x86,0x8a,0x92,0xbf,0x82,0x00},//14 46 {0x00,0x5f,0x50,0x5f,0x41,0x41,0x5f,0x00},//15 47 {0x00,0x5f,0x50,0x5f,0x51,0x51,0x5f,0x00},//16 48 {0x00,0x5f,0x51,0x41,0x41,0x41,0x41,0x00},//17 49 {0x00,0x5f,0x51,0x51,0x5f,0x51,0x51,0x5f},//18 50 {0x00,0x5f,0x51,0x51,0x5f,0x41,0x41,0x5f},//19 51 {0x00,0xe6,0x19,0x19,0xe9,0x89,0xf7,0x00},//20 52 {0x00,0xfa,0x0a,0x0a,0xfa,0x82,0xfa,0x00},//21 53 {0x00,0xef,0x21,0x27,0xe8,0x88,0xef,0x00},//22 54 {0x00,0xef,0x21,0x27,0xe1,0x81,0xef,0x00},//23 55 {0x00,0xe9,0x29,0x29,0xef,0x81,0xe1,0x00},//24 56 {0xfc,0x42,0x42,0x42,0x7c,0x48,0x44,0x42},// Recess 57 {0xfc,0x42,0x42,0x42,0x7c,0x40,0x40,0x40},//Prayer 58 {0x3C,0x42,0xA5,0x81,0xA5,0x99,0x42,0x3C},//simle 59 {0x3C,0x42,0xA5,0x81,0xBD,0x81,0x42,0x3C},//netural 60 {0x3C,0x42,0xA5,0x81,0x99,0xA5,0x42,0x3C},//sad 61 {0x18,0x3C,0x7E,0xFF,0x18,0x18,0x18,0x18},//arrow up 62 {0x18,0x18,0x18,0x18,0xFF,0x7E,0x3C,0x18},//arrow down 63}; // end of MAX7219_Dot_Matrix_font 64void setup() 65{ 66 lcd.init(); // initialize the lcd 67 lcd.clear(); 68lcd.backlight(); 69lcd.noBlink(); 70lcd.setCursor(0,0); 71lcd.print("Welcome "); 72lcd.setCursor(0,1); 73lcd.print("balli education"); 74delay(1000); 75lcd.clear(); 76lcd.setCursor(0,0); 77lcd.print("School Bell"); 78lcd.setCursor(0,1); 79lcd.print("Automation"); 80delay(1000); 81Serial.begin(57600); 82pinMode(ledPin, OUTPUT); 83 // initialize the pushbutton pin as an input: 84 // pinMode(buttonPin, INPUT); 85 pinMode(st, INPUT); 86 pinMode(up, INPUT); 87 pinMode(dn, INPUT); 88 pinMode(bk, INPUT); 89 pinMode(buzzer, OUTPUT); 90 pinMode(RELAY_PIN, OUTPUT); 91digitalWrite(RELAY_PIN, HIGH); 92digitalWrite(st, HIGH); 93digitalWrite(up, HIGH); 94digitalWrite(dn, HIGH); 95digitalWrite(bk, HIGH); 96 RTC.begin(); 97// EEPROM.write(30, bellcounter); 98 Serial.println(); 99 Serial.println("*** RTC 1307 ***"); 100lcd.clear(); 101lcd.setCursor(0,0); 102lcd.print("Clock Running"); 103delay(1000); 104lcd.clear(); 105lcd.setCursor(0,0); 106lcd.print("Hour Mode : 24"); 107delay(1000); 108Serial.print("Is Clock Running : "); 109 110 111 if (! RTC.begin()) { 112 Serial.println("Couldn't find RTC"); 113 Serial.flush(); 114 while (1) delay(10); 115 } 116 117 118 119 if (RTC.isRunning()) 120 Serial.println("Yes"); 121 else 122 Serial.println("No. Time may be Inaccurate"); 123 Serial.print("Hour Mode : "); 124 if (RTC.getHourMode() == CLOCK_H24) 125 Serial.println("24 Hours"); 126 else 127 Serial.println("12 Hours"); 128 Serial.print("Is Out Pin Enabled : "); 129 if (RTC.isOutPinEnabled()) 130 Serial.println("Yes"); 131 else 132 Serial.println("No"); 133 134 Serial.print("Is SQWE Enabled : "); 135 if (RTC.isSqweEnabled()) 136 Serial.println("Yes"); 137 else 138 Serial.println("No"); 139// EEPROM.write(30, bellcounter); 140 141 142 143 bellcounter=0; 144 int value1 = EEPROM.read(0); 145 146int hours1[value1],minutes1[value1]; 147 int j=0,j1=0,val1; 148 Serial.println(""); 149 int val=value1*2; 150 for(int i=1;i<=val;i++) 151 { 152 if(i%2!=0) 153 { 154// Serial.print(i); 155// Serial.print(":"); 156 val1=EEPROM.read(i); 157 hours1[j]=val1; 158// Serial.print(val1); 159// Serial.println(""); 160 j=j+1; 161 } 162 if(i%2==0) 163 { 164// Serial.print(i); 165// Serial.print(":"); 166 val1=EEPROM.read(i); 167 minutes1[j1]=val1; 168// Serial.print(val1); 169// Serial.println(""); 170 j1=j1+1; 171 } 172 } 173 174 175 for(int i=0;i<value1;i++) 176{ 177 if(bellcounter<value1) 178 { 179 180 181 if(RTC.getHours()==hours1[i] && RTC.getMinutes() < minutes1[i]) 182 { 183// Serial.println(" "); 184// Serial.print(bellcounter); 185// Serial.print("-"); 186// Serial.print(rtc_h); 187// Serial.print(":"); 188// Serial.print(rtc_m); 189// Serial.println(" "); 190 break; 191 } 192 193 if(RTC.getHours()>hours1[i] || (RTC.getHours()==hours1[i] && RTC.getMinutes() > minutes1[i])) 194 { 195 bellcounter=bellcounter+1; 196// Serial.println(" "); 197// Serial.print(bellcounter); 198// Serial.print("-"); 199// Serial.print(rtc_h); 200// Serial.print(":"); 201// Serial.print(rtc_m); 202// Serial.println(" "); 203 204 } 205 206 } 207 } 208 if(bellcounter==value1) 209 { 210 bellcounter=0; 211 } 212 Serial.print(bellcounter); 213 digitalWrite(RELAY_PIN, HIGH); 214 noTone(buzzer); 215 216 217 218 lc.shutdown(0,false); 219 /* Set the brightness to a medium values */ 220 lc.setIntensity(0,8); 221 /* and clear the display */ 222 lc.clearDisplay(0); 223} 224 225 226 227 228 229int counterupdown(int mcount, int mncount) 230{ 231 // lcd.clear(); 232// // read the state of the pushbutton value: 233 buttonState = digitalRead(up); 234 235 if (buttonState == LOW && preset==0) 236 { 237 if(count<mcount) 238 { 239 count++; 240 } 241 //lcd.cursor(); 242 //lcd.blink(); 243 //lcd.setCursor(lcdcol,lcdrow); 244 // lcd.print(""); 245 // myStr = String(count); /*Convert Int to String*/ 246 //lcd.print(myStr); 247 248 //Serial.println(count); 249 250 digitalWrite(ledPin, LOW); 251 preset=1; 252 delay(200); 253 } 254 else 255 { 256 preset=0; 257 } 258 259 buttonState = digitalRead(dn); 260 if (buttonState == LOW && preset==0) 261 { 262 //lcd.clear(); 263 //Serial.print("Up Counter"); 264 if(count>mncount) 265 { 266 count--; 267 } 268 269 //Serial.println(count); 270 // lcd.cursor(); 271 //lcd.blink(); 272 //lcd.print(""); 273 //myStr = String(count); /*Convert Int to String*/ 274 //lcd.print(myStr); 275 //lcd.print(count); 276 digitalWrite(ledPin, LOW); 277 preset=1; 278 delay(200); 279 } 280 else 281 { 282 preset=0; 283 } 284 return count; 285} 286 287 288 289int noofperiodsSetup() 290{ 291 int noperiod=0; 292 int flag=0; 293 294 lcd.clear(); 295 lcd.backlight(); 296 lcd.blink(); 297 while(1) 298 { 299 lcd.setCursor(0,0); 300 lcd.print("Enter No.of Bells:"); 301 //lcd.setCursor(2,1); 302 cnt=counterupdown(24,1); 303 if(cnt<10) 304 { 305 lcd.setCursor(1,1); 306 lcd.print("0"); 307 lcd.setCursor(2,1); 308 } 309 else 310 { 311 lcd.setCursor(1,1); 312 } 313 314// Serial.print(cnt); 315 lcd.print(cnt); 316 buttonState = digitalRead(st); 317 if (buttonState == LOW && preset==0) 318 { 319 digitalWrite(ledPin, LOW); 320 noperiod=cnt; 321 //Serial.print(noperiod); 322 delay(200); 323 lcd.noBlink(); 324 //lcd.noBlink(); 325 //lcd.clear(); 326 // lcd.print("Enter Time"); 327 // while(1); 328 break; 329 } 330 else 331 { 332 preset=0; 333 digitalWrite(ledPin, HIGH); 334 } 335 336 } 337 338int size=noperiod; 339 EEPROM.write(addr, noperiod); 340 addr=addr+1; 341 int hours[size],minutes[size]; 342 cnt=0; 343 count=0; 344for(int i=0;i<size;i++) 345{ 346lcd.clear(); 347// //lcd.backlight(); 348lcd.blink(); 349lcd.setCursor(0,0); 350lcd.print(i); 351lcd.print(" Bell Time: "); 352lcd.setCursor(5,1); 353lcd.print("00"); 354lcd.setCursor(7,1); 355lcd.print(":"); 356lcd.setCursor(8,1); 357lcd.print("00"); 358 359 while(1) 360 { 361 cnt=0; 362 cnt=counterupdown(24,1); 363 if(cnt<10) 364 { 365 lcd.setCursor(5,1); 366 lcd.print("0"); 367 lcd.setCursor(6,1); 368 //lcd.setCursor(6,1); 369 //lcd.print("0"); 370 } 371 else 372 { 373 lcd.setCursor(5,1); 374 } 375 lcd.print(cnt); 376 buttonState = digitalRead(st); 377 if (buttonState == LOW && preset==0) 378 { 379// Serial.println("hours: "); 380//Serial.print(cnt); 381 382 hours[i]=cnt; 383 EEPROM.write(addr, cnt); 384 addr=addr+1; 385 digitalWrite(ledPin, LOW); 386 delay(200); 387 count=0; 388 break; 389 } 390 else 391 { 392 preset=0; 393 digitalWrite(ledPin, HIGH); 394 } 395 396 } 397 398 399 while(1) 400 { 401 cnt=0; 402// lcd.print("Enter No.of Bells:"); 403 // lcd.setCursor(8,1); 404 cnt=counterupdown(60,1); 405// // lcd.print(""); 406 // Serial.print(cnt); 407 if(cnt<10) 408 { 409 //lcd.setCursor(9,1); 410 lcd.setCursor(8,1); 411 lcd.print("0"); 412 lcd.setCursor(9,1); 413 } 414 else 415 { 416 lcd.setCursor(8,1); 417 } 418 lcd.print(cnt); 419 buttonState = digitalRead(st); 420 if (buttonState == LOW && preset==0) 421 { 422// hours=cnt; 423//Serial.println("Minute: "); 424//Serial.print(cnt); 425 minutes[i]=cnt; 426 EEPROM.write(addr, cnt); 427 addr=addr+1; 428 count=0; 429 digitalWrite(ledPin, LOW); 430 delay(200); 431 432 break; 433 } 434 else 435 { 436 preset=0; 437 digitalWrite(ledPin, HIGH); 438 } 439 440 } 441// Serial.println(i); 442// Serial.print(" Period "); 443// Serial.print(hours[size]); 444// Serial.print(":"); 445// Serial.print(minutes[size]); 446 447}//end of far loop 448 449//for(int i=0;i<size;i++) 450//{ 451// Serial.println(i); 452// Serial.print(" Period "); 453// Serial.print(hours[size]); 454// Serial.print(":"); 455// Serial.print(minutes[size]); 456// } 457 //while(1); 458 return noperiod; 459} 460 461void setDate() 462{ 463 RTC.begin(); 464 RTC.setHourMode(CLOCK_H24); 465 466 lcd.clear(); 467lcd.backlight(); 468lcd.blink(); 469lcd.setCursor(0,0); 470lcd.print("Set Current Date"); 471lcd.setCursor(2,1); 472lcd.print("00"); 473lcd.setCursor(4,1); 474lcd.print(":"); 475lcd.setCursor(5,1); 476lcd.print("00"); 477lcd.print(":"); 478lcd.setCursor(8,1); 479lcd.print("2023"); 480while(1) 481 { 482 cnt=0; 483 cnt=counterupdown(31,1); 484 if(cnt<10) 485 { 486 lcd.setCursor(2,1); 487 lcd.print("0"); 488 lcd.setCursor(3,1); 489 } 490 else 491 { 492 lcd.setCursor(2,1); 493 } 494 lcd.print(cnt); 495 buttonState = digitalRead(st); 496 if (buttonState == LOW && preset==0) 497 { 498 RTC.setDay(cnt); 499 500 //hours[i]=cnt; 501 digitalWrite(ledPin, LOW); 502 delay(200); 503 count=0; 504 break; 505 } 506 else 507 { 508 preset=0; 509 digitalWrite(ledPin, HIGH); 510 } 511 512 } 513 514while(1) 515 { 516 cnt=0; 517 cnt=counterupdown(12,1); 518 if(cnt<10) 519 { 520 lcd.setCursor(5,1); 521 lcd.print("0"); 522 lcd.setCursor(6,1); 523 } 524 else 525 { 526 lcd.setCursor(5,1); 527 } 528 lcd.print(cnt); 529 buttonState = digitalRead(st); 530 if (buttonState == LOW && preset==0) 531 { 532 RTC.setMonth(cnt); 533 534 //hours[i]=cnt; 535 digitalWrite(ledPin, LOW); 536 delay(200); 537 count=2022; 538 break; 539 } 540 else 541 { 542 preset=0; 543 digitalWrite(ledPin, HIGH); 544 } 545 546 } 547 lcd.setCursor(8,1); 548 lcd.print("2023"); 549 550 551 while(1) 552 { 553 cnt=counterupdown(2050,2023); 554 555 lcd.setCursor(8,1); 556 lcd.print(cnt); 557 buttonState = digitalRead(st); 558 if (buttonState == LOW && preset==0) 559 { 560 561 RTC.setYear(cnt); 562 //hours[i]=cnt; 563 digitalWrite(ledPin, LOW); 564 delay(200); 565 count=0; 566 break; 567 } 568 else 569 { 570 preset=0; 571 digitalWrite(ledPin, HIGH); 572 } 573 574 } 575} 576 577 578 579 580void setWeek() 581{ 582 lcd.clear(); 583// //lcd.backlight(); 584lcd.blink(); 585lcd.setCursor(0,0); 586lcd.print("Set Week"); 587lcd.setCursor(2,1); 588 RTC.begin(); 589 RTC.setHourMode(CLOCK_H24); 590 591while(1) 592 { 593 cnt=0; 594 cnt=counterupdown(7,1); 595 if(cnt<10) 596 { 597 lcd.setCursor(2,1); 598 lcd.print("0"); 599 lcd.setCursor(3,1); 600 } 601 else 602 { 603 lcd.setCursor(2,1); 604 } 605 lcd.print(cnt); 606 buttonState = digitalRead(st); 607 if (buttonState == LOW && preset==0) 608 { 609 RTC.setWeek(cnt); 610 //hours[i]=cnt; 611 digitalWrite(ledPin, LOW); 612 delay(200); 613 count=0; 614 break; 615 } 616 else 617 { 618 preset=0; 619 digitalWrite(ledPin, HIGH); 620 } 621 622 } 623 624} 625 626 627void setTime() 628{ 629lcd.clear(); 630lcd.backlight(); 631lcd.blink(); 632lcd.setCursor(0,0); 633RTC.begin(); 634RTC.setHourMode(CLOCK_H24); 635 636lcd.print("Set Current Time"); 637lcd.setCursor(2,1); 638lcd.print("00"); 639lcd.setCursor(4,1); 640lcd.print(":"); 641lcd.setCursor(5,1); 642lcd.print("00"); 643while(1) 644 { 645 cnt=0; 646 cnt=counterupdown(24,1); 647 if(cnt<10) 648 { 649 lcd.setCursor(2,1); 650 lcd.print("0"); 651 lcd.setCursor(3,1); 652 } 653 else 654 { 655 lcd.setCursor(2,1); 656 } 657 lcd.print(cnt); 658 buttonState = digitalRead(st); 659 if (buttonState == LOW && preset==0) 660 { 661 //hours[i]=cnt; 662 663 RTC.setHours(cnt); 664 665 666 digitalWrite(ledPin, LOW); 667 delay(200); 668 count=0; 669 break; 670 } 671 else 672 { 673 preset=0; 674 digitalWrite(ledPin, HIGH); 675 } 676 677 } 678 679while(1) 680 { 681 cnt=0; 682 cnt=counterupdown(60,1); 683 if(cnt<10) 684 { 685 lcd.setCursor(5,1); 686 lcd.print("0"); 687 lcd.setCursor(6,1); 688 } 689 else 690 { 691 lcd.setCursor(5,1); 692 } 693 lcd.print(cnt); 694 buttonState = digitalRead(st); 695 if (buttonState == LOW && preset==0) 696 { 697 RTC.setMinutes(cnt); 698 //hours[i]=cnt; 699 digitalWrite(ledPin, LOW); 700 delay(200); 701 count=0; 702 break; 703 } 704 else 705 { 706 preset=0; 707 digitalWrite(ledPin, HIGH); 708 } 709 710 } 711 712 RTC.setSeconds(00); 713} 714void RTC_Setup() 715{ 716lcd.clear(); 717//lcd.backlight(); 718lcd.blink(); 719lcd.setCursor(0,0); 720lcd.print(" RTC Setup"); 721lcd.setCursor(0,1); 722lcd.print("Date,Time,Week"); 723 delay(500); 724 lcd.clear(); 725setDate(); 726 delay(500); 727 lcd.clear(); 728setWeek(); 729 delay(500); 730 lcd.clear(); 731setTime(); 732 delay(500); 733 lcd.clear(); 734} 735 String StrFind() 736 { 737 String day; 738 switch (RTC.getWeek()) 739 { 740 case 1: 741 day="SUN"; 742 break; 743 case 2: 744 day="MON"; 745 break; 746 case 3: 747 day="TUE"; 748 break; 749 case 4: 750 day="WED"; 751 break; 752 case 5: 753 day="THU"; 754 break; 755 case 6: 756 day="FRI"; 757 break; 758 case 7: 759 day="SAT"; 760 break; 761 762 } 763 return day; 764 } 765void display() 766{ 767 768 769lcd.clear(); 770lcd.backlight(); 771lcd.noBlink(); 772lcd.setCursor(0,0); 773 774 lcd.print(StrFind()); 775 lcd.print(" "); 776 lcd.print(RTC.getDay()); 777 lcd.print("-"); 778 lcd.print(RTC.getMonth()); 779 lcd.print("-"); 780 lcd.print(RTC.getYear()); 781 lcd.setCursor(0,1); 782 lcd.print(RTC.getHours()); 783 lcd.print(":"); 784 lcd.print(RTC.getMinutes()); 785 lcd.print(":"); 786 lcd.print(RTC.getSeconds()); 787 Serial.print(" "); 788 Serial.print(StrFind()); 789 Serial.print(RTC.getDay()); 790 Serial.print("-"); 791 Serial.print(RTC.getMonth()); 792 Serial.print("-"); 793 Serial.print(RTC.getYear()); 794 795 Serial.print(" "); 796 797 Serial.print(RTC.getHours()); 798 Serial.print(":"); 799 Serial.print(RTC.getMinutes()); 800 Serial.print(":"); 801 Serial.print(RTC.getSeconds()); 802 if (RTC.getHourMode() == CLOCK_H12) 803 { 804 switch (RTC.getMeridiem()) 805 { 806 case HOUR_AM : 807 Serial.print(" AM"); 808 break; 809 case HOUR_PM : 810 Serial.print(" PM"); 811 break; 812 } 813 } 814 Serial.println(); 815 } 816 int a=0,value=0; 817 int value1=0; 818int bell_flag=0; 819void printByte(byte character []) { 820 821int i = 0; 822 for(i=0;i<8;i++) 823 { 824 lc.setRow(0,i,character[i]); 825 } 826 827} 828 829 830int noofbreaksetup() 831{ 832 int nobreak=0; 833 int flag=0; 834 835 lcd.clear(); 836 // lcd.backlight(); 837 lcd.blink(); 838 cnt=0; 839 while(1) 840 { 841 842 lcd.setCursor(0,0); 843 lcd.print("No.of Break:"); 844 //lcd.setCursor(2,1); 845 cnt=counterupdown(10,1); 846 if(cnt<10) 847 { 848 lcd.setCursor(1,1); 849 lcd.print("0"); 850 lcd.setCursor(2,1); 851 } 852 else 853 { 854 lcd.setCursor(1,1); 855 } 856 857// Serial.print(cnt); 858 lcd.print(cnt); 859 buttonState = digitalRead(st); 860 if (buttonState == LOW && preset==0) 861 { 862 digitalWrite(ledPin, LOW); 863 nobreak=cnt; 864 //Serial.print(noperiod); 865 delay(200); 866 lcd.noBlink(); 867 //lcd.noBlink(); 868 //lcd.clear(); 869 // lcd.print("Enter Time"); 870 // while(1); 871 break; 872 } 873 else 874 { 875 preset=0; 876 digitalWrite(ledPin, HIGH); 877 } 878 879 } 880 881 int size=nobreak; 882 addr=100; 883 EEPROM.write(addr, nobreak); 884 addr=addr+1; 885 Serial.println(""); 886 Serial.println("No of Break entered::"); 887 Serial.print(size); 888 delay(200); 889 int shours[size],sminutes[size],ehours[size],eminutes[size]; 890 cnt=0; 891 count=0; 892for(int i=0;i<size;i++) 893{ 894lcd.clear(); 895lcd.blink(); 896lcd.setCursor(0,0); 897lcd.print(i); 898lcd.print(" Start Bell Time: "); 899lcd.setCursor(5,1); 900lcd.print("00"); 901lcd.setCursor(7,1); 902lcd.print(":"); 903lcd.setCursor(8,1); 904lcd.print("00"); 905 906 while(1) 907 { 908 //cnt=0; 909 cnt=counterupdown(24,1); 910 if(cnt<10) 911 { 912 lcd.setCursor(5,1); 913 lcd.print("0"); 914 lcd.setCursor(6,1); 915 } 916 else 917 { 918 lcd.setCursor(5,1); 919 } 920 lcd.print(cnt); 921 buttonState = digitalRead(st); 922 if (buttonState == LOW && preset==0) 923 { 924 shours[i]=cnt; 925 EEPROM.write(addr, cnt); 926 addr=addr+1; 927 //Serial.println("loop Start Hours Time:"); 928 //Serial.print(shours[i]); 929 digitalWrite(ledPin, LOW); 930 delay(200); 931 count=0; 932 break; 933 } 934 else 935 { 936 preset=0; 937 digitalWrite(ledPin, HIGH); 938 } 939 940 } 941 cnt=0; 942 943 while(1) 944 { 945 //cnt=0; 946// lcd.print("Enter No.of Bells:"); 947 // lcd.setCursor(8,1); 948 cnt=counterupdown(60,1); 949// // lcd.print(""); 950 // Serial.print(cnt); 951 if(cnt<10) 952 { 953 lcd.setCursor(8,1); 954 lcd.print("0"); 955 lcd.setCursor(9,1); 956 } 957 else 958 { 959 lcd.setCursor(8,1); 960 } 961 lcd.print(cnt); 962 buttonState = digitalRead(st); 963 if (buttonState == LOW && preset==0) 964 { 965// hours=cnt; 966 //Serial.println("Start mintues Time:"); 967 //Serial.print(cnt); 968 sminutes[i]=cnt; 969 EEPROM.write(addr, cnt); 970 addr=addr+1; 971 count=0; 972 digitalWrite(ledPin, LOW); 973 delay(200); 974 975 break; 976 } 977 else 978 { 979 preset=0; 980 digitalWrite(ledPin, HIGH); 981 } 982 983 } 984 985// Serial.println(""); 986 // Serial.print(shours[0]); 987 // Serial.print(":"); 988 //Serial.print(sminutes[0]); 989 990/////////////////////////////////////////////// 991 //End of Recess Time 992 ///////////////////////////////// 993 994 lcd.clear(); 995lcd.blink(); 996lcd.setCursor(0,0); 997lcd.print(i); 998lcd.print(" End Bell Time: "); 999lcd.setCursor(5,1); 1000lcd.print("00"); 1001lcd.setCursor(7,1); 1002lcd.print(":"); 1003lcd.setCursor(8,1); 1004lcd.print("00"); 1005 1006 while(1) 1007 { 1008 //cnt=0; 1009 cnt=counterupdown(24,1); 1010 if(cnt<10) 1011 { 1012 lcd.setCursor(5,1); 1013 lcd.print("0"); 1014 lcd.setCursor(6,1); 1015 } 1016 else 1017 { 1018 lcd.setCursor(5,1); 1019 } 1020 lcd.print(cnt); 1021 buttonState = digitalRead(st); 1022 if (buttonState == LOW && preset==0) 1023 { 1024 ehours[i]=cnt; 1025 EEPROM.write(addr, cnt); 1026 addr=addr+1; 1027 digitalWrite(ledPin, LOW); 1028 delay(200); 1029 count=0; 1030 break; 1031 } 1032 else 1033 { 1034 preset=0; 1035 digitalWrite(ledPin, HIGH); 1036 } 1037 1038 } 1039 1040 1041 while(1) 1042 { 1043 //cnt=0; 1044// lcd.print("Enter No.of Bells:"); 1045 // lcd.setCursor(8,1); 1046 cnt=counterupdown(60,1); 1047// // lcd.print(""); 1048 // Serial.print(cnt); 1049 if(cnt<10) 1050 { 1051 lcd.setCursor(8,1); 1052 lcd.print("0"); 1053 lcd.setCursor(9,1); 1054 } 1055 else 1056 { 1057 lcd.setCursor(8,1); 1058 } 1059 lcd.print(cnt); 1060 buttonState = digitalRead(st); 1061 if (buttonState == LOW && preset==0) 1062 { 1063// hours=cnt; 1064 eminutes[i]=cnt; 1065 EEPROM.write(addr, cnt); 1066 addr=addr+1; 1067 count=0; 1068 digitalWrite(ledPin, LOW); 1069 delay(200); 1070 1071 break; 1072 } 1073 else 1074 { 1075 preset=0; 1076 digitalWrite(ledPin, HIGH); 1077 } 1078 } 1079 1080}//end of far loop 1081 //Serial.println(" "); 1082 //Serial.print(ehours[size]); 1083 //Serial.print(":"); 1084 //Serial.print(eminutes[size]); 1085for(int i=0;i<size;i++) 1086 { 1087 1088 Serial.println(" "); 1089 Serial.println(i); 1090 Serial.print("Break At "); 1091 Serial.print(" "); 1092 Serial.print(shours[i]); 1093 Serial.print(":"); 1094 Serial.print(sminutes[i]); 1095 Serial.print("->"); 1096 Serial.print(ehours[i]); 1097 Serial.print(":"); 1098 Serial.print(eminutes[i]); 1099} 1100 delay(200); 1101 1102} 1103 1104 1105 1106 1107 1108 1109 1110int compareTime( int sh, int sm, int eh, int em) 1111{ 1112 int stime,etime; /*New string is defined*/ 1113 int res=-2; 1114 stime = (String(sh)+String(sm)).toInt(); /*Convert Int to String*/ 1115 etime =(String(eh)+String(em)).toInt(); 1116 Serial.println("Stime:= "); 1117 Serial.println(stime); 1118 Serial.println("Etime "); 1119 Serial.println(etime); 1120Serial.println(" "); 1121 if(stime<etime) 1122 { 1123 res=-1; 1124 Serial.print("Stime less then end time"); 1125 } 1126 else if(stime>etime) 1127 { 1128 res=1; 1129 Serial.print("Stime greater then end time"); 1130 } 1131 else if(stime==etime) 1132 { 1133 res=0; 1134 Serial.print("Stime equal to end time"); 1135 1136 } 1137 else 1138 { 1139 res=2; 1140 Serial.print("time is not comparable"); 1141 1142 } 1143 1144 return res; 1145} 1146 1147int comparecurrentTime( int sh, int sm, int eh, int em) 1148{ 1149 int stime,etime,cptime; /*New string is defined*/ 1150 int res=-2; 1151 int ch=RTC.getHours(),cm=RTC.getMinutes(); 1152 if(sm<10) 1153 { 1154 stime = (String(sh)+String("0")+String(sm)).toInt(); /*Convert Int to String*/ 1155 } 1156 else 1157 { 1158 stime = (String(sh)+String(sm)).toInt(); /*Convert Int to String*/ 1159 } 1160 1161 if(em<10) 1162 { 1163 etime = (String(eh)+String("0")+String(em)).toInt(); /*Convert Int to String*/ 1164 } 1165 else 1166 { 1167 etime =(String(eh)+String(em)).toInt(); 1168 } 1169 if(cm<10) 1170 { 1171 cptime = (String(ch)+String("0")+String(cm)).toInt(); /*Convert Int to String*/ 1172 } 1173 else 1174 { 1175 cptime =(String(ch)+String(cm)).toInt(); 1176 } 1177 Serial.println("Stime:= "); 1178 Serial.println(stime); 1179 Serial.println("Etime "); 1180 Serial.println(etime); 1181 Serial.println("cptime "); 1182 Serial.println(cptime); 1183Serial.println(" "); 1184digitalWrite(RELAY_PIN, HIGH); 1185noTone(buzzer); 1186//if(sh==RTC.getHours() && sm<RTC.getMinutes() && RTC.getSeconds()<=60) 1187 if(stime==cptime && RTC.getSeconds()==00) 1188 { 1189 res=0; 1190 int bell=25; 1191 byte sd[8]={Matrix_font[bell][0],Matrix_font[bell][1],Matrix_font[bell][2],Matrix_font[bell][3],Matrix_font[bell][4],Matrix_font[bell][5],Matrix_font[bell][6],Matrix_font[bell][7]}; 1192 printByte(sd); 1193 lcd.clear(); 1194 lcd.setCursor(0,0); 1195 lcd.print("Break Start "); 1196 lcd.setCursor(0,1); 1197 lcd.print(RTC.getHours()); 1198 lcd.print(":"); 1199 lcd.print(RTC.getMinutes()); 1200 lcd.print(":"); 1201 lcd.print(RTC.getSeconds()); 1202 Serial.print("Break Start"); 1203 digitalWrite(RELAY_PIN, LOW);// REALY WILL ON ON LOW SIGNAL 1204 tone(buzzer, 1000); // Send 1KHz sound signal... 1205 delay(5000); 1206 digitalWrite(RELAY_PIN, HIGH); 1207noTone(buzzer); 1208////break; 1209 } 1210 else if(stime==cptime) 1211 { 1212 res=0; 1213 int bell=25; 1214 byte sd[8]={Matrix_font[bell][0],Matrix_font[bell][1],Matrix_font[bell][2],Matrix_font[bell][3],Matrix_font[bell][4],Matrix_font[bell][5],Matrix_font[bell][6],Matrix_font[bell][7]}; 1215 printByte(sd); 1216 lcd.clear(); 1217 lcd.setCursor(0,0); 1218 lcd.print("Break Start "); 1219 lcd.setCursor(0,1); 1220 lcd.print(RTC.getHours()); 1221 lcd.print(":"); 1222 lcd.print(RTC.getMinutes()); 1223 lcd.print(":"); 1224 lcd.print(RTC.getSeconds()); 1225 Serial.print("Break Start"); 1226 1227 } 1228 else if((stime<cptime)&&(cptime<etime) && RTC.getSeconds()<60) 1229 { 1230 res=1; 1231 int bell=25; 1232 byte sd[8]={Matrix_font[bell][0],Matrix_font[bell][1],Matrix_font[bell][2],Matrix_font[bell][3],Matrix_font[bell][4],Matrix_font[bell][5],Matrix_font[bell][6],Matrix_font[bell][7]}; 1233 printByte(sd); 1234 Serial.print("Break Time"); 1235 lcd.clear(); 1236 lcd.setCursor(0,0); 1237 lcd.print("Break Time "); 1238 lcd.setCursor(0,1); 1239 lcd.print(RTC.getHours()); 1240 lcd.print(":"); 1241 lcd.print(RTC.getMinutes()); 1242 lcd.print(":"); 1243 lcd.print(RTC.getSeconds()); 1244 1245 } 1246 else if(cptime==etime && RTC.getSeconds()==00) 1247 { 1248 res=-1; 1249 lcd.clear(); 1250 lcd.setCursor(0,0); 1251 lcd.print("Break End "); 1252 lcd.setCursor(0,1); 1253 lcd.print(RTC.getHours()); 1254 lcd.print(":"); 1255 lcd.print(RTC.getMinutes()); 1256 lcd.print(":"); 1257 lcd.print(RTC.getSeconds()); 1258 Serial.print("Break End Time"); 1259 digitalWrite(RELAY_PIN, LOW);// REALY WILL ON ON LOW SIGNAL 1260 tone(buzzer, 1000); // Send 1KHz sound signal... 1261 lc.clearDisplay(0); 1262 delay(5000); 1263 digitalWrite(RELAY_PIN, HIGH); 1264 noTone(buzzer); 1265 bellcounter=bellcounter+1; 1266 periodTime(); 1267 } 1268 else 1269 { 1270 res=2; 1271 periodTime(); 1272 } 1273 1274 return res; 1275} 1276void entertosetup() 1277{ 1278 int noofPeriods=0; 1279 int buttonState1=1, buttonState2=1, buttonState3=1; 1280 buttonState = digitalRead(st); 1281 buttonState1 = digitalRead(up); 1282 buttonState2 = digitalRead(dn); 1283 buttonState3 = digitalRead(bk); 1284 if (buttonState == LOW && buttonState1 == LOW) 1285 { 1286 RTC_Setup(); 1287 //delay(200); 1288 } 1289 if (buttonState == LOW && buttonState2 == LOW) 1290 { 1291 noofPeriods=noofperiodsSetup(); 1292 Serial.print(noofPeriods); 1293 //delay(200); 1294 } 1295 1296 if (buttonState1 == LOW && buttonState2 == LOW ) 1297 { 1298 noofbreaksetup(); 1299 1300 } 1301 } 1302int breakTimer() 1303{ 1304 // ////////////////////////////////////////////////////// 1305// ////////////////////////////////// Break Timer ////////////// 1306///////////////////////////////////////////////////////////////// 1307int spnt=100; 1308int value11 = EEPROM.read(spnt); 1309 Serial.println(value11); 1310 int shours[value11],sminutes[value11],ehours[value11],eminutes[value11]; 1311 int j=0; 1312 int j1=0,val1=0; 1313 int val2=0; 1314 Serial.println(""); 1315int val=value11*4; 1316Serial.println("================================"); 1317spnt=spnt+1; 1318for(int i=0;i<value11*4;i+=4) 1319 { 1320 Serial.println(" "); 1321 Serial.println(j); 1322 val1=EEPROM.read(spnt); 1323 spnt=spnt+1; 1324 shours[j]=val1; 1325 //j=j+1; 1326 1327 val1=EEPROM.read(spnt); 1328 spnt=spnt+1; 1329 sminutes[j]=val1; 1330 //j=j+1; 1331 1332 val1=EEPROM.read(spnt); 1333 spnt=spnt+1; 1334 ehours[j]=val1; 1335 //j=j+1; 1336 val1=EEPROM.read(spnt); 1337 spnt=spnt+1; 1338 eminutes[j]=val1; 1339 j=j+1; 1340 } 1341 1342 1343 1344 for(int i=0;i<value11;i++) 1345 { 1346 1347 Serial.println(" "); 1348 Serial.println(i); 1349 Serial.print("Break At "); 1350 Serial.print(" "); 1351 Serial.print(shours[i]); 1352 Serial.print(":"); 1353 Serial.print(sminutes[i]); 1354 Serial.print("->"); 1355 Serial.print(ehours[i]); 1356 Serial.print(":"); 1357 Serial.print(eminutes[i]); 1358} 1359// while(1); 1360 1361/////////////////////////////////////////////////////////////////// 1362////////////////////////////////////////Break Timer///////////////// 1363////////////////////////////////////////////////////////////////// 1364// 1365// 1366// 1367// 1368int result=0; 1369for(int i=0;i<value11;i++) 1370{ 1371 result=comparecurrentTime(shours[i],sminutes[i],ehours[i],eminutes[i]); 1372 Serial.println(" Result of comaprason:="); 1373 Serial.println(result); 1374 if(result==1) 1375 { 1376 break; 1377 } 1378} 1379 1380return result; 1381 } 1382 1383void periodTime() 1384{ 1385 // ////////////////////////////////////////////////////// 1386// ////////////////////////////////// Period Timer ////////////// 1387///////////////////////////////////////////////////////////////// 1388 value1 = EEPROM.read(0); 1389 Serial.println(value1); 1390 int hours1[value1],minutes1[value1]; 1391 int j=0,j1=0,val1,bell=0; 1392 Serial.println(""); 1393 int val=value1*2; 1394 for(int i=1;i<=val;i++) 1395 { 1396 if(i%2!=0) 1397 { 1398// Serial.print(i); 1399// Serial.print(":"); 1400 val1=EEPROM.read(i); 1401 hours1[j]=val1; 1402// Serial.print(val1); 1403// Serial.println(""); 1404 j=j+1; 1405 } 1406 if(i%2==0) 1407 { 1408// Serial.print(i); 1409// Serial.print(":"); 1410 val1=EEPROM.read(i); 1411 minutes1[j1]=val1; 1412// Serial.print(val1); 1413// Serial.println(""); 1414 j1=j1+1; 1415 } 1416 } 1417 //////////////////////////////////////// 1418 /////////////////////////////////// 1419 lcd.setCursor(14,0); 1420 lcd.print(bellcounter); 1421 lcd.setCursor(11,1); 1422 lcd.print(hours1[bellcounter]); 1423 lcd.print(":"); 1424 lcd.print(minutes1[bellcounter]); 1425 ///////////////////////////////////////////////////// 1426 ///////////////////////////////////////////////////// 1427 /////////////////////////////////////////////////// 1428 1429for(int i=0;i<value1;i++) 1430 { 1431 Serial.print(i); 1432 Serial.print(": "); 1433 Serial.print(hours1[i]); 1434 Serial.print(":"); 1435 Serial.print(minutes1[i]); 1436 Serial.print(":"); 1437 Serial.print(bellcounter); 1438 Serial.println(""); 1439 if(bellcounter==0) 1440 { 1441 bell=26; 1442 byte sd[8]={Matrix_font[bell][0],Matrix_font[bell][1],Matrix_font[bell][2],Matrix_font[bell][3],Matrix_font[bell][4],Matrix_font[bell][5],Matrix_font[bell][6],Matrix_font[bell][7]}; 1443 printByte(sd); 1444 //lcd.print("Prayer Over"); 1445 1446 } 1447 else 1448 { 1449 bell=bellcounter-1; 1450 // bell=bellcounter; 1451 byte sd[8]={Matrix_font[bell][0],Matrix_font[bell][1],Matrix_font[bell][2],Matrix_font[bell][3],Matrix_font[bell][4],Matrix_font[bell][5],Matrix_font[bell][6],Matrix_font[bell][7]}; 1452 printByte(sd); 1453 } 1454 1455 if(hours1[i]==RTC.getHours() && minutes1[i]==RTC.getMinutes() && RTC.getSeconds()==00) 1456 { 1457 Serial.print("Bell Over"); 1458 lcd.clear(); 1459 lcd.backlight(); 1460 lcd.setCursor(0,0); 1461 lcd.print(bell); 1462 lcd.print(" Bell Over"); 1463 digitalWrite(RELAY_PIN, LOW);// REALY WILL ON ON LOW SIGNAL 1464 tone(buzzer, 1000); // Send 1KHz sound signal... 1465 bellcounter=bellcounter+1; 1466 1467 1468 if(bellcounter>=value1) 1469 { 1470 bellcounter=0; 1471 } 1472 delay(5000); // ...for 1 sec 1473 1474 1475 1476 } 1477 digitalWrite(RELAY_PIN, HIGH); 1478 noTone(buzzer); 1479 } 1480 1481 //////////////////////////////////////////////// 1482 1483 1484 } 1485 1486void loop() 1487{ 1488entertosetup(); 1489display(); 1490breakTimer(); 1491 1492delay(1000); 1493}
Downloadable files
Automatic School Bell Prototype
Automatic School Bell Prototype
School_Bell_PushButton_Final_Backup.ino
Documentation
Automatic School Bell Prototype
Automatic School Bell Prototype
https://youtu.be/5Ok1kHcCCgk?si=AWLeMnSQJ-G_ZG74
Comments
Only logged in users can leave comments