Hallo zusammen,
ich brauche für meine H0e Bahn im Schattenbahnhof Gleisbesetztmelder.
Das ganze soll mit dem Arduino und RFID Scanner aufgebaut werden.
Ich habe auch schon einmal einen Sketch so verändert das ich mehrere Züge einscannen kann und die auch kurzzeitig auf einem LCD Display anzeigen kann. Bleibt der Zug genau auf dem Scanner stehen habe ich eine Gleisbesetztanzeige mit Zugerkennung.
Leider habe ich noch nichts brauchbares gefunden um einen Zug in das Abstellgleis einfahrend ein zu scannen und dann beim verlassen die Anzeige von Gleis Besetzt auf Gleis frei zu schalten.
Hat einer von Euch da etwas mehr Erfahrung?
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
// Include required libraries
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
// Create instances
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
String tagUID = "49 5E 24 A3"; // String to store UID of tag. Change it with your tag's UID
String tagUID1 = "1C 65 24 A3"; // String to store UID of tag. Change it with your tag's UID
String tagUID2 = "04 BD EA 0A 37 60 80"; // Zug 1 Ruebenzug001
String tagUID3 = "04 FD EA 0A 37 60 80"; // Zug 2 China PZ001 kurz
String tagUID4 = "49 5E 24 AA"; // Zug3
String tagUID5 = "1C 65 24 AB"; // Zug4
String tagUID6 = "49 5E 24 AC"; // Zug5
String tagUID7 = "1C 65 24 AD"; // Zug6
String tagUID8 = "49 5E 24 AE"; // Zug7
String tagUID9 = "1C 65 24 AF"; // Zug8
String tagUID10 = "49 5E 24 AG"; // Zug9
String tagUID11 = "1C 65 24 AH"; // Zug10
String tagUID12 = "49 5E 24 AI"; // Zug11
String tagUID13 = "1C 65 24 AJ"; // Zug12
String tagUID14= "49 5E 24 AK"; // Zug 13
String tagUID15 = "1C 65 24 AL"; // Zug 14
String tagUID16 = "1C 65 24 AM"; // Zug 15
void setup() {
// Arduino Pin configuration
lcd.begin(); // LCD screen
lcd.backlight();
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
lcd.clear();
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(" GLEIS 1 SBH001");// Freies GLEIS SCHATTENBAHNHOF001 SHB!!!
lcd.setCursor(0, 1);
lcd.print(" GLEIS 1 frei! ");
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
//Reading from the card
String tag = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
tag.concat(String(mfrc522.uid.uidByte[i], HEX));
}
tag.toUpperCase();
//Checking the card
if (tag.substring(1) == tagUID) // ANFANG lesen SCHLÜSSELANHÄNGER1
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("SCHLUESSEL 001");
delay(10000); delay(3000);
lcd.clear();
}
tag.toUpperCase();
//Checking the card
if (tag.substring(1) == tagUID1) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 1
//Checking the card
if (tag.substring(1) == tagUID2) //Anfang lesen Rübenzug 001
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("GZ Ruebenzug 001");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 2
//Checking the card
if (tag.substring(1) == tagUID3) //Anfang lesen PZ Kurz CHINA
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("PZ kurz 001");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 3
//Checking the card
if (tag.substring(1) == tagUID4) //Anfang lesen WEM PZ 001
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("WEM PZ 001");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 4
//Checking the card
if (tag.substring(1) == tagUID5) //Anfang lesen WEM PZ 002
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("WEM PZ 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 5
//Checking the card
if (tag.substring(1) == tagUID6) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 6
//Checking the card
if (tag.substring(1) == tagUID7) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 7
//Checking the card
if (tag.substring(1) == tagUID8) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 8
//Checking the card
if (tag.substring(1) == tagUID9) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zu9
//Checking the card
if (tag.substring(1) == tagUID10) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 10
//Checking the card
if (tag.substring(1) == tagUID11) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 11
//Checking the card
if (tag.substring(1) == tagUID12) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 12
//Checking the card
if (tag.substring(1) == tagUID13) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase(); // Zug 13
//Checking the card
if (tag.substring(1) == tagUID14) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 14
//Checking the card
if (tag.substring(1) == tagUID15) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
tag.toUpperCase();// Zug 15
//Checking the card
if (tag.substring(1) == tagUID16) //Anfang lesen SCHLÜSSELANHÄNGER2
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("GLEIS 1 besetzt");
lcd.setCursor(0, 1);
lcd.print("Schluessel 002");
delay(10000);// der Zug muss auf dem Scanner stehen bleiben!
lcd.clear();
}
}
Einen Resetschalter noch in den Sketch einzubinden ist nicht das Problem.
Nun bin ich gespannt was Euch dazu einfällt.
Bis bald Gruß
Karsten