Team members: Kristen Nicole Scudder, Li Zhuang, and Yuyang Yin
The Problem: Underserved Vulnerable Pedestrians at the Intersection
National MUTCD signal standards recommend using a crossing time for the average pedestrian (3.5ft/s) which is faster than the average speed of an elderly pedestrian (2ft/s – 2.5ft/s). The disabled pedestrian’s walking speed varies person to person but they tend to move slower than the average pedestrian.
This problem is particularly important in the City of Philadelphia because the disable population has increased by almost 7,000 people from 2012, and the population of Philadelphians over the age of 65 has increased by over 25,000 since 2010 which is a 14% increase.
The Solution: Crossing Guard
We want to address the problem by creating an opt-in solution for vulnerable populations, something that could be prescribed similarly to a handicap parking pass. Our concept is a RFID chip that is detected by the intersection as a pedestrian approaches, similarly to a toll system detecting a toll pass in your car.
To make the intersections more friendly to underserved populations, we are introducing Crossing Guard, an RFID (Radio-frequency identification) tag system for vulnerable people such as the elderly, visually impaired, hearing impaired, or mobility impaired who have difficulties crossing intersections in busy urban areas. The RFID tag uses the electronically-stored information to trigger different responses at the intersection as a pedestrian approaching the intersection is detected. The intersection responds by extending the crossing light signal timing, playing an audio noise to indicate that it is safe to cross, or displaying a visual cue that it is safe to cross. This not only helps pedestrians with limited mobility to feel safer when crossing a street but may also contribute to maintaining traffic flows by not permanently extending pedestrian intervals. The setting could also reduce the potential disturbance caused by audio assistance that running all the time.
The RFID sensors will be attached to the traffic light poles along with the speakers (No additional speaker required if the intersection already has it installed). Ground LED lights are installed on the ground with the wiring underneath the pavements. The traffic light poles will provide a constant power source to the system.
-
Why are we choosing RFID tag?
The RFID tag is inexpensive compared to other systems such as monitoring cameras. It is small and nonintrusive which are easy to carry around and less likely to be noticed by others. The system provides the correct range from tag to sensor which makes our solution feasible to implement. Last but not least, it does not require the pedestrian to find a push button which is particularly helpful for visually impaired populations.
-
Where can people with special needs obtain RFID tags?
In our proposal, people with special needs can obtain RFID tags from their doctors. We are encouraging doctors to explain the benefits of using the RFID tag in daily life to those people during their routine visits. People can also obtain the RFID tags from pharmacy stores such as Walgreens and CVS throughout the City for free with prescription and ID. In addition, these tags can be embedded in or attached to special types of equipment as such wheelchairs and blind canes (See picture below).
Prototype: How Crossing Guard Works?
When a pedestrian with an RFID tag approaching the intersection, the person along with the unique ID assigned to that tag will be detected by the RFID Reader installed on the traffic light pole. For this prototype, we are proposing two major responses. One is for the visually impaired population, and it will trigger the speaker to play audio “Safe to Cross” or “Wait” to notify the person about traffic light status. The other response is for the mobility impaired population, as the intersection will respond by extending the crossing time for 5 seconds. The ground LED lights will only be triggered when light intensity is low, which will notify the drivers that vulnerable pedestrian is crossing the intersection and make sure to pay attention. This project is not limited to these two responses. Additional surveys and research may help refine the responses we proposed and introduce other categories for RFID tags’ unique ID to trigger more responses at the intersection.
Moreover, if the person could not make to the opposite corner (the RFID Reader on the other side has not detected the same tag when the crossing interval ends), an extra 5 seconds will be added once to ensure crossing while reducing the stress level of that person. Then the intersection will be set back to the regular cycle.
Enjoy the video!
Location Recommendation
We chose an example location on the intersection of Market Street and 22nd Street in Philadelphia. It is a busy and highly utilized intersection for the elderly and disabled. The intersection is close to the John Fox Towers, a senior apartment. The decision is also based on the consideration of the width and high injury rates of Market Street indicated by High Injury Network Map provided by Vision Zero.
Based on the analysis, we would recommend a pilot installation of the system in Cobbs Creek Neighborhood and then promote Crossing Guard implementation in entire Philadelphia.
Future
The Crossing Guard will better serve the vulnerable population living in urban regions by not only generating instant benefits but also benefiting the population in long-term. The data collected by the system will provide significant add-on values in future studies associated with the vulnerable population in urban settings and potentially promote improvements to their life in cities.
Appendix: Prototype Code
Master Board: Control Traffic Intersection (Arduino Mega 2560)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
/* This is the code for the Master board: Control traffic cycle and request signal from Slave boards We used Arduino Mega 2560 Here */ //*********************************************************************************** #include <Wire.h> // Include the required Wire library for I2C#include <Wire.h> #include <SD.h> //include SD module library #define SD_ChipSelectPin 53 //define pin53 as CS pin #include <TMRpcm.h> //include speaker control library TMRpcm tmrpcm; //crete an object for speaker library // Include the library code for Liquid Crystal Screen. //Link for the library: http://wiki.sunfounder.cc/index.php?title=I%C2%B2C_LCD1602 #include <LiquidCrystal_I2C.h> #define PAYLOAD_SIZE 2 // how many bytes to expect from each I2C salve node #define NODE_MAX 6 // maximum number of slave nodes (I2C addresses) to probe #define START_NODE 2 // The starting I2C address of slave nodes #define NODE_READ_DELAY 1000 // Some delay between I2C node reads int nodePayload[PAYLOAD_SIZE]; int Board2TagGroup; int Board3TagGroup; //************************************** Define the pins by names ************************ const int test1 = 34; //red LED that will light up when card for visual impaired is detected const int test2 = 11; //yellow LED that will light up when card for mobility impaired is detected //Traffic Light for the same direction of crossing signal const int Red_PIN = 28; const int Yellow_PIN = 29; const int Green_PIN = 30; //Traffic light for the other direction const int Red_PIN2 = 22; const int Yellow_PIN2 = 23; const int Green_PIN2 = 24; int timer = 500; //A timer for the CountDown, to run the for loop 500 times, which turns out as 1 second. LiquidCrystal_I2C lcd(0x27, 16, 1); // set the LCD address to 0x27 for a 16 chars and 1 line display. // Pin 2-8 is connected to the 7 segments of the display. // We only need to count down from 10 to 0 so that only two digit L3 and L4 are used for this tutorial. int pinA = 8; int pinB = 7; int pinC = 6; int pinD = 5; int pinE = 4; int pinF = 3; int pinG = 2; int L3 = 13; int L4 = 12; //*********************************** photoresistor ************************** const int sensorPin = A0; const int ledNight = 40; // We'll also set up some global variables for the light level: int lightLevel, low = 100, high = 0; //need calibration, change the number accordingly based on your environment //*************************************************************************************** void setup() { pinMode (test1, OUTPUT); pinMode (test2, OUTPUT); Serial.begin(115200); Serial.print("Initializing SD card..."); Serial.println("MASTER READER NODE"); Serial.print("Maximum Slave Nodes: "); Serial.println(NODE_MAX); Serial.print("Payload size: "); Serial.println(PAYLOAD_SIZE); Serial.println("***********************"); Wire.begin(); // Activate I2C link pinMode (53, OUTPUT); digitalWrite (53, HIGH); if (!SD.begin(SD_ChipSelectPin)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); //Traffic Lights //Initialize the digital pins as outputs. pinMode(Red_PIN, OUTPUT); pinMode(Yellow_PIN, OUTPUT); pinMode(Green_PIN, OUTPUT); pinMode(Red_PIN2, OUTPUT); pinMode(Yellow_PIN2, OUTPUT); pinMode(Green_PIN2, OUTPUT); //Liquid Crystal Screen lcd.init(); //initialize the lcd. lcd.backlight(); //open the backlight. //7 Digit Display //Initialize the digital pins as outputs. pinMode(pinA, OUTPUT); pinMode(pinB, OUTPUT); pinMode(pinC, OUTPUT); pinMode(pinD, OUTPUT); pinMode(pinE, OUTPUT); pinMode(pinF, OUTPUT); pinMode(pinG, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT); tmrpcm.speakerPin = 46; //Define speaker pin. The speaker library is using pin9. pinMode(ledNight, OUTPUT); } //*************************************************************************************************************** // Define the sequence of the pattern in this mini intersection. // When the computer gets to the end of the loop() function, it starts loop() again. //*************************************************************************************************************** void loop() { RequestSignal (); //Request signal from slave boards //********************************************* Visual Impaired Extend traffic light and play audio ************************** if (Board2TagGroup == 1) { Serial.println ("Group1"); digitalWrite (test1, HIGH); digitalWrite (test2, LOW); //Light up LED when light intensity is low. Check light intensity value, calibration needed Serial.print ("light intensity:"); Serial.println (analogRead(sensorPin)); lightLevel = analogRead(sensorPin); void NightLED(); delay(500); // wait for 1/2 second to start blinking //Audio waiting tmrpcm.setVolume(5); // Set the volume as 5. tmrpcm.play("Wait2.wav"); Serial.println("Do not cross"); //One direction starts the traffic flow, the other direction holds the flow. digitalWrite(Green_PIN2, HIGH); // turn the LED Green 2 on digitalWrite(Red_PIN, HIGH); // turn the LED Red on lcd.setCursor(3, 0); // set the cursor to column 3, line 0 lcd.print("DO NOT CROSS"); // Print a message to the LCD delay(6000); // wait for 6 seconds (I shorten the real world traffic flow time for display purpose) digitalWrite(Green_PIN2, LOW); // turn the LED Green 2 off digitalWrite(Red_PIN, LOW); // turn the LED Red off //Transition: yellow lights turn on and off digitalWrite(Yellow_PIN, HIGH); // turn the yellow LED on digitalWrite(Yellow_PIN2, HIGH); // turn the yellow LED 2 on delay(1000); // wait for a second digitalWrite(Yellow_PIN, LOW); // turn the yellow LED off digitalWrite(Yellow_PIN2, LOW); // turn the yellow LED 2 off //play audio tmrpcm.play("Crossing.wav"); tmrpcm.loop(1); Serial.println ("Cross"); //Switch Traffic flow //One direction starts the traffic flow, the other direction holds the flow. lcd.setCursor(3, 0); // set the cursor to column 3, line 0 lcd.print(" "); // Print a message to the LCD (delete old message) delay(1); //Print new message lcd.setCursor(6, 0); // set the cursor to column 6, line 0 lcd.print("CROSS"); // Print a message to the LCD digitalWrite(Red_PIN2, HIGH); // turn the red LED 2 on digitalWrite(Green_PIN, HIGH); // turn the green LED on delay (5000); //Start Count Down for pedestrian crossing tmrpcm.loop(0); AudibleCountDown(); RequestBroad3 (); //Request signal from slave board 3 Group1Check(); //check whether the person reaches the other corner tmrpcm.volume(0); } //********************************************* Mobility Impaired Extend traffic light only ********************************* if (Board2TagGroup == 2) { Serial.println ("Group2"); digitalWrite (test1, LOW); digitalWrite (test2, HIGH); Serial.print ("light intensity:"); Serial.println (analogRead(sensorPin)); //digitalWrite (ledNight, HIGH); lightLevel = analogRead(sensorPin); void NightLED(); Trafficlight(); delay(10000); //Wait for 10 seconds CountDown15(); //Pedestrian with mobility impairment does not cross when count down ends RequestBroad3 (); Group2Check(); } //********************************************* Regular intersection no RFID ********************************* if (Board2TagGroup == 0) { Serial.println ("NoGroup"); digitalWrite (test1, LOW); digitalWrite (test2, LOW); digitalWrite (ledNight, LOW); Trafficlight(); delay(5000); //Wait for 5 seconds //Start Count Down for pedestrian crossing CountDown(); CrossingEnd(); } //********************************************** Functions ******************************************************* void NightLED() //Light up the ground LED at night if (lightLevel > low) { digitalWrite (ledNight, HIGH); } else { digitalWrite (ledNight,LOW); } } //Since we only deal with one direction crossing, assume the other direction do not have RFID intervention in this scenario// void Trafficlight() { delay(500); // wait for 1/2 second to start blinking //One direction starts the traffic flow, the other direction holds the flow. digitalWrite(Green_PIN2, HIGH); // turn the LED Green 2 on digitalWrite(Red_PIN, HIGH); // turn the LED Red on lcd.setCursor(3, 0); // set the cursor to column 3, line 0 lcd.print("DO NOT CROSS"); // Print a message to the LCD delay(6000); // wait for 6 seconds (I shorten the real world traffic flow time for display purpose) digitalWrite(Green_PIN2, LOW); // turn the LED Green 2 off digitalWrite(Red_PIN, LOW); // turn the LED Red off //Transition: yellow lights turn on and off digitalWrite(Yellow_PIN, HIGH); // turn the yellow LED on digitalWrite(Yellow_PIN2, HIGH); // turn the yellow LED 2 on delay(1000); // wait for a second digitalWrite(Yellow_PIN, LOW); // turn the yellow LED off digitalWrite(Yellow_PIN2, LOW); // turn the yellow LED 2 off //Switch Traffic flow //One direction starts the traffic flow, the other direction holds the flow. lcd.setCursor(3, 0); // set the cursor to column 3, line 0 lcd.print(" "); // Print a message to the LCD delay(1); //Print new message lcd.setCursor(6, 0); // set the cursor to column 6, line 0 lcd.print("CROSS"); // Print a message to the LCD digitalWrite(Red_PIN2, HIGH); // turn the red LED 2 on digitalWrite(Green_PIN, HIGH); // turn the green LED on } //Pedestrian Crossing count down for last 10 seconds: from 10 to 0 void CountDown() { for (int i=0; i<timer; i++) { //10 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //0 digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //9 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //8 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //7 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //6 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //5 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); //The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //4 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //3 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //2 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //1 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //0 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } //Turn off the 7 digit display digitalWrite(L3, LOW); digitalWrite(L4, LOW); delay(2); } void AudibleCountDown() { tmrpcm.setVolume(5); tmrpcm.play("10.wav"); for (int i=0; i<timer; i++) { //10 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //0 digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } tmrpcm.play("9.wav"); for (int i=0; i<timer; i++) { //9 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("8.wav"); for (int i=0; i<timer; i++) { //8 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("7.wav"); for (int i=0; i<timer; i++) { //7 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("6.wav"); for (int i=0; i<timer; i++) { //6 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("5.wav"); for (int i=0; i<timer; i++) { //5 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); //The for loop, for running the program 500 times. } tmrpcm.play("4.wav"); for (int i=0; i<timer; i++) { //4 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("3.wav"); for (int i=0; i<timer; i++) { //3 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("2.wav"); for (int i=0; i<timer; i++) { //2 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } tmrpcm.play("1.wav"); for (int i=0; i<timer; i++) { //1 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } //tmrpcm.play("0.wav"); for (int i=0; i<timer; i++) { //0 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } //Turn off the 7 digit display digitalWrite(L3, LOW); digitalWrite(L4, LOW); delay(2); } void CrossingEnd() { //Pedestrian Crossing finish digitalWrite(Red_PIN2, LOW); // turn the red LED 2 off digitalWrite(Green_PIN, LOW); // turn the green LED off digitalWrite(Yellow_PIN, HIGH); // turn the yellow LED on digitalWrite(Yellow_PIN2, HIGH); // turn the yellow LED 2 on delay(1000); // wait for a second digitalWrite(Yellow_PIN, LOW); // turn the yellow LED off digitalWrite(Yellow_PIN2, LOW); // turn the yellow LED 2 off } //Pedestrian Crossing count down for last 15 seconds: from 15 to 0 void CountDown15() { for (int i=0; i<timer; i++) { //15 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //5 digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //14 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //4 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //13 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //3 digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //12 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //2 digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //11 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //10 digitalWrite(L3, LOW); digitalWrite(L4, HIGH); //0 digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(1); digitalWrite(L3, HIGH); digitalWrite(L4, LOW); //1 digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(1); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //9 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //8 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //7 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //6 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //5 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); //The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //4 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //3 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //2 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //1 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } for (int i=0; i<timer; i++) { //0 digitalWrite(L3, HIGH); digitalWrite(L4, LOW); digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); delay(2); // The for loop, for running the program 500 times. } //Turn off the 7 digit display digitalWrite(L3, LOW); digitalWrite(L4, LOW); delay(2); } void Group1Check() { if (Board2TagGroup != Board3TagGroup) { Serial.println("Extra Crossing for visual impaired"); for (int i = 0; i < 3; i++) { //Print new message tmrpcm.setVolume(5); tmrpcm.play("Finish.wav"); lcd.setCursor(1, 0); // set the cursor to column 3, line 0 lcd.print("Finish Crossing"); // Print a message to the LCD delay (1000); lcd.setCursor(1, 0); // set the cursor to column 3, line 0 lcd.print(" "); // Print a message to the LCD delay(1000); tmrpcm.volume(0); } CrossingEnd(); } else { CrossingEnd(); } } void Group2Check() { if (Board2TagGroup != Board3TagGroup) { Serial.println("Extra Crossing for mobility impaired"); for (int i = 0; i < 3; i++) { //Print new message lcd.setCursor(1, 0); // set the cursor to column 3, line 0 lcd.print("Finish Crossing"); // Print a message to the LCD delay (1000); lcd.setCursor(1, 0); // set the cursor to column 3, line 0 lcd.print(" "); // Print a message to the LCD delay(1000); } CrossingEnd(); } else { CrossingEnd(); } } void RequestSignal () //change this to only request from broad 2 { for (int nodeAddress = START_NODE; nodeAddress <= NODE_MAX; nodeAddress++) { // we are starting from Node address 2 Wire.requestFrom(nodeAddress, PAYLOAD_SIZE); // request data from node# if(Wire.available() == PAYLOAD_SIZE) { // if data size is avaliable from nodes for (int i = 0; i < PAYLOAD_SIZE; i++) nodePayload[i] = Wire.read(); // get nodes data for (int j = 0; j < PAYLOAD_SIZE; j++) {Serial.println(nodePayload[j]); // print nodes data if(nodeAddress == 2){ Board2TagGroup = nodePayload[j]; } else if(nodeAddress == 3){ Board3TagGroup = nodePayload[j]; } } Serial.println("*************************"); } } delay(NODE_READ_DELAY); Serial.print("Board 2 Tag Group: "); Serial.println(Board2TagGroup); Serial.print("Board 3 Tag Group: "); Serial.println(Board3TagGroup); } void RequestBroad3 ()//change this to only request from broad 3 { //for (int nodeAddress = START_NODE; nodeAddress <= NODE_MAX; nodeAddress++) { // we are starting from Node address 2 Wire.requestFrom(3, PAYLOAD_SIZE); // request data from node# if(Wire.available() == PAYLOAD_SIZE) { // if data size is avaliable from nodes for (int i = 0; i < PAYLOAD_SIZE; i++) nodePayload[i] = Wire.read(); // get nodes data for (int j = 0; j < PAYLOAD_SIZE; j++) {Serial.println(nodePayload[j]); // print nodes data Board3TagGroup = nodePayload[j]; } Serial.println("*************************"); } delay(NODE_READ_DELAY); Serial.print("Board 2 Tag Group: "); Serial.println(Board2TagGroup); Serial.print("Board 3 Tag Group: "); Serial.println(Board3TagGroup); } |
Slave Board 1: Searching for RFID Tags (Arduino Uno)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
/**************************************************************************/ /*! This code is based on the file "readMifare.pde" created by Adafruit Industries @license BSD (see license.txt) This example will wait for any ISO14443A card or tag, and depending on the size of the UID will attempt to read from it. If the card has a 4-byte UID it is probably a Mifare Classic card, and the following steps are taken: - Authenticate block 4 (the first block of Sector 1) using the default KEYA of 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF - If authentication succeeds, we can then read any of the 4 blocks in that sector (though only block 4 is read here) If the card has a 7-byte UID it is probably a Mifare Ultralight card, and the 4 byte pages can be read directly. Page 4 is read by default since this is the first 'general- purpose' page on the tags. This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards This library works with the Adafruit NFC breakout ----> https://www.adafruit.com/products/364 Check out the links above for our tutorials and wiring diagrams These chips use SPI or I2C to communicate. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! */ /**************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_PN532.h> #include <Wire.h> // Include the required Wire library for I2C to connect Arduinos // To use the shield with I2C, define the pins connected to the IRQ and reset lines. #define PN532_IRQ (2) #define PN532_RESET (3) Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); #define NODE_ADDRESS 2 // Change this unique address for each I2C slave node #define PAYLOAD_SIZE 2 // Number of bytes expected to be received by the master I2C node byte nodePayload[PAYLOAD_SIZE]; #if defined(ARDUINO_ARCH_SAMD) // for Zero, output on USB Serial console, remove line below if using // programming port to program the Zero! #define Serial SerialUSB #endif void setup(void) { pinMode(8, OUTPUT); //Define Group 1 output pin (Red LED) pinMode(7, OUTPUT); //Define Group 2 output pin (Yellow LED) //Start Serial Monitor and set baud rate Serial.begin(115200); Serial.println("Hello!"); nfc.begin(); //initiate NFC connection //Search for PN532 uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } //If firmware found, print to serial monitor Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC); //Identify node address Serial.println("SLAVE SENDER NODE"); Serial.print("Node address: "); Serial.println(NODE_ADDRESS); Serial.print("Payload size: "); Serial.println(PAYLOAD_SIZE); Serial.println("***********************"); Wire.begin(NODE_ADDRESS); // Activate I2C network Wire.onRequest(requestEvent); // Request attention of master node //configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A Card ..."); Serial.println(""); } void loop(void) { uint8_t success; // Create variable for detected card uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) //Create Groups for different responses uint32_t Group1 = 1693588743; //Red LED uint32_t Group2 = 436264598; //Yellow LED uint32_t cardidentifier = 0; //Variable for current card being read //Success boolean is defined when a card is found and read success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); if (success) { // Print that card is found Serial.println("Found an ISO14443A card"); Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); Serial.print(" UID Value: "); nfc.PrintHex(uid, uidLength); Serial.println(""); if (uidLength == 4) // Mifare Classic Card { Serial.println("This is a Mifare Classic card (4 byte UID)"); Serial.println("Trying to authenticate block 4 with default KEYA value"); uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // Redefine success boolean if card is authenticated success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya); if (success) { Serial.println("Sector 1 (Blocks 4..7) has been authenticated"); Serial.println(""); uint8_t data[16]; //Turn UID into a single variable cardidentifier = uid[3]; cardidentifier <<= 8; cardidentifier |= uid[2]; cardidentifier <<= 8; cardidentifier |= uid[1]; cardidentifier <<= 8; cardidentifier |= uid[0]; Serial.print("Card Number "); Serial.print(cardidentifier); Serial.print(": "); if(cardidentifier == Group1) //Flash Red LED { response1(); delay(10000); } else if(cardidentifier == Group2) //Flash Yellow LED { response2(); delay(15000); } else //Flash both LEDs 3 times { noGroup(); } // Pause before reading another card delay(3000); } } else { Serial.println("Ooops ... authentication failed: Try another key?"); } } delay(1000); nodePayload[0] = NODE_ADDRESS; // Sending Node address back. nodePayload[1] = 0; // } void response1() //Tag Group 1 { digitalWrite(8, HIGH); Serial.println("GROUP 1!!!"); Serial.println(); nodePayload[0] = NODE_ADDRESS; // Sending Node address back. nodePayload[1] = 1; // Send Tag Group number delay(1000); } void response2() //Tag Group 2 { digitalWrite(7, HIGH); |
Slave Board 2: Searching for RFID tags on the other side (Arduino Uno)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#include <MFRC522.h> #include <SPI.h> #include <Wire.h> // Include the required Wire library for I2C#include <Wire.h #define SAD 10 #define RST 5 MFRC522 nfc(SAD, RST); #define NODE_ADDRESS 3 // Change this unique address for each I2C slave node #define PAYLOAD_SIZE 2 // Number of bytes expected to be received by the master I2C node byte keyA[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; byte keyB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; byte FoundTag; // Variable used to check if Tag was found byte ReadTag; // Variable used to store anti-collision value to read Tag information byte TagData[MAX_LEN]; // Variable used to store Full Tag Data byte TagSerialNumber[5]; // Variable used to store only Tag Serial Number byte TagGroup1[5] = {0x07, 0x1D, 0xF2, 0x64}; // Group 1 byte TagGroup2[5] = {0x96, 0xDE, 0x00, 0x1A}; // Group 2 byte nodePayload[PAYLOAD_SIZE]; void setup() { SPI.begin(); Serial.begin(115200); Serial.println("Looking for MFRC522."); nfc.begin(); // Get the firmware version of the RFID chip byte version = nfc.getFirmwareVersion(); if (! version) { Serial.print("Didn't find MFRC522 board."); while(1); //halt } Serial.print("Found chip MFRC522 "); Serial.print("Firmware ver. 0x"); Serial.print(version, HEX); Serial.println("."); Serial.println("SLAVE SENDER NODE"); Serial.print("Node address: "); Serial.println(NODE_ADDRESS); Serial.print("Payload size: "); Serial.println(PAYLOAD_SIZE); Serial.println("***********************"); Wire.begin(NODE_ADDRESS); // Activate I2C network Wire.onRequest(requestEvent); // Request attention of master node } void loop() { byte status; byte data[MAX_LEN]; byte serial[5]; int i, j, pos; status = nfc.requestTag(MF1_REQIDL, data); // if tag will respond MI_OK if (status == MI_OK) { Serial.println("Tag detected."); Serial.print("Type: "); Serial.print(data[0], HEX); Serial.print(", "); Serial.println(data[1], HEX); // calculate the anti-collision value for the currently detected // tag and write the serial into the data array. status = nfc.antiCollision(data); memcpy(serial, data, 5); Serial.println("The serial nb of the tag is:"); for (i = 0; i < 3; i++) { Serial.print(serial[i], HEX); Serial.print(", "); } Serial.println(serial[3], HEX); int TagGroup= 0; // Variable used to confirm good Tag Detected // Get anti-collision value to properly read information from the Tag ReadTag = nfc.antiCollision(TagData); memcpy(TagSerialNumber, TagData, 4); // Write the Tag information in the TagSerialNumber variable Serial.println("Tag detected."); Serial.print("Serial Number: "); for (int i = 0; i < 4; i++) { // Loop to print serial number to serial monitor Serial.print(TagSerialNumber[i], HEX); Serial.print(", "); } Serial.println(""); Serial.println(); // Group 1 Tag Serial Number check for(int i=0; i < 4; i++){ if (TagGroup1[i] != TagSerialNumber[i]) { break; // if not equal, then break out of the "for" loop } if (i == 3) { // if we made it to 4 loops then the Tag Serial numbers are matching TagGroup=1; } } //Group 2 Tag Serial Number check for(int i=0; i < 4; i++){ if (TagGroup2[i] != TagSerialNumber[i]) { break; // if not equal, then break out of the "for" loop } if (i == 3) { // if we made it to 4 loops then the Tag Serial numbers are matching TagGroup=2; } } // Send signal back to large RFID sensor if (TagGroup == 1){ Serial.println("GROUP 1!!!"); Serial.println(); nodePayload[0] = NODE_ADDRESS; // Sending Node address back. nodePayload[1] = TagGroup; // Send Tag Group number Serial.print("Node Address: "); Serial.println(NODE_ADDRESS); Serial.print("Tag Group: "); Serial.println(TagGroup); delay(10000); } else if (TagGroup == 2){ Serial.println("Group 2!!"); Serial.println(); nodePayload[0] = NODE_ADDRESS; // Sending Node address back. nodePayload[1] = TagGroup; // Send Tag Group number Serial.print("Node Address: "); Serial.println(NODE_ADDRESS); Serial.print("Tag Group: "); Serial.println(TagGroup); delay(10000); } delay(500); } delay(1000); nodePayload[0] = NODE_ADDRESS; // Sending Node address back. nodePayload[1] = 0; // Serial.println("otherwise 0"); } void requestEvent() { Wire.write(nodePayload,PAYLOAD_SIZE); Serial.print("Tag Group: "); // for debugging purposes. Serial.println(nodePayload[1]); // for debugging purposes. } |
Check out our previous Tutorials for the project if you would like to see how each Arduino part works.