Components and supplies
Kinect Sensor
Arduino Mega 2560
RFID reader (generic)
Project description
Code
RFID Detection
arduino
This code runs on the Arduno Mega inside the RFID-reading pedestal. It detects RFID tags put ("PUT" via Serial) on and taken ("TKN") off each of the three RFID readers connected to it.
1unsigned long pulse_width; 2 3int ledPin1 = 2; 4int ledPin2 = 3; 5int ledPin3 = 4; 6int ledPin4 = 5; 7int ledPin5 = 6; 8 9/* 10int vibPin = 7; 11 12int pirPin1 = 8; 13int pirPin2 = 9; 14int pirPin3 = 10; 15int pirPin4 = 11; 16int pirPin5 = 12; 17*/ 18 19int triggerPin = 7; 20int monitorPin = 8; 21 22 23void setup() { 24 25 delay(250); 26 Serial.begin(9600); 27 Serial1.begin(9600); 28 Serial2.begin(9600); 29 Serial3.begin(9600); 30 31 delay(250); 32 33/* 34 pinMode(vibPin,OUTPUT); // vibration motor 35 36 pinMode(pirPin1,INPUT); // PIR 1 37 pinMode(pirPin2,INPUT); // PIR 2 38 pinMode(pirPin3,INPUT); // PIR 3 39 pinMode(pirPin4,INPUT); // PIR 4 40 pinMode(pirPin5,INPUT); // PIR 5 41 */ 42 43 pinMode(ledPin1,OUTPUT); 44 45 pinMode(triggerPin, OUTPUT); 46 pinMode(monitorPin, INPUT); 47 digitalWrite(triggerPin, LOW); 48 49 50 digitalWrite(ledPin1,LOW); 51 52// Serial.println("Datatouch 0.5"); 53 54} 55 56String id1 = ""; 57String id2 = ""; 58String id3 = ""; 59 60String old_id1 = ""; 61String very_old_id1 = ""; 62String old_id2 = ""; 63String very_old_id2 = ""; 64String old_id3 = ""; 65String very_old_id3 = ""; 66 67void touchDown() { 68 69/* 70 digitalWrite(vibPin, HIGH); 71 delay(200); 72 digitalWrite(vibPin, LOW); 73*/ 74} 75 76 77void pickUp() { 78 79/* 80 digitalWrite(vibPin, HIGH); 81 delay(50); 82 digitalWrite(vibPin, LOW); 83*/ 84 85} 86 87 88void loop() { 89 90 91pulse_width = pulseIn(monitorPin, HIGH); // Count how long the pulse is high in microseconds 92 if(pulse_width != 0){ // If we get a reading that isn't zero, let's print it 93 pulse_width = pulse_width/10; // 10usec = 1 cm of distance for LIDAR-Lite 94 String s; 95 Serial.println("#DIST:"+String(pulse_width) + ";"); // Print the distance 96 } 97 98 99// digitalWrite(ledPin1,LOW); 100 101 delay(200); 102 103 104 very_old_id1 = old_id1; 105 old_id1 = id1; 106 id1 = ""; 107 108// Serial.println("voi: "+very_old_id1+"\ | "+"oi: "+old_id1+"\ | "+"i: "+id1+" * "); 109 110 111 while (Serial1.available() > 0) { 112 byte inByte = (byte)Serial1.read(); 113 id1 = id1 + inByte; 114 } 115 if (id1.length() > 8) { 116 Serial.flush(); 117 118 if ((very_old_id1 == "") && (old_id1 == "")) { 119 Serial.println("#RFID1:"+id1+" PUT;"); 120 touchDown(); 121 } 122 123 } 124 125 if ((very_old_id1.length() > 8) && (old_id1 == "") && (id1 == "")) { 126 Serial.println("#RFID1:"+very_old_id1+" TKN;"); 127 pickUp(); 128 } 129 130 131 very_old_id2 = old_id2; 132 old_id2 = id2; 133 id2 = ""; 134 135 //Serial.println("voi: "+very_old_id2+"\ | "+"oi: "+old_id2+"\ | "+"i: "+id2+" * "); 136 137 while (Serial2.available() > 0) { 138 byte inByte = (byte)Serial2.read(); 139 id2 = id2 + inByte; 140 } 141 if (id2.length() > 8) { 142 Serial.flush(); 143 144 if ((very_old_id2 == "") && (old_id2 == "")) { 145 Serial.println("#RFID2:"+id2+" PUT;"); 146 touchDown(); 147 } 148 149 } 150 151 if ((very_old_id2.length() > 8) && (old_id2 == "") && (id2 == "")) { 152 Serial.println("#RFID2:"+very_old_id2+" TKN;"); 153 pickUp(); 154 } 155 156 157 very_old_id3 = old_id3; 158 old_id3 = id3; 159 id3 = ""; 160 161 //Serial.println("voi: "+very_old_id3+"\ | "+"oi: "+old_id3+"\ | "+"i: "+id3+" * "); 162 163 while (Serial3.available() > 0) { 164 byte inByte = (byte)Serial3.read(); 165 id3 = id3 + inByte; 166 } 167 if (id3.length() > 8) { 168 Serial.flush(); 169 170 if ((very_old_id3 == "") && (old_id3 == "")) { 171 Serial.println("#RFID3:"+id3+" PUT;"); 172 touchDown(); 173 } 174 175 } 176 177 if ((very_old_id3.length() > 8) && (old_id3 == "") && (id3 == "")) { 178 Serial.println("#RFID3:"+very_old_id3+" TKN;"); 179 pickUp(); 180 } 181 182 183 184if (millis() > 10000) { 185 //delay(100000); 186} 187 188 189} 190 191
Comments
Only logged in users can leave comments