Musical Door Lock

Musical Door Lock © GPL3+

Instead of using a keypad to open your front door or even your safe, why not control the mechanism by a slider that glides through pitches?

  • 2,700 views
  • 1 comment
  • 7 respects

Components and supplies

About this project

This project is designed to allow you to open and close a door lock that is attached to a push-pull solenoid. It uses a slide that is detected by the ultrasonic sensor to correlate the distance away from the sensor, to note frequencies. The "password" for this lock is all musical. You set the pattern for the password, in this case, C D E, and if this is correct, the door will open.

Code

CodeArduino
const int trigPin = 10;
const int echoPin = 11;
const int buzzer = 12;
const int lock = 4;
const int led = 13;

float duration, distance, note, number;


void setup() 
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT); // Set buzzer - pin 12 as an output
  pinMode(lock, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  number = (duration*.0343)/2;
  distance = round(number);
  delay(100);
  Serial.print("Distance: ");
  Serial.println(distance);

  if(distance < 3)
  {
    delay(1000);
    Serial.print("START");
    Sequence();
    
  } 
}


void Sequence()
  {  
    digitalWrite(lock, LOW);
    digitalWrite(led, LOW);
    delay(2000);
    if(distance < 5)
    {
      delay(1000);
      tone(buzzer, 262);
      Serial.print("C");
      delay(2000);
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);

      duration = pulseIn(echoPin, HIGH);
      number = (duration*.0343)/2;
      distance = round(number);
      delay(100);
      Serial.print("Distance: ");
      Serial.println(distance);
      
      if(distance == 5)
      {
        delay(1000);
        tone(buzzer, 294);
        Serial.print("D");
        delay(2000);
        digitalWrite(trigPin, LOW);
        delayMicroseconds(2);
        digitalWrite(trigPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(trigPin, LOW);
  
        duration = pulseIn(echoPin, HIGH);
        number = (duration*.0343)/2;
        distance = round(number);
        delay(100);
        Serial.print("Distance: ");
        Serial.println(distance);       
        
        if(distance >= 6)
        {
        delay(1000);     
        tone(buzzer, 330);
        Serial.print("It Worked");
        digitalWrite(lock, HIGH);
        digitalWrite(led, HIGH);
        delay(1000);
        noTone(buzzer);
         }

         else if(distance < 6)
        {
        Serial.print("Didn't work 2");
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
        delay(500);
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
        delay(500);
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
      }
      }
      else if((distance < 5) || (distance >6))
      {
        Serial.print("Didn't work 1");
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
        delay(500);
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
        delay(500);
        tone(buzzer, 262);
        delay(500);
        noTone(buzzer);
      }
    }
    
    else
    {
      Serial.print("Restart");
    }
  }

Schematics

Schematic
Img 1066 quylnqjewq
Solenoid Schematic
Solenoid schematic da20uqzq6b

Comments

Similar projects you might like

RFID and Keypad Based Door Lock Using Arduino

by Aqib

  • 47,560 views
  • 27 comments
  • 101 respects

Coolest Door Lock Ever

Project tutorial by Vivek Gupta

  • 8,773 views
  • 4 comments
  • 12 respects

Door Lock System with Arduino

Project showcase by jayesh_nawani

  • 63,897 views
  • 5 comments
  • 35 respects

Voice Command Door Lock

by Muhammad_Munir

  • 4,840 views
  • 1 comment
  • 4 respects

Bluetooth Door Lock

Project tutorial by Muhammad_Munir

  • 8,263 views
  • 4 comments
  • 22 respects
Add projectSign up / Login