IR and buzzer overload?

Hello everyone, I have been working on this door lock opener for quite sometime now. It is meant to open a door latch with a push button, remote control, and RFID key card and a green LED and buzzer would turn on. The OLED will display "Door open. Come in."

The push button and RFID work perfectly. The problem is the IR receiver. When I use a remote to open the latch, it will work but then the servo will turn on again and again. There are sometimes that this does not happen and other times it will do this 2-5 times or until I use the RFID key card and then it stops. I am using Two 18650 5,000 mAh 3.7V batteries. When I use the 9V1A adapter, the servo will not turn on/off as much when I use the remote control.

The buzzer will also turn on automatically and stay on when I power the arduino for the first time until I either push the button, use the key card or remote. It will just do this once, then it will work perfectly after I press the push button, use the key card or remote.

Here is my code

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <IRremote.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(OLED_RESET);


 
#define SS_PIN 53 // Uno pin 10 Nano pin D10 of RFID
#define RST_PIN 5 // Uno pin 9 Nano pin D9 of RFID
#define SERVO_PIN 3    //servo pin was pin 9
#define ACCESS_DELAY 2000
#define DENIED_DELAY 1000
#define LED_G 7     //led green pin 7
#define LED_R 6     //led red pin 6
#define BUZZER 4    //buzzer pin 4
#define pushButtonPin 8  //push button pin 2
int buttonPushed = 0;
decode_results results;
Servo myservo;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int IRpin = 11;      //IR receiver pin 11
IRrecv irrecv(IRpin);
 
void setup()
{
  Serial.begin(9600); // Initiate a serial communication
  irrecv.enableIRIn();

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();

 
  SPI.begin(); // Initiate SPI bus
  mfrc522.PCD_Init(); // Initiate MFRC522
  myservo.attach(SERVO_PIN);
 
  
 
 pinMode (SDA, OUTPUT);
 
  pinMode (LED_G, OUTPUT);
  pinMode (LED_R, OUTPUT);
  pinMode (BUZZER, OUTPUT);
  pinMode(pushButtonPin, INPUT_PULLUP);
}
void loop()
{
   display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  
  display.display();
  display.clearDisplay();
  //start of IR SKETCH
 
  if (irrecv.decode(&results))
  {
    irrecv.resume();
  }
  if (results.value == 3249146358)
  {
    delay(500);
    digitalWrite (LED_G, HIGH);  //led turns on
    digitalWrite(BUZZER, HIGH);  //buzzer turns on
    delay(500);                 // for half a second
    digitalWrite(BUZZER, LOW);   //buzzer turns off
    myservo.write( 0 );          //servo goes to 0 degrees
    
//plug here
display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
    
    delay(7500);                   //for 7 and a half seconds
    myservo.write( 100 );          //servo goes to 100 degrees
    digitalWrite (LED_G, LOW);   //led green turns off
  
 
  }
 
 
  /* start of pushbutton sketch
    Everytime you press pushbutton it will turn on green led and buzzer, then servo
    will go from 0 to 100 degrees for 7 and a half seconds.  Then the push button
    will go from 1 to 0 state (on/off).*/
  if (digitalRead(pushButtonPin) == LOW) {
    buttonPushed = 1;
     }
     
  if ( buttonPushed ) {
     
    digitalWrite (LED_G, HIGH);
    digitalWrite(BUZZER, HIGH);
    delay(500); 
   digitalWrite(BUZZER, LOW);
    myservo.write(0);


    //plug here
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
    delay(7500);
    myservo.write(100);
    digitalWrite (LED_G, LOW);
    buttonPushed = 0;
 
  
    
  }
  //start of RFID SKETCH
  // Look for new cards
 
  if
  ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
 
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  Serial.println("Put your card to the reader...");
  Serial.println();
 
  //Show UID on serial monitor
  Serial.print("UID tag :");
 
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
 if (content.substring(1) == "5A 77 E2 81" || content.substring(1) == "F9 31 75 9C") //change here the UID of the card
    {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    digitalWrite(BUZZER, HIGH);
    delay(300);
    digitalWrite(BUZZER, LOW);
    myservo.write( 0 );
//plug here
   display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
 
    delay(7500);
    myservo.write( 100 );
    digitalWrite(LED_G, LOW);
  }
else {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    digitalWrite (BUZZER, HIGH);
    delay(DENIED_DELAY);
    digitalWrite(LED_R, LOW);
    digitalWrite(BUZZER, LOW);
  }
  
  }

Here is also a picture of everything wired. The only change I made on this picture is I connected the ground to the servo, IR reciever, RFID and OLED directly to the arduino but everything is connected as in my picture.

Why does the buzzer turn on when I apply power to the arduino for the first time?

Why does the servo turn on/off only when I use the IR receiver?

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