Skip to content

Commit 6195e59

Browse files
Update arduino_code.ino
1 parent 439fa04 commit 6195e59

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

arduino/arduino_code/arduino_code.ino

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
#include <MFRC522.h>
33
#include <Keypad.h>
44
#include <SPI.h>
5+
#include <LiquidCrystal.h>
56

67
// RFID
7-
#define SS_PIN 10
8-
#define RST_PIN 9
9-
#define solenoidPin 11
8+
#define SS_PIN 6
9+
#define RST_PIN 5
10+
#define solenoidPin 4
1011
MFRC522 rfid(SS_PIN, RST_PIN);
1112

13+
const int rs = 12; // Digital Pin 12
14+
const int en = 11; // Digital Pin 11
15+
const int d6 = 10; // Digital Pin 10
16+
const int d4 = 9; // Digital Pin 9
17+
const int d5 = 8; // Digital Pin 8
18+
const int d7 = 7; // Digital Pin 7
19+
1220
// Keypad
1321
const byte ROWS = 4; // Four rows
1422
const byte COLS = 3; // Three columns
@@ -22,17 +30,21 @@ byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
2230
byte colPins[COLS] = {5, 4, 3}; // Connect to the column pinouts of the keypad
2331
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
2432

25-
// Kullanıcı RFID kartları ve şifreler
33+
// Users RFID PASSWORD NAME
2634
String validCards[] = {"CARD1_UID", "CARD2_UID"};
2735
String userPasswords[] = {"1234", "5678"};
2836
String userNames[] = {"X", "Y"};
2937

38+
// LCD
39+
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
40+
3041
String enteredPassword = "";
3142

3243
void setup() {
3344
Serial.begin(115200);
3445
SPI.begin();
3546
rfid.PCD_Init();
47+
lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines, turn on backlight
3648
}
3749

3850
void loop() {
@@ -53,6 +65,7 @@ void loop() {
5365
if (isValidCard(cardUID)) {
5466
String user = getUserByCard(cardUID);
5567
openDoor();
68+
displayGreeting(user, cardUID);
5669
Serial.print("Hello ");
5770
Serial.println(user);
5871
sendResultToJetson("Hello " + user);
@@ -67,6 +80,7 @@ void loop() {
6780
if (isValidPassword(enteredPassword)) {
6881
String user = getUserByPassword(enteredPassword);
6982
openDoor();
83+
displayGreeting(user, "PASSWORD");
7084
Serial.print("Hello ");
7185
Serial.println(user);
7286
sendResultToJetson("Hello " + user);
@@ -115,13 +129,21 @@ String getUserByPassword(String password) {
115129
}
116130

117131
void openDoor() {
118-
119132
digitalWrite(solenoidPin, HIGH);
120-
sleep(1);
133+
delay(1000); // 1 second delay
134+
digitalWrite(solenoidPin, LOW);
121135
}
122136

123137
void sendResultToJetson(String message) {
124138
Serial.print("RESULT:");
125139
Serial.println(message);
126140
}
127141

142+
void displayGreeting(String user, String identifier) {
143+
lcd.clear();
144+
lcd.setCursor(0, 0);
145+
lcd.print("Merhaba ");
146+
lcd.print(user);
147+
lcd.setCursor(0, 1);
148+
lcd.print(identifier);
149+
}

0 commit comments

Comments
 (0)