Assignment 8: Who’s there?

Problem:
I go to a circuit training gym, and since it reopened after covid, we’ve had to stand in line to take our temperature before we’re allowed to be admitted into class. This designated spot is obfuscated by a bunch of equipment, and it’s not always easy for the trainer on duty to be alerted whenever someone arrives. They are also likely to be re-setting the equipment for the next class, and unable to rely on visual cues.

Solution:
Whenever someone arrives at the door, the ultrasonic sensor initiates the speaker to start playing a tune to alert the trainer that someone is here. Once they take their temperature is taken and they leave that spot, the tune automatically stops because the distance sensed in the ultrasonic sensor returns back to baseline. This is less frustrating and annoying than a doorbell or buzzer, which can startle other people in the room and disrupt their pre-workout stretch.

https://vimeo.com/user80133951/review/472812721/a046f1c7f5

Sometimes, the trainer uses a vacuum cleaner to clean the gym between classes, and can’t hear soft ambient noises. In this case, the person waiting can use a button to sound a buzzer and stop the tune playing to attract the attention of the trainer more effectively.

//Setting up ultrasonic speaker pins
const int trigPin = 12;
const int echoPin = 13;

//Defines variables
long duration;
int distance;

//Setting up speaker
#include "pitches.h"

//Setting up melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4, 4
};

//buzzer interrupt
static const int togglePin = 2;
bool buzzerState = false;
const bool isInterrupt = true;

void SwitchPressed()
{
  //play buzzer
  }

void setup() {
//To read ultrasonic speaker
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
pinMode(togglePin, INPUT); // Button for buzzer

}

void loop() {

//Reading from ultrasonic speaker
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// calculate distance
distance= duration*0.034/2;

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

if(distance<100){
//  digitalWrite(11,HIGH);

  // iterate over the notes of the melody:

  for (int thisNote = 0; thisNote < 8; 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 = 1000 / noteDurations[thisNote];

    tone(8, 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);}

}
    else{
//  digitalWrite(11,LOW);
    // stop the tone playing:
    noTone(8);
}
}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.