skruglewicz
Published

Rehearsal Room Occupancy System for UMASS Music Students

The aim of this project is to create a Rehearsal Room Occupancy System to solve the problem of scheduling conflicts for music students.

IntermediateWork in progressOver 3 days153

Things used in this project

Hardware components

DFRobot Huskylens
×1
DFRobot FireBeetle 2 ESP32-E IoT Microcontroller
×1
DFRobot Gravity: IO Shield for FireBeetle 2
×1
DFRobot Gravity: Digital 10A Relay Module
×1
Fermion: DFPlayer Pro - A mini MP3 Player with On-board 128MB Storage (Breakout)
DFRobot Fermion: DFPlayer Pro - A mini MP3 Player with On-board 128MB Storage (Breakout)
×1
DFRobot Stereo Enclosed Speaker - 3W 8Ω
×1
DFRobot Jumper Wires
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud
Edge Impulse Studio
Edge Impulse Studio

Story

Read more

Schematics

Design Diagram

This is showing the Hardware and Connections for the system

Face Recognition Hardware Wiring Diagram

This shows the Connections between the HuskeyLens, ESP32+Shield, and the Relay module.
PLEASE NOTE: That D2 on the Shield did not work so my firmware uses D2.

MP3 Player Wireing Diagram

This schematic shows the connections from the ESP Shield to the MP3player and from the MP3player to the speaker.
PLEASE NOTE; That for the Red/Black wires from the speaker, you can either connected to the R+/R- or the L+/L- pins.

Code

RehearsalRoomOccupancy.ino

Arduino
Solve the problem of scheduling conflicts for music students. It will allow students to easily sign up for time in rehearsal rooms and provide real-time occupancy tracking to ensure that students are aware of available rooms.
/*

*/

/*DFPlayer*/
#include <DFRobot_DF1201S.h>
DFRobot_DF1201S DF1201S;

/*HUSKYLENS*/
#include "HUSKYLENS.h"
HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
void printResult(HUSKYLENSResult result);


void setup() {
   Serial.begin(115200);
   
  /*DFPlayer CODE*/
  Serial2.begin(115200);
  while(!DF1201S.begin(Serial2)){
    Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }
  /*Set volume to 20*/
  DF1201S.setVol(/*VOL = */20);
  Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  /*Enter music mode*/
  DF1201S.switchFunction(DF1201S.MUSIC);
  /*Wait for the end of the prompt tone*/
  delay(2000);
  DF1201S.setPlayMode(DF1201S.SINGLE);
  /*Get playback  */ 
  Serial.println(DF1201S.getPlayMode()); 
  
  Wire.begin();
  while (!huskylens.begin(Wire))
  {
      Serial.println(F("Begin failed!"));
      Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
      Serial.println(F("2.Please recheck the connection."));
      delay(100);
  }
    
  /*RELAY*/
  pinMode(D2, OUTPUT);
  
}

void playit(int filenum)
{
   /*PLAY A SOUND */ 
  Serial.print("filenum: ");
  Serial.println(filenum); 
  DF1201S.playFileNum(filenum);
  DF1201S.pause();
}


void loop() {
    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    }
}

void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        //Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);
       if(result.ID==4){
         playit(1);
         Serial.println(result.ID);
         digitalWrite(D2, HIGH);
         delay(2000);
         digitalWrite(D2, LOW);
        } else playit(2);
    }
}

Test_ID_Recognition.ino

Arduino
#include "HUSKYLENS.h"
HUSKYLENS huskylens;
//HUSKYLENS green line >> SDA; blue line >> SCL
void printResult(HUSKYLENSResult result);

void setup() {
    Serial.begin(115200);
    Wire.begin();
    while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
    pinMode(D6, OUTPUT);
}

void loop() {
    if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    }
}

void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);
       if(result.ID==1){
         digitalWrite(D6, HIGH);
         delay(2000);
         digitalWrite(D6, LOW);
        }
    }
}

Test-DFPlayer-Messages.ino

Arduino
#include <SoftwareSerial.h>
#include "HUSKYLENS.h"
#include <DFRobot_DF1201S.h>

HUSKYLENS huskylens;
//SoftwareSerial PSerial(25, 26);
DFRobot_DF1201S DF1201S;

float PERSON, LABCOAT;

void printResult(HUSKYLENSResult result);

//HUSKYLENS green line >> Pin 10; blue line >> Pin 11
//DF1201S TX,RX——> ESP32-E TX,RX
void setup() {
  Serial.begin(115200);
      while(!DF1201S.begin(Serial))
    {
      Serial.println("Init failed, please check the wire connection!");
      delay(1000);
    }
    DF1201S.setVol(20); 
      Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  /*Enter music mode*/
  DF1201S.switchFunction(DF1201S.MUSIC);
  /*Wait for the end of the prompt tone */
  delay(2000);
  /*Set playback mode to "repeat all"*/
  DF1201S.setPlayMode(DF1201S.ALLCYCLE);
  Serial.print("PlayMode:");
  /*Get playback mode*/
  Serial.println(DF1201S.getPlayMode());
  
  Wire.begin();
  while (!huskylens.begin(Wire))
  {
    Serial.println(F("Begin failed!"));
    Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
    Serial.println(F("2.Please recheck the connection."));
    delay(100);
  }
    //PSerial.begin(9600);
    

}
void loop()
{
     if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));
    else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));
    else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!"));
    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
        }    
    } 
  
    Serial.println("Start playing");
  /*Start playing*/
  DF1201S.start();
  delay(3000);
  }


  
void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);
    }
    else if (result.command == COMMAND_RETURN_ARROW){
        Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID);
    }
    else{
        Serial.println("Object unknown!");
    }
}

Test_Relay.ino

Arduino
Used to test the connection of the Gravity Relay
void setup() {
  // put your setup code here, to run once:
    pinMode(D2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
        delay(1000);
        digitalWrite(D2, LOW);
        delay(500);
        digitalWrite(D2, HIGH);
         

}

Test_MP3_Player_DFR0768.ino

Arduino
Used to Test the DF player.
#include <DFRobot_DF1201S.h>

DFRobot_DF1201S DF1201S;
void setup(void){
  Serial.begin(115200);
  Serial2.begin(115200);
  while(!DF1201S.begin(Serial2)){
    Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }
  /*Set volume to 20*/
  DF1201S.setVol(/*VOL = */20);
  Serial.print("VOL:");
  /*Get volume*/
  Serial.println(DF1201S.getVol());
  /*Enter music mode*/
  DF1201S.switchFunction(DF1201S.MUSIC);
  /*Wait for the end of the prompt tone*/
  delay(2000);
  /*Set playback mode to "repeat all"*/
  //DF1201S.setPlayMode(DF1201S.ALLCYCLE);
  DF1201S.setPlayMode(DF1201S.SINGLE);
  Serial.print("PlayMode:");
  /*Get playback mode*/
  Serial.println(DF1201S.getPlayMode());
}

void loop(){
  Serial.println("Start playing");
  DF1201S.start();
  delay(3000);
  Serial.println("Pause");
  DF1201S.pause();
  delay(3000);
  Serial.println("Play the next song");
  DF1201S.next();
  delay(3000);
  Serial.println("Play the previous song");
  DF1201S.last();
  delay(3000);
  Serial.println("Start playing");
  
  DF1201S.fastForward(/*FF = */10);

  Serial.print("File number:");
  Serial.println(DF1201S.getCurFileNumber());
  Serial.print("The number of files available to play:");
  Serial.println(DF1201S.getTotalFile());
  Serial.print("The time length the current song has played:");
  Serial.println(DF1201S.getCurTime());
  Serial.print("The total length of the currently-playing song:");
  Serial.println(DF1201S.getTotalTime());
  Serial.print("The name of the currently-playing file:");
  Serial.println(DF1201S.getFileName());
  
  delay(3000);
  DF1201S.playFileNum(/*File Number = */1);
  while(1);
}

Credits

skruglewicz

skruglewicz

23 projects • 10 followers
I am now a retired Senior Software Engineer with a Bachelor’s of Science Degree in Computer Science from Boston University.

Comments