Assignment 7: Automatic Musical Doorbell

Concept

For the 7th Assignment in our Introduction to Interactive Media course, we were assigned the task of creating a musical instrument that incorporates at least one digital and one analog sensor. After brainstorming various ideas, we decided to design an interactive project that combines functionality with musical creativity. Our concept is an “Automatic  MusicalDoor Bell”.

Our concept envisions a scenario where, as a person approaches and comes within 20 centimeters of the distance sensor, the system is triggered to play melodious door bell music. This immediate and musical response not only alerts the presence of someone at the door but also enhances the interaction with a harmonious greeting.

Implementation

In the development of our interactive door bell project, we aimed to create a distinctive auditory experience that went beyond the typical door bell chime. To achieve this, we programmed the Piezo buzzer to emit a unique melody rather than a standard tone. This melody was carefully chosen to be pleasant and welcoming, enhancing the interactive aspect of our device.

To further enrich the sonic experience, we introduced physical elements that function as percussive instruments. Specifically, we utilized a steel bottle and a glass cup, both positioned to serve as drums. These items were chosen for their resonant qualities and the distinct sounds they produce when struck.

The action of striking these improvised drums is controlled by a servo motor, to which a drumstick is attached. As the servo motor rotates in response to the proximity detected by the distance sensor, the attached drumstick swings. It hits the steel bottle on one side and the glass cup on the other.  The combination of this sound with the melody from the buzzer results in a complex musical note that is triggered by the presence of a person within the sensor’s 20 cm range.

The entire system is designed to be responsive: as soon as the ultrasonic distance sensor detects something within its range, both the servo motor and the buzzer are activated, collaboratively producing a musical output. This not only signals the presence of a visitor but does so in an unexpectedly musical way, turning a simple functional alert into an engaging and enjoyable experience.

Demo Video

A demo video, in detail, can be seen here:

Pictures of Circuit

Difficulties and Limitations

One of the significant challenges we faced during the implementation of our project was selecting the appropriate materials for the drum components. The process of determining the ideal materials involved extensive trial and error. We experimented with various types of cups and materials for the drumstick to achieve the desired sound quality and durability.

Looking ahead, for future iterations of the project, we aim to explore a broader range of frequencies for the buzzer, allowing for more diverse musical expressions. Additionally, adjusting the angles and speeds of the servo motor holds potential for creating a more dynamic and visually appealing interaction. These enhancements will not only improve the functionality of our device but also enrich the user experience, making each interaction with the door bell a unique and enjoyable moment.

Code

#include <Servo.h>

// Constants for the pins
const int buzzerPin = 4;
const int servoPin = A5;
const int triggerPin = 6;
const int echoPin = 5;

// Create a Servo object
Servo myServo;

// Variables for the distance measurement
long duration;
int distance;

void setup() {
  // Set the buzzer pin as output
  pinMode(buzzerPin, OUTPUT);
  // Initialize the servo
  myServo.attach(servoPin);
  // Set the ultrasonic sensor pins
  pinMode(triggerPin, OUTPUT);
  pinMode(echoPin, INPUT);
  // Begin serial communication (for debugging purposes)
  Serial.begin(9600);
}

void loop() {
  // Measure the distance from the ultrasonic sensor
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2; 

  // Check if something is within the desired range
  if (distance < 20) { 
    // Rotate servo to 180 degrees
    myServo.write(60);
    // delay(10);
    // myServo.write(50);
    delay(100); 
    // Rotate servo back to 0 degrees
    myServo.write(0);
    delay(250); 

    // Play a melody
    playMelody();
  } else {
    // Keep the servo at 0 degrees when not activated
    myServo.write(0);
    // No sound
    noTone(buzzerPin);
  }


  // Serial.print("Distance: ");
  // Serial.println(distance);
  
  delay(100); 
}

void playMelody() {
  // Note frequencies, e.g., C4, D4, E4, F4
  int melody[] = {262, 294, 330, 349};
  int noteDurations[] = {200, 200, 200, 200};  // duration of each note in milliseconds

  for (int thisNote = 0; thisNote < 4; thisNote++) {
    // To calculate the note duration, take one second divided by the note type.
    //e.g., quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = noteDurations[thisNote];
    tone(buzzerPin, melody[thisNote], noteDuration);

    // To distinguish the notes, set a minimum time between them.
    // The note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // Stop the tone playing:
    noTone(buzzerPin);
  }
}

 

 

Leave a Reply