Introduction: Arduino Door Opener Apartment Intercom

About: Manufacturing Engineer with a degree in Mechanical Engineering, love doing projects on the side, have a laser engraver, 3d printer, and cricut along with standard wood working tools.

An Arduino based apartment door intercom opener. By pressing the buzzer at the entrance in a certain pattern the door will unlock. Using the Arduino Nano RP2040 Connect with its built in microphone. The sketch listens for a noise above the value 10,000 and then waits 1 second, listens for a noise below 10,000, waits 1 second and listens for a noise above 10,000 and then runs the servo to 180 and then back to 0, then continues listening.

Supplies

  • Arduino Nano RP2040 Connect
  • Jumper Wires
  • Mini Breadboard
  • SG90
  • Screwdriver
  • #6-32 screws (if current screws are not long enough)
  • Computer with access to Arduino IDE program
  • 3d Printer and filament
  • Wi-Fi controlled smart outlet and USB power block (optional)

Step 1: Write Code for Arduino

Write/copy code from the link below. If you wish to change the pattern just change the if statements for the while loop adding or removing an if statement and the delay. I know this probably isn't the best written code, it was my first time working on an actual Arduino project, but it does work effectively.


https://create.arduino.cc/editor/herzogshandicraft/8eb65701-9bf6-4c19-9b55-52288359c113/preview



#include <WiFiNINA.h>

#include <PDM.h>

#include <Servo.h>


Servo servo;


bool LED_SWITCH = false;


// default number of output channels

static const char channels = 1;


// default PCM output frequency

static const int frequency = 16000;


// Buffer to read samples into, each sample is 16-bits

short sampleBuffer[512];


// Number of audio samples read

volatile int samplesRead;


void setup() {

 Serial.begin(9600);

 pinMode(LEDB, OUTPUT);

 delay(100);

 digitalWrite(LEDB, HIGH);

 delay(3000);

 digitalWrite(LEDB, LOW);

 delay(100);

 // while (!Serial);

 // Configure the data receive callback

  delay(100);

 digitalWrite(LEDB, HIGH);

 delay(3000);

 digitalWrite(LEDB, LOW);

 delay(100);

 PDM.onReceive(onPDMdata);

 delay(100);

 digitalWrite(LEDB, HIGH);

 delay(3000);

 digitalWrite(LEDB, LOW);

 delay(100);


 // Optionally set the gain

 // Defaults to 20 on the BLE Sense and -10 on the Portenta Vision Shields

 // PDM.setGain(30);


 // Initialize PDM with:

 // - one channel (mono mode)

 // - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense

 // - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shields

 if (!PDM.begin(channels, frequency)) {

  Serial.println("Failed to start PDM!");

  while (1);

 }

}


void loop() {

 // Wait for samples to be read

 if (samplesRead) {


  // Print samples to the serial monitor or plotter

  for (int i = 0; i < samplesRead; i++) {

   if (channels == 2) {

    Serial.print("L:");

    Serial.print(sampleBuffer[i]);

    Serial.print(" R:");

    i++;

   }

   Serial.println(sampleBuffer[i]);


   if (sampleBuffer[i] > 10000 || sampleBuffer[i] <= -10000) {

   delay(1000); // listens for loud noise and waits 1 second

    if (sampleBuffer[i] < 10000 && sampleBuffer[i] >= -10000) {

    delay(1000); // listens for less than loud noise and waits 1 second

     if (sampleBuffer[i] > 10000 || sampleBuffer[i] <= -10000) {

      // listens for loud noise and runs servo program

    delay(100);

    servo.attach(9);//set arduino PWM pin D9

    delay(100);

    servo.write(180);

    delay(3000);

    servo.write(0);

    delay(1000);

    servo.detach();

    delay(2000);

    }

    else {

    delay(100);

    }

   }

  }

  }

  // Clear the read count

  samplesRead = 0;

 }

}


/**

  Callback function to process the data from the PDM microphone.

  NOTE: This callback is executed as part of an ISR.

  Therefore using `Serial` to print messages inside this function isn't supported.

 * */

void onPDMdata() {

 // Query the number of available bytes

 int bytesAvailable = PDM.available();


 // Read into the sample buffer

 PDM.read(sampleBuffer, bytesAvailable);


 // 16-bit, 2 bytes per sample

 samplesRead = bytesAvailable / 2;

}

Step 2: Design and Print

I designed the case in Fusion 360 by getting measurements of the breadboard and servo motor. The holes for the intercom are a bit tight for the #6 screws, but work, they are approximately 83mm apart.


I left the curve on the top of the print in for a common USB rechargeable battery if you wish it to be wireless. However when I used the battery the servo drew too much power and caused the Arduino to crash. I believe the correct sized capacitor could be used, but I chose to just plug it into a Wi-Fi controlled outlet so I could turn it on and off remotely and not worry about recharging.


I printed out of gray PLA on a Creality CR6 Max, no supports were needed.

Step 3: Assemble

Peel sticky tape off the back of the breadboards and assemble. Screw the servo motor onto the board. Then remove and use/replace the screws on the current intercom so that they are long enough to hold on the 3d printed part also.

Step 4: Install Program and Wire

Upload the sketch onto the Arduino, and wire with the Brown to Ground, Red to +5V, Orange To Digital Pin 9 and plug USB into a wall outlet to power. If the light lights up 3 times it is ready to be tested. I was able to whistle nearby to reach above the required noise limit to test. Then place the little arm that comes with the servo into the correct position to press the button.

Step 5: Enjoy

Enjoy just pressing the intercom button in your selected pattern to let yourself into the apartment without having to get your keys out.


Check out a YouTube video of it in action here.

https://youtube.com/shorts/6c5FZWNPJTU

Anything Goes Contest

Participated in the
Anything Goes Contest