Arduino Combination Safe
Rotate the potentiometers in the correct sequence to access system!
Components and supplies
4
Resistor 1k ohm
4
LED, Green
1
I2C 16x2 Arduino LCD Display Module
1
Buzzer
1
Jumper wires (generic)
4
Rotary potentiometer (generic)
1
Breadboard (generic)
1
Tactile Switch, Top Actuated
1
Arduino UNO
1
Resistor 220 ohm
Apps and platforms
1
Arduino IDE
Project description
Code
Repository link:
Code:
arduino
1/* Arduino 'Combination Safe' concept 2 3 Components: 4 - Arduino Uno 5 - Green LED (x 4) 6 - 10KOhm potentiometer (x 4) 7 - 1kOhm resistor (x 4) 8 - 220Ohm resistor 9 - LCD I2C (20x4) 10 - Passive Buzzer 11 - Push button tactile switch 12 - Some jumper wires 13 14 Libraries: 15 - LiquidCrystal_I2C library 16 17 Created on 29 June 2022 by c010rblind3ngineer 18*/ 19 20#include <LiquidCrystal_I2C.h> 21 22int pot1, pot2, pot3, pot4; 23const int buzzer = 9; 24const int buttonPin = 2; 25 26//////////////////////////////////////////////////////////////////////////////// 27// LEDs are for visual indication of the correct input password, // 28// for future project you could put numeric indicators on each potentiometer. // 29//////////////////////////////////////////////////////////////////////////////// 30const int D1_LED = 7; 31const int D2_LED = 6; 32const int D3_LED = 5; 33const int D4_LED = 4; 34 35unsigned long firstDigitTime; 36unsigned long lastDigitTime; 37 38int timeLimit = 8000; // time limit for User to input combination 39int i = 0; 40int t = 0; 41int load = 0; 42 43int line; 44int count; 45 46int password[5] = {1, 2, 3, 4}; // set your own password here... 47 48byte loadingBar[] = { 49 B11111, 50 B11111, 51 B11111, 52 B11111, 53 B11111, 54 B11111, 55 B11111, 56 B11111, 57}; 58 59LiquidCrystal_I2C lcd(0x27, 20, 4); 60 61void setup() { 62 Serial.begin(9600); 63 pinMode(D1_LED, OUTPUT); 64 pinMode(D2_LED, OUTPUT); 65 pinMode(D3_LED, OUTPUT); 66 pinMode(D4_LED, OUTPUT); 67 pinMode(buttonPin, INPUT); 68 69 lcd.init(); 70 lcd.createChar(0, loadingBar); 71} 72 73void loop() { 74 ////////////////////////////////////////////////////////////// 75 // There are 3 sets of 'Combination' functions: // 76 // Combination_original() ---->> pot#1, pot#2, pot#3, pot#4 // 77 // Combination_one() ---->> pot#1, pot#3, pot#2, pot#4 // 78 // Combination_two() ---->> pot#4, pot#3, pot#2, pot#1 // 79 ////////////////////////////////////////////////////////////// 80 for (count = 0; count < 3;) { 81 if (count == 0) { 82 while (load < 1) { 83 safeInit(); 84 load = 1; 85 } 86 Combination_original(); 87 } 88 if (count == 1) { 89 while (load < 1) { 90 lcd.clear(); 91 lcd.print("Press button once..."); 92 while (digitalRead(buttonPin) != HIGH) {} 93 if (digitalRead(buttonPin) == HIGH) { 94 i = 0; 95 t = 0; 96 } 97 delay(100); 98 safeInit(); 99 load = 1; 100 } 101 Combination_one(); 102 } 103 if (count == 2) { 104 while (load < 1) { 105 lcd.clear(); 106 lcd.print("Press button once..."); 107 while (digitalRead(buttonPin) != HIGH) {} 108 if (digitalRead(buttonPin) == HIGH) { 109 i = 0; 110 t = 0; 111 } 112 delay(100); 113 safeInit(); 114 load = 1; 115 } 116 Combination_two(); 117 } 118 } 119 // if User fail to input combination within time limit for ALL tries, shutdown system... 120 delay(3000); 121 lcd.clear(); 122 lcd.setCursor(0, 1); 123 lcd.print(" Goodbye. "); 124 delay(1000); 125 tone(buzzer, 2000); 126 delay(100); 127 noTone(buzzer); 128 delay(50); 129 tone(buzzer, 2000); 130 delay(100); 131 noTone(buzzer); 132 delay(50); 133 lcd.clear(); 134 lcd.noBacklight(); 135} 136 137// Initialization & Loading screen 138void safeInit() { 139 lcd.backlight(); 140 lcd.setCursor(0, 0); 141 lcd.print(" Arduino "); 142 lcd.setCursor(0, 1); 143 lcd.print(" Combination Safe "); 144 delay(5000); 145 lcd.clear(); 146 lcd.print(" Loading... "); 147 delay(1000); 148 lcd.setCursor(0, 1); 149 for (line = 0; line < 20; line++) { 150 lcd.write(0); 151 delay(200); 152 } 153 delay(250); 154 tone(buzzer, 2000); 155 delay(100); 156 noTone(buzzer); 157 delay(50); 158 tone(buzzer, 2000); 159 delay(100); 160 noTone(buzzer); 161 delay(50); 162 lcd.clear(); 163 lcd.setCursor(0, 1); 164 lcd.print(" Enter combination: "); 165} 166 167///////////////////////////Combination # Original///////////////////////////// 168// Turn potentiometers in this sequence: // 169// First - pot #1 // 170// Second - pot #2 // 171// Third - pot #3 // 172// Fourth - pot #4 // 173// *NOTE*: You can set your own combination sequence by changing the // 174// arrangement of pot1_digact - pot4_digact in the 'if' // 175// statements. // 176////////////////////////////////////////////////////////////////////////////// 177void Combination_original() { 178 while (i < 4) { 179 if (pot1_digact(password[0]) == 1) { // pot #1 180 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 181 // capture time taken for the user to input the FIRST digit 182 while (t < 1) { 183 firstDigitTime = millis(); 184 Serial.print("First Digit Time: "); 185 Serial.println(firstDigitTime); 186 t = 1; 187 } 188 i = 1; 189 if (pot2_digact(password[1]) == 1) { // pot #2 190 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 191 i = 2; 192 if (pot3_digact(password[2]) == 1) { // pot #3 193 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 194 i = 3; 195 if (pot4_digact(password[3]) == 1) { // pot #4 196 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 197 t = 0; // re-enable 'timer' 198 // capture time taken for the user to input the LAST digit 199 while (t < 1) { 200 lastDigitTime = millis(); 201 Serial.print("Last Digit Time: "); 202 Serial.println(lastDigitTime); 203 t = 1; 204 } 205 // Compare start and end timing if User enter password within the time limit 206 if (lastDigitTime - firstDigitTime < timeLimit) { 207 //ACCESS GRANTED HERE// 208 accessGranted(); 209 } 210 else { 211 //ACCCESS DENIED HERE// 212 accessDenied(); 213 count++; 214 load = 0; 215 } 216 delay(1000); 217 digitalWrite(D1_LED, LOW); 218 digitalWrite(D3_LED, LOW); 219 digitalWrite(D2_LED, LOW); 220 digitalWrite(D4_LED, LOW); 221 i = 4; 222 } 223 else { 224 digitalWrite(D4_LED, LOW); 225 } 226 } 227 else { 228 digitalWrite(D3_LED, LOW); 229 } 230 } 231 else { 232 digitalWrite(D2_LED, LOW); 233 } 234 } 235 else { 236 digitalWrite(D1_LED, LOW); 237 } 238 } 239} 240 241///////////////////////////Combination # ONE////////////////////////////////// 242// Turn potentiometers in this sequence: // 243// First - pot #1 // 244// Second - pot #3 // 245// Third - pot #2 // 246// Fourth - pot #4 // 247// *NOTE*: You can set your own combination sequence by changing the // 248// arrangement of pot1_digact - pot4_digact in the 'if' // 249// statements. // 250////////////////////////////////////////////////////////////////////////////// 251void Combination_one() { 252 while (i < 4) { 253 if (pot1_digact(password[0]) == 1) { // pot #1 254 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 255 // capture time taken for the user to input the FIRST digit 256 while (t < 1) { 257 firstDigitTime = millis(); 258 Serial.print("First Digit Time: "); 259 Serial.println(firstDigitTime); 260 t = 1; 261 } 262 i = 1; 263 if (pot3_digact(password[1]) == 1) { // pot #3 264 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 265 i = 2; 266 if (pot2_digact(password[2]) == 1) { // pot #2 267 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 268 i = 3; 269 if (pot4_digact(password[3]) == 1) { // pot #4 270 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 271 t = 0; // re-enable 'timer' 272 // capture time taken for the user to input the LAST digit 273 while (t < 1) { 274 lastDigitTime = millis(); 275 Serial.print("Last Digit Time: "); 276 Serial.println(lastDigitTime); 277 t = 1; 278 } 279 // Compare start and end timing if User enter password within the time limit 280 if (lastDigitTime - firstDigitTime < timeLimit) { 281 //ACCESS GRANTED HERE// 282 accessGranted(); 283 } 284 else { 285 //ACCESS DENIED HERE// 286 accessDenied(); 287 count++; 288 load = 0; 289 } 290 delay(1000); 291 digitalWrite(D1_LED, LOW); 292 digitalWrite(D3_LED, LOW); 293 digitalWrite(D2_LED, LOW); 294 digitalWrite(D4_LED, LOW); 295 i = 4; 296 } 297 else { 298 digitalWrite(D4_LED, LOW); 299 } 300 } 301 else { 302 digitalWrite(D3_LED, LOW); 303 } 304 } 305 else { 306 digitalWrite(D2_LED, LOW); 307 } 308 } 309 else { 310 digitalWrite(D1_LED, LOW); 311 } 312 } 313} 314 315///////////////////////////Combination # TWO////////////////////////////////// 316// Turn potentiometers in this sequence: // 317// First - pot #4 // 318// Second - pot #3 // 319// Third - pot #2 // 320// Fourth - pot #1 // 321// *NOTE*: You can set your own combination sequence by changing the // 322// arrangement of pot1_digact - pot4_digact in the 'if' // 323// statements. // 324////////////////////////////////////////////////////////////////////////////// 325void Combination_two() { 326 while (i < 4) { 327 if (pot4_digact(password[0]) == 1) { // pot #4 328 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 329 // capture time taken for the user to input the FIRST digit 330 while (t < 1) { 331 firstDigitTime = millis(); 332 Serial.print("First Digit Time: "); 333 Serial.println(firstDigitTime); 334 t = 1; 335 } 336 i = 1; 337 if (pot3_digact(password[1]) == 1) { // pot #3 338 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 339 i = 2; 340 if (pot2_digact(password[2]) == 1) { // pot #2 341 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 342 i = 3; 343 if (pot1_digact(password[3]) == 1) { // pot #1 344 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 345 t = 0; // re-enable 'timer' 346 // capture time taken for the user to input the LAST digit 347 while (t < 1) { 348 lastDigitTime = millis(); 349 Serial.print("Last Digit Time: "); 350 Serial.println(lastDigitTime); 351 t = 1; 352 } 353 // Compare start and end timing if User enter password within the time limit 354 if (lastDigitTime - firstDigitTime < timeLimit) { 355 //ACCESS GRANTED HERE// 356 accessGranted(); 357 } 358 else { 359 //ACCESS DENIED HERE// 360 accessDenied(); 361 count++; 362 } 363 delay(1000); 364 digitalWrite(D1_LED, LOW); 365 digitalWrite(D3_LED, LOW); 366 digitalWrite(D2_LED, LOW); 367 digitalWrite(D4_LED, LOW); 368 i = 4; 369 } 370 else { 371 digitalWrite(D4_LED, LOW); 372 } 373 } 374 else { 375 digitalWrite(D3_LED, LOW); 376 } 377 } 378 else { 379 digitalWrite(D2_LED, LOW); 380 } 381 } 382 else { 383 digitalWrite(D1_LED, LOW); 384 } 385 } 386} 387 388//////////////////////////////////////////////////////////////////////////// 389// This function turns the 1st potentiometer into a rotating dial (1 - 9) // 390//////////////////////////////////////////////////////////////////////////// 391int pot1_digact(int val) { 392 pot1 = analogRead(A0); 393 // for 1st digit of the password 394 switch (val) { 395 case 1: 396 if ((val == 1) && pot1 >= 100 && pot1 <= 199) { 397 return 1; 398 } 399 else { 400 return 0; 401 } 402 break; 403 case 2: 404 if ((val == 2) && pot1 >= 200 && pot1 <= 399) { 405 return 1; 406 } 407 else { 408 return 0; 409 } 410 break; 411 case 3: 412 if ((val == 3) && pot1 >= 300 && pot1 <= 399) { 413 return 1; 414 } 415 else { 416 return 0; 417 } 418 break; 419 case 4: 420 if ((val == 4) && pot1 >= 400 && pot1 <= 499) { 421 return 1; 422 } 423 else { 424 return 0; 425 } 426 break; 427 case 5: 428 if ((val == 5) && pot1 >= 500 && pot1 <= 599) { 429 return 1; 430 } 431 else { 432 return 0; 433 } 434 break; 435 case 6: 436 if ((val == 6) && pot1 >= 600 && pot1 <= 699) { 437 return 1; 438 } 439 else { 440 return 0; 441 } 442 break; 443 case 7: 444 if ((val == 7) && pot1 >= 700 && pot1 <= 799) { 445 return 1; 446 } 447 else { 448 return 0; 449 } 450 break; 451 case 8: 452 if ((val == 8) && pot1 >= 800 && pot1 <= 899) { 453 return 1; 454 } 455 else { 456 return 0; 457 } 458 break; 459 case 9: 460 if ((val == 9) && pot1 >= 900) { 461 return 1; 462 } 463 else { 464 return 0; 465 } 466 break; 467 } 468} 469 470//////////////////////////////////////////////////////////////////////////// 471// This function turns the 2nd potentiometer into a rotating dial (1 - 9) // 472//////////////////////////////////////////////////////////////////////////// 473int pot2_digact(int val) { 474 pot2 = analogRead(A1); 475 // for 2nd digit of the password 476 switch (val) { 477 case 1: 478 if ((val == 1) && pot2 >= 100 && pot2 <= 199) { 479 return 1; 480 } 481 else { 482 return 0; 483 } 484 break; 485 case 2: 486 if ((val == 2) && pot2 >= 200 && pot2 <= 399) { 487 return 1; 488 } 489 else { 490 return 0; 491 } 492 break; 493 case 3: 494 if ((val == 3) && pot2 >= 300 && pot2 <= 399) { 495 return 1; 496 } 497 else { 498 return 0; 499 } 500 break; 501 case 4: 502 if ((val == 4) && pot2 >= 400 && pot2 <= 499) { 503 return 1; 504 } 505 else { 506 return 0; 507 } 508 break; 509 case 5: 510 if ((val == 5) && pot2 >= 500 && pot2 <= 599) { 511 return 1; 512 } 513 else { 514 return 0; 515 } 516 break; 517 case 6: 518 if ((val == 6) && pot2 >= 600 && pot2 <= 699) { 519 return 1; 520 } 521 else { 522 return 0; 523 } 524 break; 525 case 7: 526 if ((val == 7) && pot2 >= 700 && pot2 <= 799) { 527 return 1; 528 } 529 else { 530 return 0; 531 } 532 break; 533 case 8: 534 if ((val == 8) && pot2 >= 800 && pot2 <= 899) { 535 return 1; 536 } 537 else { 538 return 0; 539 } 540 break; 541 case 9: 542 if ((val == 9) && pot2 >= 900) { 543 return 1; 544 } 545 else { 546 return 0; 547 } 548 break; 549 } 550} 551 552//////////////////////////////////////////////////////////////////////////// 553// This function turns the 3rd potentiometer into a rotating dial (1 - 9) // 554//////////////////////////////////////////////////////////////////////////// 555int pot3_digact(int val) { 556 pot3 = analogRead(A2); 557 // for 3rd digit of the password 558 switch (val) { 559 case 1: 560 if ((val == 1) && pot3 >= 100 && pot3 <= 199) { 561 return 1; 562 } 563 else { 564 return 0; 565 } 566 break; 567 case 2: 568 if ((val == 2) && pot3 >= 200 && pot3 <= 399) { 569 return 1; 570 } 571 else { 572 return 0; 573 } 574 break; 575 case 3: 576 if ((val == 3) && pot3 >= 300 && pot3 <= 399) { 577 return 1; 578 } 579 else { 580 return 0; 581 } 582 break; 583 case 4: 584 if ((val == 4) && pot3 >= 400 && pot3 <= 499) { 585 return 1; 586 } 587 else { 588 return 0; 589 } 590 break; 591 case 5: 592 if ((val == 5) && pot3 >= 500 && pot3 <= 599) { 593 return 1; 594 } 595 else { 596 return 0; 597 } 598 break; 599 case 6: 600 if ((val == 6) && pot3 >= 600 && pot3 <= 699) { 601 return 1; 602 } 603 else { 604 return 0; 605 } 606 break; 607 case 7: 608 if ((val == 7) && pot3 >= 700 && pot3 <= 799) { 609 return 1; 610 } 611 else { 612 return 0; 613 } 614 break; 615 case 8: 616 if ((val == 8) && pot3 >= 800 && pot3 <= 899) { 617 return 1; 618 } 619 else { 620 return 0; 621 } 622 break; 623 case 9: 624 if ((val == 9) && pot3 >= 900) { 625 return 1; 626 } 627 else { 628 return 0; 629 } 630 break; 631 } 632} 633 634//////////////////////////////////////////////////////////////////////////// 635// This function turns the 4th potentiometer into a rotating dial (1 - 9) // 636//////////////////////////////////////////////////////////////////////////// 637int pot4_digact(int val) { 638 pot4 = analogRead(A3); 639 // for 4th digit of the password 640 switch (val) { 641 case 1: 642 if ((val == 1) && pot4 >= 100 && pot4 <= 199) { 643 return 1; 644 } 645 else { 646 return 0; 647 } 648 break; 649 case 2: 650 if ((val == 2) && pot4 >= 200 && pot4 <= 399) { 651 return 1; 652 } 653 else { 654 return 0; 655 } 656 break; 657 case 3: 658 if ((val == 3) && pot4 >= 300 && pot4 <= 399) { 659 return 1; 660 } 661 else { 662 return 0; 663 } 664 break; 665 case 4: 666 if ((val == 4) && pot4 >= 400 && pot4 <= 499) { 667 return 1; 668 } 669 else { 670 return 0; 671 } 672 break; 673 case 5: 674 if ((val == 5) && pot4 >= 500 && pot4 <= 599) { 675 return 1; 676 } 677 else { 678 return 0; 679 } 680 break; 681 case 6: 682 if ((val == 6) && pot4 >= 600 && pot4 <= 699) { 683 return 1; 684 } 685 else { 686 return 0; 687 } 688 break; 689 case 7: 690 if ((val == 7) && pot4 >= 700 && pot4 <= 799) { 691 return 1; 692 } 693 else { 694 return 0; 695 } 696 break; 697 case 8: 698 if ((val == 8) && pot4 >= 800 && pot4 <= 899) { 699 return 1; 700 } 701 else { 702 return 0; 703 } 704 break; 705 case 9: 706 if ((val == 9) && pot4 >= 900) { 707 return 1; 708 } 709 else { 710 return 0; 711 } 712 break; 713 } 714} 715 716void accessGranted() { 717 lcd.clear(); 718 lcd.setCursor(0, 1); 719 lcd.print(" Access Granted "); 720 digitalWrite(D1_LED, LOW); 721 digitalWrite(D3_LED, LOW); 722 digitalWrite(D2_LED, LOW); 723 digitalWrite(D4_LED, LOW); 724 tone(buzzer, 2000); 725 digitalWrite(D1_LED, HIGH); 726 digitalWrite(D3_LED, HIGH); 727 digitalWrite(D2_LED, HIGH); 728 digitalWrite(D4_LED, HIGH); 729 delay(100); 730 digitalWrite(D1_LED, LOW); 731 digitalWrite(D3_LED, LOW); 732 digitalWrite(D2_LED, LOW); 733 digitalWrite(D4_LED, LOW); 734 noTone(buzzer); 735 delay(100); 736 digitalWrite(D1_LED, HIGH); 737 digitalWrite(D3_LED, HIGH); 738 digitalWrite(D2_LED, HIGH); 739 digitalWrite(D4_LED, HIGH); 740 tone(buzzer, 2000); 741 delay(100); 742 noTone(buzzer); 743 delay(100); 744} 745 746void accessDenied() { 747 lcd.clear(); 748 lcd.setCursor(0, 1); 749 lcd.print(" Access Denied "); 750 tone(buzzer, 1000); 751 delay(250); 752 noTone(buzzer); 753 delay(100); 754 tone(buzzer, 1000); 755 delay(250); 756 noTone(buzzer); 757 delay(100); 758 tone(buzzer, 1000); 759 delay(250); 760 noTone(buzzer); 761 delay(100); 762 lcd.clear(); 763 lcd.setCursor(0, 0); 764 lcd.print(" Please reset "); 765 lcd.setCursor(0, 1); 766 lcd.print("ALL FOUR knobs to 0"); 767 lcd.setCursor(0, 2); 768 for (line = 0; line < 20; line++) { 769 lcd.write(0); 770 delay(1000); 771 } 772} 773
Code:
arduino
1/* Arduino 'Combination Safe' concept 2 3 Components: 4 - Arduino Uno 5 - Green LED (x 4) 6 - 10KOhm potentiometer (x 4) 7 - 1kOhm resistor (x 4) 8 - 220Ohm resistor 9 - LCD I2C (20x4) 10 - Passive Buzzer 11 - Push button tactile switch 12 - Some jumper wires 13 14 Libraries: 15 - LiquidCrystal_I2C library 16 17 Created on 29 June 2022 by c010rblind3ngineer 18*/ 19 20#include <LiquidCrystal_I2C.h> 21 22int pot1, pot2, pot3, pot4; 23const int buzzer = 9; 24const int buttonPin = 2; 25 26//////////////////////////////////////////////////////////////////////////////// 27// LEDs are for visual indication of the correct input password, // 28// for future project you could put numeric indicators on each potentiometer. // 29//////////////////////////////////////////////////////////////////////////////// 30const int D1_LED = 7; 31const int D2_LED = 6; 32const int D3_LED = 5; 33const int D4_LED = 4; 34 35unsigned long firstDigitTime; 36unsigned long lastDigitTime; 37 38int timeLimit = 8000; // time limit for User to input combination 39int i = 0; 40int t = 0; 41int load = 0; 42 43int line; 44int count; 45 46int password[5] = {1, 2, 3, 4}; // set your own password here... 47 48byte loadingBar[] = { 49 B11111, 50 B11111, 51 B11111, 52 B11111, 53 B11111, 54 B11111, 55 B11111, 56 B11111, 57}; 58 59LiquidCrystal_I2C lcd(0x27, 20, 4); 60 61void setup() { 62 Serial.begin(9600); 63 pinMode(D1_LED, OUTPUT); 64 pinMode(D2_LED, OUTPUT); 65 pinMode(D3_LED, OUTPUT); 66 pinMode(D4_LED, OUTPUT); 67 pinMode(buttonPin, INPUT); 68 69 lcd.init(); 70 lcd.createChar(0, loadingBar); 71} 72 73void loop() { 74 ////////////////////////////////////////////////////////////// 75 // There are 3 sets of 'Combination' functions: // 76 // Combination_original() ---->> pot#1, pot#2, pot#3, pot#4 // 77 // Combination_one() ---->> pot#1, pot#3, pot#2, pot#4 // 78 // Combination_two() ---->> pot#4, pot#3, pot#2, pot#1 // 79 ////////////////////////////////////////////////////////////// 80 for (count = 0; count < 3;) { 81 if (count == 0) { 82 while (load < 1) { 83 safeInit(); 84 load = 1; 85 } 86 Combination_original(); 87 } 88 if (count == 1) { 89 while (load < 1) { 90 lcd.clear(); 91 lcd.print("Press button once..."); 92 while (digitalRead(buttonPin) != HIGH) {} 93 if (digitalRead(buttonPin) == HIGH) { 94 i = 0; 95 t = 0; 96 } 97 delay(100); 98 safeInit(); 99 load = 1; 100 } 101 Combination_one(); 102 } 103 if (count == 2) { 104 while (load < 1) { 105 lcd.clear(); 106 lcd.print("Press button once..."); 107 while (digitalRead(buttonPin) != HIGH) {} 108 if (digitalRead(buttonPin) == HIGH) { 109 i = 0; 110 t = 0; 111 } 112 delay(100); 113 safeInit(); 114 load = 1; 115 } 116 Combination_two(); 117 } 118 } 119 // if User fail to input combination within time limit for ALL tries, shutdown system... 120 delay(3000); 121 lcd.clear(); 122 lcd.setCursor(0, 1); 123 lcd.print(" Goodbye. "); 124 delay(1000); 125 tone(buzzer, 2000); 126 delay(100); 127 noTone(buzzer); 128 delay(50); 129 tone(buzzer, 2000); 130 delay(100); 131 noTone(buzzer); 132 delay(50); 133 lcd.clear(); 134 lcd.noBacklight(); 135} 136 137// Initialization & Loading screen 138void safeInit() { 139 lcd.backlight(); 140 lcd.setCursor(0, 0); 141 lcd.print(" Arduino "); 142 lcd.setCursor(0, 1); 143 lcd.print(" Combination Safe "); 144 delay(5000); 145 lcd.clear(); 146 lcd.print(" Loading... "); 147 delay(1000); 148 lcd.setCursor(0, 1); 149 for (line = 0; line < 20; line++) { 150 lcd.write(0); 151 delay(200); 152 } 153 delay(250); 154 tone(buzzer, 2000); 155 delay(100); 156 noTone(buzzer); 157 delay(50); 158 tone(buzzer, 2000); 159 delay(100); 160 noTone(buzzer); 161 delay(50); 162 lcd.clear(); 163 lcd.setCursor(0, 1); 164 lcd.print(" Enter combination: "); 165} 166 167///////////////////////////Combination # Original///////////////////////////// 168// Turn potentiometers in this sequence: // 169// First - pot #1 // 170// Second - pot #2 // 171// Third - pot #3 // 172// Fourth - pot #4 // 173// *NOTE*: You can set your own combination sequence by changing the // 174// arrangement of pot1_digact - pot4_digact in the 'if' // 175// statements. // 176////////////////////////////////////////////////////////////////////////////// 177void Combination_original() { 178 while (i < 4) { 179 if (pot1_digact(password[0]) == 1) { // pot #1 180 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 181 // capture time taken for the user to input the FIRST digit 182 while (t < 1) { 183 firstDigitTime = millis(); 184 Serial.print("First Digit Time: "); 185 Serial.println(firstDigitTime); 186 t = 1; 187 } 188 i = 1; 189 if (pot2_digact(password[1]) == 1) { // pot #2 190 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 191 i = 2; 192 if (pot3_digact(password[2]) == 1) { // pot #3 193 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 194 i = 3; 195 if (pot4_digact(password[3]) == 1) { // pot #4 196 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 197 t = 0; // re-enable 'timer' 198 // capture time taken for the user to input the LAST digit 199 while (t < 1) { 200 lastDigitTime = millis(); 201 Serial.print("Last Digit Time: "); 202 Serial.println(lastDigitTime); 203 t = 1; 204 } 205 // Compare start and end timing if User enter password within the time limit 206 if (lastDigitTime - firstDigitTime < timeLimit) { 207 //ACCESS GRANTED HERE// 208 accessGranted(); 209 } 210 else { 211 //ACCCESS DENIED HERE// 212 accessDenied(); 213 count++; 214 load = 0; 215 } 216 delay(1000); 217 digitalWrite(D1_LED, LOW); 218 digitalWrite(D3_LED, LOW); 219 digitalWrite(D2_LED, LOW); 220 digitalWrite(D4_LED, LOW); 221 i = 4; 222 } 223 else { 224 digitalWrite(D4_LED, LOW); 225 } 226 } 227 else { 228 digitalWrite(D3_LED, LOW); 229 } 230 } 231 else { 232 digitalWrite(D2_LED, LOW); 233 } 234 } 235 else { 236 digitalWrite(D1_LED, LOW); 237 } 238 } 239} 240 241///////////////////////////Combination # ONE////////////////////////////////// 242// Turn potentiometers in this sequence: // 243// First - pot #1 // 244// Second - pot #3 // 245// Third - pot #2 // 246// Fourth - pot #4 // 247// *NOTE*: You can set your own combination sequence by changing the // 248// arrangement of pot1_digact - pot4_digact in the 'if' // 249// statements. // 250////////////////////////////////////////////////////////////////////////////// 251void Combination_one() { 252 while (i < 4) { 253 if (pot1_digact(password[0]) == 1) { // pot #1 254 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 255 // capture time taken for the user to input the FIRST digit 256 while (t < 1) { 257 firstDigitTime = millis(); 258 Serial.print("First Digit Time: "); 259 Serial.println(firstDigitTime); 260 t = 1; 261 } 262 i = 1; 263 if (pot3_digact(password[1]) == 1) { // pot #3 264 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 265 i = 2; 266 if (pot2_digact(password[2]) == 1) { // pot #2 267 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 268 i = 3; 269 if (pot4_digact(password[3]) == 1) { // pot #4 270 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 271 t = 0; // re-enable 'timer' 272 // capture time taken for the user to input the LAST digit 273 while (t < 1) { 274 lastDigitTime = millis(); 275 Serial.print("Last Digit Time: "); 276 Serial.println(lastDigitTime); 277 t = 1; 278 } 279 // Compare start and end timing if User enter password within the time limit 280 if (lastDigitTime - firstDigitTime < timeLimit) { 281 //ACCESS GRANTED HERE// 282 accessGranted(); 283 } 284 else { 285 //ACCESS DENIED HERE// 286 accessDenied(); 287 count++; 288 load = 0; 289 } 290 delay(1000); 291 digitalWrite(D1_LED, LOW); 292 digitalWrite(D3_LED, LOW); 293 digitalWrite(D2_LED, LOW); 294 digitalWrite(D4_LED, LOW); 295 i = 4; 296 } 297 else { 298 digitalWrite(D4_LED, LOW); 299 } 300 } 301 else { 302 digitalWrite(D3_LED, LOW); 303 } 304 } 305 else { 306 digitalWrite(D2_LED, LOW); 307 } 308 } 309 else { 310 digitalWrite(D1_LED, LOW); 311 } 312 } 313} 314 315///////////////////////////Combination # TWO////////////////////////////////// 316// Turn potentiometers in this sequence: // 317// First - pot #4 // 318// Second - pot #3 // 319// Third - pot #2 // 320// Fourth - pot #1 // 321// *NOTE*: You can set your own combination sequence by changing the // 322// arrangement of pot1_digact - pot4_digact in the 'if' // 323// statements. // 324////////////////////////////////////////////////////////////////////////////// 325void Combination_two() { 326 while (i < 4) { 327 if (pot4_digact(password[0]) == 1) { // pot #4 328 digitalWrite(D1_LED, HIGH); // turn ON 1st LED 329 // capture time taken for the user to input the FIRST digit 330 while (t < 1) { 331 firstDigitTime = millis(); 332 Serial.print("First Digit Time: "); 333 Serial.println(firstDigitTime); 334 t = 1; 335 } 336 i = 1; 337 if (pot3_digact(password[1]) == 1) { // pot #3 338 digitalWrite(D2_LED, HIGH); // turn ON 2nd LED 339 i = 2; 340 if (pot2_digact(password[2]) == 1) { // pot #2 341 digitalWrite(D3_LED, HIGH); // turn ON 3rd LED 342 i = 3; 343 if (pot1_digact(password[3]) == 1) { // pot #1 344 digitalWrite(D4_LED, HIGH); // turn ON 4th LED 345 t = 0; // re-enable 'timer' 346 // capture time taken for the user to input the LAST digit 347 while (t < 1) { 348 lastDigitTime = millis(); 349 Serial.print("Last Digit Time: "); 350 Serial.println(lastDigitTime); 351 t = 1; 352 } 353 // Compare start and end timing if User enter password within the time limit 354 if (lastDigitTime - firstDigitTime < timeLimit) { 355 //ACCESS GRANTED HERE// 356 accessGranted(); 357 } 358 else { 359 //ACCESS DENIED HERE// 360 accessDenied(); 361 count++; 362 } 363 delay(1000); 364 digitalWrite(D1_LED, LOW); 365 digitalWrite(D3_LED, LOW); 366 digitalWrite(D2_LED, LOW); 367 digitalWrite(D4_LED, LOW); 368 i = 4; 369 } 370 else { 371 digitalWrite(D4_LED, LOW); 372 } 373 } 374 else { 375 digitalWrite(D3_LED, LOW); 376 } 377 } 378 else { 379 digitalWrite(D2_LED, LOW); 380 } 381 } 382 else { 383 digitalWrite(D1_LED, LOW); 384 } 385 } 386} 387 388//////////////////////////////////////////////////////////////////////////// 389// This function turns the 1st potentiometer into a rotating dial (1 - 9) // 390//////////////////////////////////////////////////////////////////////////// 391int pot1_digact(int val) { 392 pot1 = analogRead(A0); 393 // for 1st digit of the password 394 switch (val) { 395 case 1: 396 if ((val == 1) && pot1 >= 100 && pot1 <= 199) { 397 return 1; 398 } 399 else { 400 return 0; 401 } 402 break; 403 case 2: 404 if ((val == 2) && pot1 >= 200 && pot1 <= 399) { 405 return 1; 406 } 407 else { 408 return 0; 409 } 410 break; 411 case 3: 412 if ((val == 3) && pot1 >= 300 && pot1 <= 399) { 413 return 1; 414 } 415 else { 416 return 0; 417 } 418 break; 419 case 4: 420 if ((val == 4) && pot1 >= 400 && pot1 <= 499) { 421 return 1; 422 } 423 else { 424 return 0; 425 } 426 break; 427 case 5: 428 if ((val == 5) && pot1 >= 500 && pot1 <= 599) { 429 return 1; 430 } 431 else { 432 return 0; 433 } 434 break; 435 case 6: 436 if ((val == 6) && pot1 >= 600 && pot1 <= 699) { 437 return 1; 438 } 439 else { 440 return 0; 441 } 442 break; 443 case 7: 444 if ((val == 7) && pot1 >= 700 && pot1 <= 799) { 445 return 1; 446 } 447 else { 448 return 0; 449 } 450 break; 451 case 8: 452 if ((val == 8) && pot1 >= 800 && pot1 <= 899) { 453 return 1; 454 } 455 else { 456 return 0; 457 } 458 break; 459 case 9: 460 if ((val == 9) && pot1 >= 900) { 461 return 1; 462 } 463 else { 464 return 0; 465 } 466 break; 467 } 468} 469 470//////////////////////////////////////////////////////////////////////////// 471// This function turns the 2nd potentiometer into a rotating dial (1 - 9) // 472//////////////////////////////////////////////////////////////////////////// 473int pot2_digact(int val) { 474 pot2 = analogRead(A1); 475 // for 2nd digit of the password 476 switch (val) { 477 case 1: 478 if ((val == 1) && pot2 >= 100 && pot2 <= 199) { 479 return 1; 480 } 481 else { 482 return 0; 483 } 484 break; 485 case 2: 486 if ((val == 2) && pot2 >= 200 && pot2 <= 399) { 487 return 1; 488 } 489 else { 490 return 0; 491 } 492 break; 493 case 3: 494 if ((val == 3) && pot2 >= 300 && pot2 <= 399) { 495 return 1; 496 } 497 else { 498 return 0; 499 } 500 break; 501 case 4: 502 if ((val == 4) && pot2 >= 400 && pot2 <= 499) { 503 return 1; 504 } 505 else { 506 return 0; 507 } 508 break; 509 case 5: 510 if ((val == 5) && pot2 >= 500 && pot2 <= 599) { 511 return 1; 512 } 513 else { 514 return 0; 515 } 516 break; 517 case 6: 518 if ((val == 6) && pot2 >= 600 && pot2 <= 699) { 519 return 1; 520 } 521 else { 522 return 0; 523 } 524 break; 525 case 7: 526 if ((val == 7) && pot2 >= 700 && pot2 <= 799) { 527 return 1; 528 } 529 else { 530 return 0; 531 } 532 break; 533 case 8: 534 if ((val == 8) && pot2 >= 800 && pot2 <= 899) { 535 return 1; 536 } 537 else { 538 return 0; 539 } 540 break; 541 case 9: 542 if ((val == 9) && pot2 >= 900) { 543 return 1; 544 } 545 else { 546 return 0; 547 } 548 break; 549 } 550} 551 552//////////////////////////////////////////////////////////////////////////// 553// This function turns the 3rd potentiometer into a rotating dial (1 - 9) // 554//////////////////////////////////////////////////////////////////////////// 555int pot3_digact(int val) { 556 pot3 = analogRead(A2); 557 // for 3rd digit of the password 558 switch (val) { 559 case 1: 560 if ((val == 1) && pot3 >= 100 && pot3 <= 199) { 561 return 1; 562 } 563 else { 564 return 0; 565 } 566 break; 567 case 2: 568 if ((val == 2) && pot3 >= 200 && pot3 <= 399) { 569 return 1; 570 } 571 else { 572 return 0; 573 } 574 break; 575 case 3: 576 if ((val == 3) && pot3 >= 300 && pot3 <= 399) { 577 return 1; 578 } 579 else { 580 return 0; 581 } 582 break; 583 case 4: 584 if ((val == 4) && pot3 >= 400 && pot3 <= 499) { 585 return 1; 586 } 587 else { 588 return 0; 589 } 590 break; 591 case 5: 592 if ((val == 5) && pot3 >= 500 && pot3 <= 599) { 593 return 1; 594 } 595 else { 596 return 0; 597 } 598 break; 599 case 6: 600 if ((val == 6) && pot3 >= 600 && pot3 <= 699) { 601 return 1; 602 } 603 else { 604 return 0; 605 } 606 break; 607 case 7: 608 if ((val == 7) && pot3 >= 700 && pot3 <= 799) { 609 return 1; 610 } 611 else { 612 return 0; 613 } 614 break; 615 case 8: 616 if ((val == 8) && pot3 >= 800 && pot3 <= 899) { 617 return 1; 618 } 619 else { 620 return 0; 621 } 622 break; 623 case 9: 624 if ((val == 9) && pot3 >= 900) { 625 return 1; 626 } 627 else { 628 return 0; 629 } 630 break; 631 } 632} 633 634//////////////////////////////////////////////////////////////////////////// 635// This function turns the 4th potentiometer into a rotating dial (1 - 9) // 636//////////////////////////////////////////////////////////////////////////// 637int pot4_digact(int val) { 638 pot4 = analogRead(A3); 639 // for 4th digit of the password 640 switch (val) { 641 case 1: 642 if ((val == 1) && pot4 >= 100 && pot4 <= 199) { 643 return 1; 644 } 645 else { 646 return 0; 647 } 648 break; 649 case 2: 650 if ((val == 2) && pot4 >= 200 && pot4 <= 399) { 651 return 1; 652 } 653 else { 654 return 0; 655 } 656 break; 657 case 3: 658 if ((val == 3) && pot4 >= 300 && pot4 <= 399) { 659 return 1; 660 } 661 else { 662 return 0; 663 } 664 break; 665 case 4: 666 if ((val == 4) && pot4 >= 400 && pot4 <= 499) { 667 return 1; 668 } 669 else { 670 return 0; 671 } 672 break; 673 case 5: 674 if ((val == 5) && pot4 >= 500 && pot4 <= 599) { 675 return 1; 676 } 677 else { 678 return 0; 679 } 680 break; 681 case 6: 682 if ((val == 6) && pot4 >= 600 && pot4 <= 699) { 683 return 1; 684 } 685 else { 686 return 0; 687 } 688 break; 689 case 7: 690 if ((val == 7) && pot4 >= 700 && pot4 <= 799) { 691 return 1; 692 } 693 else { 694 return 0; 695 } 696 break; 697 case 8: 698 if ((val == 8) && pot4 >= 800 && pot4 <= 899) { 699 return 1; 700 } 701 else { 702 return 0; 703 } 704 break; 705 case 9: 706 if ((val == 9) && pot4 >= 900) { 707 return 1; 708 } 709 else { 710 return 0; 711 } 712 break; 713 } 714} 715 716void accessGranted() { 717 lcd.clear(); 718 lcd.setCursor(0, 1); 719 lcd.print(" Access Granted "); 720 digitalWrite(D1_LED, LOW); 721 digitalWrite(D3_LED, LOW); 722 digitalWrite(D2_LED, LOW); 723 digitalWrite(D4_LED, LOW); 724 tone(buzzer, 2000); 725 digitalWrite(D1_LED, HIGH); 726 digitalWrite(D3_LED, HIGH); 727 digitalWrite(D2_LED, HIGH); 728 digitalWrite(D4_LED, HIGH); 729 delay(100); 730 digitalWrite(D1_LED, LOW); 731 digitalWrite(D3_LED, LOW); 732 digitalWrite(D2_LED, LOW); 733 digitalWrite(D4_LED, LOW); 734 noTone(buzzer); 735 delay(100); 736 digitalWrite(D1_LED, HIGH); 737 digitalWrite(D3_LED, HIGH); 738 digitalWrite(D2_LED, HIGH); 739 digitalWrite(D4_LED, HIGH); 740 tone(buzzer, 2000); 741 delay(100); 742 noTone(buzzer); 743 delay(100); 744} 745 746void accessDenied() { 747 lcd.clear(); 748 lcd.setCursor(0, 1); 749 lcd.print(" Access Denied "); 750 tone(buzzer, 1000); 751 delay(250); 752 noTone(buzzer); 753 delay(100); 754 tone(buzzer, 1000); 755 delay(250); 756 noTone(buzzer); 757 delay(100); 758 tone(buzzer, 1000); 759 delay(250); 760 noTone(buzzer); 761 delay(100); 762 lcd.clear(); 763 lcd.setCursor(0, 0); 764 lcd.print(" Please reset "); 765 lcd.setCursor(0, 1); 766 lcd.print("ALL FOUR knobs to 0"); 767 lcd.setCursor(0, 2); 768 for (line = 0; line < 20; line++) { 769 lcd.write(0); 770 delay(1000); 771 } 772} 773
Repository link:
Downloadable files
Circuit:
Circuit:

Circuit:
Circuit:

Schematic:
Schematic:

Comments
Only logged in users can leave comments