HELP how will i integrate this code into this code, I am planning to open the lock from the otherside of the door using serial monitor from my laptop

Integrating this code

String door = "";
void setup() {  
   Serial.begin(9600);  
 
}  
 
 
void loop() {  
   
Serial.println("Enter door pass");  
 
 while (Serial.available()==0)  
 {                                       //Wait for user input  
   
 }  
 door = Serial.readString();

if (door=="open")
{
        lcd.clear();
        lcd.print("Pass Accepted");
        sg90.write(90); // Door Opened
        digitalWrite(greenLed, HIGH);
        delay(3000);
        digitalWrite(greenLed, LOW);
        sg90.write(0); // Door Closed
        lcd.clear();
        i = 0;
        RFIDMode = true;
 
 }
 else{
   
   
   
   }
}

Into this code

// Include required libraries
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
#include <SPI.h>

// Create instances
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo sg90;

// Initialize Pins for led's, servo and buzzer
// Blue LED is connected to 5V
constexpr uint8_t greenLed = 7;
constexpr uint8_t redLed = 6;
constexpr uint8_t servoPin = 8;
constexpr uint8_t buzzerPin = 5;

char initial_password[4] = {'1', '2', '3', '4'};  // Variable to store initial password
String tagUID = "C0 C4 07 21";
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
String NAME;



char password[4];   // Variable to store users password
boolean RFIDMode = true; // boolean to change modes
char key_pressed = 0; // Variable to store incoming keys
uint8_t i = 0;  // Variable used for counter

// defining how many rows and columns our keypad have
const byte rows = 4;
const byte columns = 4;

// Keypad pin map
char hexaKeys[rows][columns] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

// Initializing pins for keypad
byte row_pins[rows] = {A0, A1, A2, A3};
byte column_pins[columns] = {2, 4, 3};

// Create instance for keypad
Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns);

void setup() {
Serial.begin(9600);
 Serial.println("CLEARDATA");
  Serial.println("LABEL,Date,Time,RFID UID,NAME");
  
  Serial.println("Scan PICC to see UID...");
  Serial.println("");
  // Arduino Pin configuration
  pinMode(buzzerPin, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  sg90.attach(servoPin);  //Declare pin 8 for servo
  sg90.write(0); // Set initial position at 90 degrees

  lcd.begin();   // LCD screen
  lcd.backlight();
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522

  lcd.clear(); // Clear LCD screen
}

void loop() {
  // System will first look for mode
  if (RFIDMode == true) {
    lcd.setCursor(0, 0);
    lcd.print("   Door Lock");
    lcd.setCursor(0, 1);
    lcd.print(" Scan Your Tag ");

    // 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 j = 0; j < mfrc522.uid.size; j++)
    {
      tag.concat(String(mfrc522.uid.uidByte[j] < 0x10 ? " 0" : " "));
      tag.concat(String(mfrc522.uid.uidByte[j], HEX));
    }
    tag.toUpperCase();

    //Checking the card
    if (tag.substring(1) == "C0 C4 07 21")
    {
      // If UID of tag is matched.
      
      lcd.clear();
      lcd.print("Tag Matched");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(greenLed, HIGH);
      delay(500);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(greenLed, LOW);
       lcd.clear();
      lcd.print("");
      digitalWrite(greenLed, HIGH);
      delay(2000);
      digitalWrite(greenLed, LOW);

      lcd.clear();
      lcd.print("Enter Password:");
      lcd.setCursor(0, 1);
      RFIDMode = false; // Make RFID mode false
      StrUID = "C0 C4 07 21";
      NAME = "";
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
    }

    else if (tag.substring(1) == "A3 51 9A 08")
    {
      // If UID of tag is matched.
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
      lcd.clear();
      lcd.print("Tag Matched");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(greenLed, HIGH);
      delay(500);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(greenLed, LOW);
       lcd.clear();
      lcd.print("");
      digitalWrite(greenLed, HIGH);
      delay(2000);
      digitalWrite(greenLed, LOW);

      lcd.clear();
      lcd.print("Enter Password:");
      lcd.setCursor(0, 1);
      RFIDMode = false; // Make RFID mode false

      StrUID = "A3 51 9A 08";
      NAME = "";
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
    }

    else
    {
      // If UID of tag is not matched.
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Wrong Tag Shown");
      lcd.setCursor(0, 1);
      lcd.print("Access Denied");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(redLed, HIGH);
      delay(3000);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(redLed, LOW);
      lcd.clear();
    }
  }

  // If RFID mode is false, it will look for keys from keypad
  if (RFIDMode == false) {
    key_pressed = keypad_key.getKey(); // Storing keys
    if (key_pressed)
    {
      password[i++] = key_pressed; // Storing in password variable
      lcd.print("*");
    }
    if (i == 4) // If 4 keys are completed
    {
      delay(200);
      if (!(strncmp(password, initial_password, 4))) // If password is matched
      {
        lcd.clear();
        lcd.print("Pass Accepted");
        sg90.write(90); // Door Opened
        digitalWrite(greenLed, HIGH);
        delay(3000);
        digitalWrite(greenLed, LOW);
        sg90.write(0); // Door Closed
        lcd.clear();
        i = 0;
        RFIDMode = true; // Make RFID mode true
      }
      else    // If password is not matched
      {
        lcd.clear();
        lcd.print("Wrong Password");
        digitalWrite(buzzerPin, HIGH);
        digitalWrite(redLed, HIGH);
        delay(3000);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(redLed, LOW);
        lcd.clear();
        i = 0;
        RFIDMode = true;  // Make RFID mode true
      }
    }
  }
}

THANKYOUSOMUCH and god bless

What don't you understand about the request in
SERIAL.BEGIN(9600); stops the overall arduino when typing the password in keypad - #2 by UKHeliBob. Please use code tags when posting code.

Do a search for arduin combining code or arduino merge code.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for advice on (nor for problems with) your project.

About time to show us what you’ve tried.
We don’t usually write your code for you, there a paid sites to do that.

Read the forum guidelines - to help us, and yourself.

does not work :<

@filifili123, what does not work?

Start simple - fix your post and add the tags.

My post was temporary suspended because it is not in format

I would like to merge this two code.

My Arduino Project is RFID lock, So i would like to activate my lock on the other side of door using serial monitor from my laptop so this is my code


String door = "";
void setup() {  
   Serial.begin(9600);  
 
}  
 
 
void loop() {  
   
Serial.println("Enter door pass");  
 
 while (Serial.available()==0)  
 {                                       //Wait for user input  
   
 }  
 door = Serial.readString();

if (door=="open")
{
        lcd.clear();
        lcd.print("Pass Accepted");
        sg90.write(90); // Door Opened
        digitalWrite(greenLed, HIGH);
        delay(3000);
        digitalWrite(greenLed, LOW);
        sg90.write(0); // Door Closed
        lcd.clear();
        i = 0;
        RFIDMode = true;
 
 }
 else{
   
   
   
   }
}
// Include required libraries
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
#include <SPI.h>

// Create instances
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo sg90;

// Initialize Pins for led's, servo and buzzer
// Blue LED is connected to 5V
constexpr uint8_t greenLed = 7;
constexpr uint8_t redLed = 6;
constexpr uint8_t servoPin = 8;
constexpr uint8_t buzzerPin = 5;

char initial_password[4] = {'1', '2', '3', '4'};  // Variable to store initial password
String tagUID = "C0 C4 07 21";
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
String NAME;



char password[4];   // Variable to store users password
boolean RFIDMode = true; // boolean to change modes
char key_pressed = 0; // Variable to store incoming keys
uint8_t i = 0;  // Variable used for counter

// defining how many rows and columns our keypad have
const byte rows = 4;
const byte columns = 4;

// Keypad pin map
char hexaKeys[rows][columns] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

// Initializing pins for keypad
byte row_pins[rows] = {A0, A1, A2, A3};
byte column_pins[columns] = {2, 4, 3};

// Create instance for keypad
Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns);

void setup() {
Serial.begin(9600);
 Serial.println("CLEARDATA");
  Serial.println("LABEL,Date,Time,RFID UID,NAME");
  
  Serial.println("Scan PICC to see UID...");
  Serial.println("");
  // Arduino Pin configuration
  pinMode(buzzerPin, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  sg90.attach(servoPin);  //Declare pin 8 for servo
  sg90.write(0); // Set initial position at 90 degrees

  lcd.begin();   // LCD screen
  lcd.backlight();
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522

  lcd.clear(); // Clear LCD screen
}

void loop() {
  // System will first look for mode
  if (RFIDMode == true) {
    lcd.setCursor(0, 0);
    lcd.print("   Door Lock");
    lcd.setCursor(0, 1);
    lcd.print(" Scan Your Tag ");

    // 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 j = 0; j < mfrc522.uid.size; j++)
    {
      tag.concat(String(mfrc522.uid.uidByte[j] < 0x10 ? " 0" : " "));
      tag.concat(String(mfrc522.uid.uidByte[j], HEX));
    }
    tag.toUpperCase();

    //Checking the card
    if (tag.substring(1) == "C0 C4 07 21")
    {
      // If UID of tag is matched.
      
      lcd.clear();
      lcd.print("Tag Matched");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(greenLed, HIGH);
      delay(500);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(greenLed, LOW);
       lcd.clear();
      lcd.print("GLENN JIMENEZ");
      digitalWrite(greenLed, HIGH);
      delay(2000);
      digitalWrite(greenLed, LOW);

      lcd.clear();
      lcd.print("Enter Password:");
      lcd.setCursor(0, 1);
      RFIDMode = false; // Make RFID mode false
      StrUID = "C0 C4 07 21";
      NAME = "GLENN JIMENEZ";
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
    }

    else if (tag.substring(1) == "A3 51 9A 08")
    {
      // If UID of tag is matched.
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
      lcd.clear();
      lcd.print("Tag Matched");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(greenLed, HIGH);
      delay(500);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(greenLed, LOW);
       lcd.clear();
      lcd.print("AERON ANDRES");
      digitalWrite(greenLed, HIGH);
      delay(2000);
      digitalWrite(greenLed, LOW);

      lcd.clear();
      lcd.print("Enter Password:");
      lcd.setCursor(0, 1);
      RFIDMode = false; // Make RFID mode false

      StrUID = "A3 51 9A 08";
      NAME = "AERON ANDRES";
      Serial.println( (String) "DATA,DATE,TIME," + StrUID + NAME);
    }

    else
    {
      // If UID of tag is not matched.
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Wrong Tag Shown");
      lcd.setCursor(0, 1);
      lcd.print("Access Denied");
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(redLed, HIGH);
      delay(3000);
      digitalWrite(buzzerPin, LOW);
      digitalWrite(redLed, LOW);
      lcd.clear();
    }
  }

  // If RFID mode is false, it will look for keys from keypad
  if (RFIDMode == false) {
    key_pressed = keypad_key.getKey(); // Storing keys
    if (key_pressed)
    {
      password[i++] = key_pressed; // Storing in password variable
      lcd.print("*");
    }
    if (i == 4) // If 4 keys are completed
    {
      delay(200);
      if (!(strncmp(password, initial_password, 4))) // If password is matched
      {
        lcd.clear();
        lcd.print("Pass Accepted");
        sg90.write(90); // Door Opened
        digitalWrite(greenLed, HIGH);
        delay(3000);
        digitalWrite(greenLed, LOW);
        sg90.write(0); // Door Closed
        lcd.clear();
        i = 0;
        RFIDMode = true; // Make RFID mode true
      }
      else    // If password is not matched
      {
        lcd.clear();
        lcd.print("Wrong Password");
        digitalWrite(buzzerPin, HIGH);
        digitalWrite(redLed, HIGH);
        delay(3000);
        digitalWrite(buzzerPin, LOW);
        digitalWrite(redLed, LOW);
        lcd.clear();
        i = 0;
        RFIDMode = true;  // Make RFID mode true
      }
    }
  }
}

THANKYOU

code merging

http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

@filifili123 ,

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Im sorry after I edit the post there is a prompt that the forum delete this post so I created a new my bad

1 Like
void loop() {

  /* START OF ADDED CODE */
  if (Serial.available()) {
    String door = Serial.readString();
    if (door=="open") {
        lcd.clear();
        lcd.print("Pass Accepted");
        sg90.write(90); // Door Opened
        digitalWrite(greenLed, HIGH);
        delay(3000);
        digitalWrite(greenLed, LOW);
        sg90.write(0); // Door Closed
        lcd.clear();
        i = 0;
        RFIDMode = true;
    }
  }
  /* END OF ADDED CODE */

  // System will first look for mode
  if (RFIDMode == true) {

[/quote]

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.