Components and supplies
Transceiver RS422, RS485
Screw terminal 2P 2.54mm
Master PCB
RGB LCD Shield Kit, 16x2 Character Display
28 dip socket
RFID MFRC-522 Module
Capacitor 22 pF
Resistor 10k ohm
Real Time Clock (RTC)
Capacitor 100 nF
Pin Header 1x5 Female 2.54mm
Arduino USB 2 Serial micro
32.768 kHz Crystal
Capacitor 10 µF
Coin Cell Battery CR2032
Slave PCB
Arduino UNO
16 MHz Crystal
ATmega328
Single Turn Potentiometer- 10k ohms
Tools and machines
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Solder Wire, Lead Free
Breadboard, 270 Pin
Apps and platforms
Arduino IDE
Project description
Code
Master
c_cpp
Code for the master station unit. The "Master Station" is responsible for the communication between "Slave stations" via RS485 data bus. It also communicate via serial port with the software that is running to "control room" computer.
1#include <SPI.h> 2#include <SoftwareSerial.h> 3#include <MFRC522.h> 4#include <Wire.h> 5//Buzzer 6#define buzzer 8 7//RS485 8#define rs485_RX A0 9#define rs485_TX A1 10#define rs485_DE A2 11#define rs485_RE A3 12SoftwareSerial rs485(rs485_RX, rs485_TX); // RX, TX 13String MASTER_PORT = "FF"; 14String newCard=""; 15//RFID 16#define SS_PIN 10 17#define RST_PIN 9 18MFRC522 mfrc522(SS_PIN, RST_PIN); 19 20char incomingByte; 21String command; 22boolean messageCompleted = false; 23boolean newMessage = false; 24 25void setup() { 26 pinMode(rs485_RE, OUTPUT); 27 pinMode(rs485_DE, OUTPUT); 28 digitalWrite(rs485_RE, LOW); 29 digitalWrite(rs485_DE, LOW); 30 Serial.begin(9600); 31 rs485.begin(19200); 32 SPI.begin(); // Initiate SPI bus 33 mfrc522.PCD_Init(); // Initiate MFRC522 34} 35 36void loop() { 37 serialCommunication(); 38 readCard(); 39 rs485Communication(); 40} 41void readCard() { 42 if ( ! mfrc522.PICC_IsNewCardPresent()) 43 { 44 return; 45 } 46 // Select one of the cards 47 if ( ! mfrc522.PICC_ReadCardSerial()) 48 { 49 return; 50 } 51 //Show UID on serial monitor 52 String card = ""; 53 for (byte i = 0; i < mfrc522.uid.size; i++) 54 { 55 card.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 56 card.concat(String(mfrc522.uid.uidByte[i], HEX)); 57 } 58 card.toUpperCase(); 59 card = card.substring(1); 60 card.replace(" ", ""); 61 newCard = card; 62 tone(buzzer,500,300); 63} 64void serialCommunication() { 65 if (rs485.available()) { 66 incomingByte = rs485.read(); 67 if (incomingByte == '>') { 68 messageCompleted = true; 69 newMessage = false; 70 } 71 else if (incomingByte == '<') { 72 newMessage = true; 73 } 74 75 if (newMessage) { 76 command.concat(incomingByte); 77 } 78 } 79 80 if (messageCompleted) { 81 if (command.substring(1, 3) == MASTER_PORT) { 82 if (command.charAt(3) == 't') { 83 Serial.println(command.substring(4)); 84 } 85 else if (command.charAt(3) == 'c') { 86 String index = command.substring(4,5); 87 String card = command.substring(5); 88 card.replace("xxxxxxxx","NOT SET"); 89 Serial.println(index+": "+card); 90 } 91 //Report last check to master - time and card id 92 else if (command.charAt(3) == 'r') { 93 Serial.println(command.substring(4)); 94 } 95 } 96 command = ""; 97 messageCompleted = false; 98 } 99} 100void rs485Communication(){ 101 if (Serial.available()) { 102 incomingByte = Serial.read(); 103 if (incomingByte == '>') { 104 messageCompleted = true; 105 newMessage = false; 106 } 107 else if (incomingByte == '<') { 108 newMessage = true; 109 } 110 111 if (newMessage) { 112 command.concat(incomingByte); 113 } 114 } 115 if (messageCompleted) { 116 if (command.substring(1, 3) != MASTER_PORT) { 117 digitalWrite(rs485_DE,HIGH); 118 rs485.print(command+">"); 119 } 120 else{ 121 Serial.println(newCard); 122 newCard=""; 123 } 124 command = ""; 125 messageCompleted = false; 126 } 127 digitalWrite(rs485_DE,LOW); 128} 129 130
Slave
c_cpp
Code for the slave station units. Every "Slave Station" - check point unit has a unique address. Edit the variable "PORT" (line 25) with hex value of unit address - value from 01 to FE (total of 254 stations). Also change the "name" of the current station by editing the variable "point" at line 24. Every check point can store to EEPROM memory up to 10 card IDs. If the security card exist, the ID and time-stamp will be saved to EEPROM memory.
1#include <SPI.h> 2#include <MFRC522.h> 3#include <LiquidCrystal.h> 4#include <Wire.h> 5#include "RTClib.h" 6#include <SoftwareSerial.h> 7#include <EEPROM.h> 8 9#define rs485_RX A0 10#define rs485_TX A1 11#define rs485_DE A2 12#define rs485_RE A3 13SoftwareSerial rs485(rs485_RX, rs485_TX); // RX, TX 14 15 16//RFID 17#define SS_PIN 10 18#define RST_PIN 9 19MFRC522 mfrc522(SS_PIN, RST_PIN); 20String cards[10] = {"", "", "", "", "", "", "", "", "", ""}; 21String check; 22String check_card; 23String check_time; 24String point = "Point A"; //Point B, Point C 25String PORT = "01"; //FROM 01,02,03 TO FE - Total of 254 Slave stations 26String MASTER_PORT = "FF"; 27 28//Time 29RTC_DS1307 rtc; 30String currentTime, DD, MM, YYYY, hh, mm; 31 32//LCD 33LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 34 35//Buzzer 36#define buzzer 8 37 38//Serial Communication 39char incomingByte; 40String command; 41boolean messageCompleted = false; 42boolean newMessage = false; 43 44void setup() { 45 pinMode(rs485_RE, OUTPUT); 46 pinMode(rs485_DE, OUTPUT); 47 digitalWrite(rs485_RE, LOW); 48 digitalWrite(rs485_DE, LOW); 49 Serial.begin(9600); // Initiate a serial communication 50 rs485.begin(19200); 51 //RFID 52 SPI.begin(); // Initiate SPI bus 53 mfrc522.PCD_Init(); // Initiate MFRC522 54 55 //RTC 56 if (! rtc.begin()) { 57 Serial.println("Couldn't find RTC"); 58 while (1); 59 } 60 if (! rtc.isrunning()) { 61 Serial.println("RTC is NOT running!"); 62 } 63 64 //LCD 65 lcd.begin(16, 2); 66 67 //Buzzer 68 pinMode(buzzer, OUTPUT); 69 //Read last check from EEPROM memory (card id and timestamp) 70 delay(10); 71 check_card = readFromMemory(0, 8); 72 delay(10); 73 check_time = readFromMemory(10, 16); 74 delay(10); 75 //Read Card id list from memory 76 for (int i = 0; i < 10; i++) { 77 cards[i] = readFromMemory(30 + (i * 10), 8); 78 //storeInMemory(30 + (i*10), "xxxxxxxx"); 79 delay(10); 80 Serial.println(cards[i]); 81 } 82 Serial.println("System is up and running"); 83} 84 85 86void setTime(int YYYY, int MM, int DD, int hh, int mm) { 87 rtc.adjust(DateTime(YYYY, MM, DD, hh, mm, 0)); 88} 89 90void readTime() { 91 //DAY 92 DateTime now = rtc.now(); 93 if (now.day() <= 9) { 94 DD = "0" + String(now.day()); 95 } 96 else { 97 DD = String(now.day()); 98 } 99 100 //MONTH 101 if (now.month() <= 9) { 102 MM = "0" + String(now.month()); 103 } 104 else { 105 MM = String(now.month()); 106 } 107 108 //HOUR 109 if (now.hour() <= 9) { 110 hh = "0" + String(now.hour()); 111 } 112 else { 113 hh = String(now.hour()); 114 } 115 116 //MINUTE 117 if (now.minute() <= 9) { 118 mm = "0" + String(now.minute()); 119 } 120 else { 121 mm = String(now.minute()); 122 } 123 124 //YEAR 125 if (now.year()) { 126 YYYY = String(now.year()); 127 } 128 currentTime = DD + "/" + MM + "/" + YYYY + " " + hh + ":" + mm; 129} 130 131void checkCard() { 132 if ( ! mfrc522.PICC_IsNewCardPresent()) 133 { 134 check = ""; 135 return; 136 } 137 // Select one of the cards 138 if ( ! mfrc522.PICC_ReadCardSerial()) 139 { 140 check = ""; 141 return; 142 } 143 //Show UID on serial monitor 144 String card = ""; 145 for (byte i = 0; i < mfrc522.uid.size; i++) 146 { 147 card.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 148 card.concat(String(mfrc522.uid.uidByte[i], HEX)); 149 } 150 card.toUpperCase(); 151 card = card.substring(1); 152 card.replace(" ", ""); 153 for (int i = 0; i < 10; i++) { 154 if (card == cards[i]) { 155 check = "VALID: " + String(card); 156 check_card = String(card); 157 check_time = currentTime; 158 storeInMemory(0, check_card); //Start store card id from memory addr 0 159 storeInMemory(10, check_time); //Start store time stamp from memory addr 10 160 return; 161 } 162 else { 163 check = "Card Not found..."; 164 } 165 } 166} 167 168void printLCD(String line1, String line2) { 169 lcd.clear(); 170 lcd.setCursor(0, 0); 171 lcd.print(line1); 172 lcd.setCursor(0, 1); 173 lcd.print(line2); 174} 175 176void buzzerTone() { 177 tone(buzzer, 1000); // Send 1KHz sound signal... 178 delay(1000); // ...for 1 sec 179 noTone(buzzer); // Stop sound... 180} 181 182void storeInMemory(char addr, String data) { 183 int _size = data.length(); 184 int i; 185 for (i = 0; i < _size; i++) 186 { 187 EEPROM.write(addr + i, data[i]); 188 } 189 EEPROM.write(addr + _size, '\\0'); //Add termination null character for String Data 190} 191String readFromMemory(char addr, int size) 192{ 193 int i; 194 char data[size + 1]; 195 int len = 0; 196 unsigned char k; 197 k = EEPROM.read(addr); 198 while (len < size) //Read until null character 199 { 200 k = EEPROM.read(addr + len); 201 data[len] = k; 202 len++; 203 } 204 data[len] = '\\0'; 205 return String(data); 206} 207 208void serialCommunication() { 209 if (rs485.available()) { 210 incomingByte = rs485.read(); 211 if (incomingByte == '>') { 212 messageCompleted = true; 213 newMessage = false; 214 } 215 else if (incomingByte == '<') { 216 newMessage = true; 217 } 218 219 if (newMessage) { 220 command.concat(incomingByte); 221 } 222 } 223 224 if (messageCompleted) { 225 if (command.substring(1, 3) == PORT || command.substring(1, 3) == "00" ) { 226 //Set time 227 if (command.charAt(3) == 'T') { 228 int YYYY = (command.substring(4, 8)).toInt(); 229 int MM = (command.substring(8, 10)).toInt(); 230 int DD = (command.substring(10, 12)).toInt(); 231 int hh = (command.substring(12, 14)).toInt(); 232 int mm = (command.substring(14)).toInt(); 233 setTime(YYYY, MM, DD, hh, mm); 234 } 235 //Set cards ids 236 else if (command.charAt(3) == 'C') { 237 int index = (command.substring(4, 5)).toInt(); 238 String id = command.substring(5); 239 cards[index] = id; 240 //Store in memory! 241 storeInMemory(30 + (index * 10), id); //Start store card id from memory addr 30 242 } 243 } 244 if (command.substring(1, 3) == PORT) { 245 //Report time of this slave station to master 246 if (command.charAt(3) == 't') { 247 digitalWrite(rs485_DE, HIGH); 248 rs485.println("<" + MASTER_PORT + "t" + currentTime + ">"); 249 digitalWrite(rs485_DE, LOW); 250 } 251 //Report card ids of this slave station to master 252 else if (command.charAt(3) == 'c') { 253 int index = (command.substring(4,5)).toInt(); 254 String MSG = "<" + MASTER_PORT + "c"+String(index); 255 MSG += cards[index] + ">"; 256 digitalWrite(rs485_DE, HIGH); 257 rs485.println(MSG); 258 digitalWrite(rs485_DE, LOW); 259 } 260 //Report last check to master - time and card id 261 else if (command.charAt(3) == 'r') { 262 digitalWrite(rs485_DE, HIGH); 263 rs485.println("<" + MASTER_PORT + "r" + check_card + " " + check_time + ">"); 264 digitalWrite(rs485_DE, LOW); 265 } 266 } 267 command = ""; 268 messageCompleted = false; 269 } 270} 271void loop() { 272 serialCommunication(); 273 checkCard(); 274 printLCD("Waiting for Card", point); 275 readTime(); 276 if (check != "") { 277 printLCD(currentTime, check); 278 buzzerTone(); 279 delay(2000); 280 } 281} 282 283
Master
c_cpp
Code for the master station unit. The "Master Station" is responsible for the communication between "Slave stations" via RS485 data bus. It also communicate via serial port with the software that is running to "control room" computer.
1#include <SPI.h> 2#include <SoftwareSerial.h> 3#include <MFRC522.h> 4#include <Wire.h> 5//Buzzer 6#define buzzer 8 7//RS485 8#define rs485_RX A0 9#define rs485_TX A1 10#define rs485_DE A2 11#define rs485_RE A3 12SoftwareSerial rs485(rs485_RX, rs485_TX); // RX, TX 13String MASTER_PORT = "FF"; 14String newCard=""; 15//RFID 16#define SS_PIN 10 17#define RST_PIN 9 18MFRC522 mfrc522(SS_PIN, RST_PIN); 19 20char incomingByte; 21String command; 22boolean messageCompleted = false; 23boolean newMessage = false; 24 25void setup() { 26 pinMode(rs485_RE, OUTPUT); 27 pinMode(rs485_DE, OUTPUT); 28 digitalWrite(rs485_RE, LOW); 29 digitalWrite(rs485_DE, LOW); 30 Serial.begin(9600); 31 rs485.begin(19200); 32 SPI.begin(); // Initiate SPI bus 33 mfrc522.PCD_Init(); // Initiate MFRC522 34} 35 36void loop() { 37 serialCommunication(); 38 readCard(); 39 rs485Communication(); 40} 41void readCard() { 42 if ( ! mfrc522.PICC_IsNewCardPresent()) 43 { 44 return; 45 } 46 // Select one of the cards 47 if ( ! mfrc522.PICC_ReadCardSerial()) 48 { 49 return; 50 } 51 //Show UID on serial monitor 52 String card = ""; 53 for (byte i = 0; i < mfrc522.uid.size; i++) 54 { 55 card.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 56 card.concat(String(mfrc522.uid.uidByte[i], HEX)); 57 } 58 card.toUpperCase(); 59 card = card.substring(1); 60 card.replace(" ", ""); 61 newCard = card; 62 tone(buzzer,500,300); 63} 64void serialCommunication() { 65 if (rs485.available()) { 66 incomingByte = rs485.read(); 67 if (incomingByte == '>') { 68 messageCompleted = true; 69 newMessage = false; 70 } 71 else if (incomingByte == '<') { 72 newMessage = true; 73 } 74 75 if (newMessage) { 76 command.concat(incomingByte); 77 } 78 } 79 80 if (messageCompleted) { 81 if (command.substring(1, 3) == MASTER_PORT) { 82 if (command.charAt(3) == 't') { 83 Serial.println(command.substring(4)); 84 } 85 else if (command.charAt(3) == 'c') { 86 String index = command.substring(4,5); 87 String card = command.substring(5); 88 card.replace("xxxxxxxx","NOT SET"); 89 Serial.println(index+": "+card); 90 } 91 //Report last check to master - time and card id 92 else if (command.charAt(3) == 'r') { 93 Serial.println(command.substring(4)); 94 } 95 } 96 command = ""; 97 messageCompleted = false; 98 } 99} 100void rs485Communication(){ 101 if (Serial.available()) { 102 incomingByte = Serial.read(); 103 if (incomingByte == '>') { 104 messageCompleted = true; 105 newMessage = false; 106 } 107 else if (incomingByte == '<') { 108 newMessage = true; 109 } 110 111 if (newMessage) { 112 command.concat(incomingByte); 113 } 114 } 115 if (messageCompleted) { 116 if (command.substring(1, 3) != MASTER_PORT) { 117 digitalWrite(rs485_DE,HIGH); 118 rs485.print(command+">"); 119 } 120 else{ 121 Serial.println(newCard); 122 newCard=""; 123 } 124 command = ""; 125 messageCompleted = false; 126 } 127 digitalWrite(rs485_DE,LOW); 128} 129 130
Slave
c_cpp
Code for the slave station units. Every "Slave Station" - check point unit has a unique address. Edit the variable "PORT" (line 25) with hex value of unit address - value from 01 to FE (total of 254 stations). Also change the "name" of the current station by editing the variable "point" at line 24. Every check point can store to EEPROM memory up to 10 card IDs. If the security card exist, the ID and time-stamp will be saved to EEPROM memory.
1#include <SPI.h> 2#include <MFRC522.h> 3#include <LiquidCrystal.h> 4#include <Wire.h> 5#include "RTClib.h" 6#include <SoftwareSerial.h> 7#include <EEPROM.h> 8 9#define rs485_RX A0 10#define rs485_TX A1 11#define rs485_DE A2 12#define rs485_RE A3 13SoftwareSerial rs485(rs485_RX, rs485_TX); // RX, TX 14 15 16//RFID 17#define SS_PIN 10 18#define RST_PIN 9 19MFRC522 mfrc522(SS_PIN, RST_PIN); 20String cards[10] = {"", "", "", "", "", "", "", "", "", ""}; 21String check; 22String check_card; 23String check_time; 24String point = "Point A"; //Point B, Point C 25String PORT = "01"; //FROM 01,02,03 TO FE - Total of 254 Slave stations 26String MASTER_PORT = "FF"; 27 28//Time 29RTC_DS1307 rtc; 30String currentTime, DD, MM, YYYY, hh, mm; 31 32//LCD 33LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 34 35//Buzzer 36#define buzzer 8 37 38//Serial Communication 39char incomingByte; 40String command; 41boolean messageCompleted = false; 42boolean newMessage = false; 43 44void setup() { 45 pinMode(rs485_RE, OUTPUT); 46 pinMode(rs485_DE, OUTPUT); 47 digitalWrite(rs485_RE, LOW); 48 digitalWrite(rs485_DE, LOW); 49 Serial.begin(9600); // Initiate a serial communication 50 rs485.begin(19200); 51 //RFID 52 SPI.begin(); // Initiate SPI bus 53 mfrc522.PCD_Init(); // Initiate MFRC522 54 55 //RTC 56 if (! rtc.begin()) { 57 Serial.println("Couldn't find RTC"); 58 while (1); 59 } 60 if (! rtc.isrunning()) { 61 Serial.println("RTC is NOT running!"); 62 } 63 64 //LCD 65 lcd.begin(16, 2); 66 67 //Buzzer 68 pinMode(buzzer, OUTPUT); 69 //Read last check from EEPROM memory (card id and timestamp) 70 delay(10); 71 check_card = readFromMemory(0, 8); 72 delay(10); 73 check_time = readFromMemory(10, 16); 74 delay(10); 75 //Read Card id list from memory 76 for (int i = 0; i < 10; i++) { 77 cards[i] = readFromMemory(30 + (i * 10), 8); 78 //storeInMemory(30 + (i*10), "xxxxxxxx"); 79 delay(10); 80 Serial.println(cards[i]); 81 } 82 Serial.println("System is up and running"); 83} 84 85 86void setTime(int YYYY, int MM, int DD, int hh, int mm) { 87 rtc.adjust(DateTime(YYYY, MM, DD, hh, mm, 0)); 88} 89 90void readTime() { 91 //DAY 92 DateTime now = rtc.now(); 93 if (now.day() <= 9) { 94 DD = "0" + String(now.day()); 95 } 96 else { 97 DD = String(now.day()); 98 } 99 100 //MONTH 101 if (now.month() <= 9) { 102 MM = "0" + String(now.month()); 103 } 104 else { 105 MM = String(now.month()); 106 } 107 108 //HOUR 109 if (now.hour() <= 9) { 110 hh = "0" + String(now.hour()); 111 } 112 else { 113 hh = String(now.hour()); 114 } 115 116 //MINUTE 117 if (now.minute() <= 9) { 118 mm = "0" + String(now.minute()); 119 } 120 else { 121 mm = String(now.minute()); 122 } 123 124 //YEAR 125 if (now.year()) { 126 YYYY = String(now.year()); 127 } 128 currentTime = DD + "/" + MM + "/" + YYYY + " " + hh + ":" + mm; 129} 130 131void checkCard() { 132 if ( ! mfrc522.PICC_IsNewCardPresent()) 133 { 134 check = ""; 135 return; 136 } 137 // Select one of the cards 138 if ( ! mfrc522.PICC_ReadCardSerial()) 139 { 140 check = ""; 141 return; 142 } 143 //Show UID on serial monitor 144 String card = ""; 145 for (byte i = 0; i < mfrc522.uid.size; i++) 146 { 147 card.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); 148 card.concat(String(mfrc522.uid.uidByte[i], HEX)); 149 } 150 card.toUpperCase(); 151 card = card.substring(1); 152 card.replace(" ", ""); 153 for (int i = 0; i < 10; i++) { 154 if (card == cards[i]) { 155 check = "VALID: " + String(card); 156 check_card = String(card); 157 check_time = currentTime; 158 storeInMemory(0, check_card); //Start store card id from memory addr 0 159 storeInMemory(10, check_time); //Start store time stamp from memory addr 10 160 return; 161 } 162 else { 163 check = "Card Not found..."; 164 } 165 } 166} 167 168void printLCD(String line1, String line2) { 169 lcd.clear(); 170 lcd.setCursor(0, 0); 171 lcd.print(line1); 172 lcd.setCursor(0, 1); 173 lcd.print(line2); 174} 175 176void buzzerTone() { 177 tone(buzzer, 1000); // Send 1KHz sound signal... 178 delay(1000); // ...for 1 sec 179 noTone(buzzer); // Stop sound... 180} 181 182void storeInMemory(char addr, String data) { 183 int _size = data.length(); 184 int i; 185 for (i = 0; i < _size; i++) 186 { 187 EEPROM.write(addr + i, data[i]); 188 } 189 EEPROM.write(addr + _size, '\\0'); //Add termination null character for String Data 190} 191String readFromMemory(char addr, int size) 192{ 193 int i; 194 char data[size + 1]; 195 int len = 0; 196 unsigned char k; 197 k = EEPROM.read(addr); 198 while (len < size) //Read until null character 199 { 200 k = EEPROM.read(addr + len); 201 data[len] = k; 202 len++; 203 } 204 data[len] = '\\0'; 205 return String(data); 206} 207 208void serialCommunication() { 209 if (rs485.available()) { 210 incomingByte = rs485.read(); 211 if (incomingByte == '>') { 212 messageCompleted = true; 213 newMessage = false; 214 } 215 else if (incomingByte == '<') { 216 newMessage = true; 217 } 218 219 if (newMessage) { 220 command.concat(incomingByte); 221 } 222 } 223 224 if (messageCompleted) { 225 if (command.substring(1, 3) == PORT || command.substring(1, 3) == "00" ) { 226 //Set time 227 if (command.charAt(3) == 'T') { 228 int YYYY = (command.substring(4, 8)).toInt(); 229 int MM = (command.substring(8, 10)).toInt(); 230 int DD = (command.substring(10, 12)).toInt(); 231 int hh = (command.substring(12, 14)).toInt(); 232 int mm = (command.substring(14)).toInt(); 233 setTime(YYYY, MM, DD, hh, mm); 234 } 235 //Set cards ids 236 else if (command.charAt(3) == 'C') { 237 int index = (command.substring(4, 5)).toInt(); 238 String id = command.substring(5); 239 cards[index] = id; 240 //Store in memory! 241 storeInMemory(30 + (index * 10), id); //Start store card id from memory addr 30 242 } 243 } 244 if (command.substring(1, 3) == PORT) { 245 //Report time of this slave station to master 246 if (command.charAt(3) == 't') { 247 digitalWrite(rs485_DE, HIGH); 248 rs485.println("<" + MASTER_PORT + "t" + currentTime + ">"); 249 digitalWrite(rs485_DE, LOW); 250 } 251 //Report card ids of this slave station to master 252 else if (command.charAt(3) == 'c') { 253 int index = (command.substring(4,5)).toInt(); 254 String MSG = "<" + MASTER_PORT + "c"+String(index); 255 MSG += cards[index] + ">"; 256 digitalWrite(rs485_DE, HIGH); 257 rs485.println(MSG); 258 digitalWrite(rs485_DE, LOW); 259 } 260 //Report last check to master - time and card id 261 else if (command.charAt(3) == 'r') { 262 digitalWrite(rs485_DE, HIGH); 263 rs485.println("<" + MASTER_PORT + "r" + check_card + " " + check_time + ">"); 264 digitalWrite(rs485_DE, LOW); 265 } 266 } 267 command = ""; 268 messageCompleted = false; 269 } 270} 271void loop() { 272 serialCommunication(); 273 checkCard(); 274 printLCD("Waiting for Card", point); 275 readTime(); 276 if (check != "") { 277 printLCD(currentTime, check); 278 buzzerTone(); 279 delay(2000); 280 } 281} 282 283
Downloadable files
Circuit Schematic
Circuit Schematic
Documentation
PCB Schematic
PCB Schematic
PCB Schematic
PCB Schematic
Comments
Only logged in users can leave comments