This device is intended to let everyone around you know when you are working or not so that you are able to stay on task.
Process
Discussion
I am overall pretty happy with my project. I think it does exactly what I intended it to do. It detects sound levels decently well and the linear actuators actually work perfectly how I intended them too. I think if anything I wish I could add in more of my fun ideas. For example, I wish I could add more stimuli to happen when the noise levels get loud. I think that would make the project even more fun and interesting. I also wish I did put more time into the design of the project just because I am a design major and I think it would enhance the interaction of this device.
Overall, I did fumble a lot along the way. I think I still don’t fully understand the sparkfun sound detector. I tried to calibrate it exactly how I wanted, but I only had so much time and I never got back around to it. Yet, the hardest part was actually making the timer and switching the modes between work and break. I am used to coding in functions, so for me, it is hard to code into a loop. A couple times I forgot that the program is constantly looping, which caused bugs. It took me a while to figure out ways around it (aka I made variables that acted as switches), but it was hard to figure out how to make my initial logic work. Then after that I had to add in the linear actuator code which was challenging because I couldn’t remember where break mode and work mode was being turned off and on. So, I think overall, my code could’ve been much cleaner because it started to confuse me. I think there’s too many switches on and off and there must be a way to simplify and make the variable names clearer.
The critiques brought up some great points and I actually ended up listening to one of them. The first one that stood out said “Maybe add double sided signs and have the signs disappear all the way into the toaster”. I strongly agreed with them and I ended up remaking my signs to be double sided and sturdier, however, the linear actuators are too tall to actually get the signs all the way in, but I would’ve loved to also incorporate that into my design. The second critique said “I would say if, theoretically, you were trying to use this device in a library, or somewhere quiet, then the sound of the linear actuators might be a bit loud and counterintuitive for its purpose”. I honestly don’t have a solution for that currently, but I thought this was an interesting thing to point out. I kinda agree that the sound could end up being distracting, yet my limitations were partially due to what was available.
If I were to make a whole new iteration, I would definitely clean up the wiring and code, since those both caused me lots of extra time. However, I also think there’s so many ways to expand on this idea like adding a more advanced timer, or adding more interactions that help keep you on task, thus I think this would be a really good project to iterate on because of the endless possibilities.
Technical Information
/* The Do Not Disturb Toaster By: Gia Marino My code has a switch that tells when the program should start. Then the program takes a start time and starts calculating time passed. If currentTime hits 25 mins and the program is not in break mode then it will switch over to break mode and move the linear actuator to indicate this. If it is in break mode and the currentTime hits 5 minutes then the program will switch into break mode and moves linear actuator accordingly. If in workmode the program will take inputs from the sound detector and send signals to the LED pin if detects moderate or loud noise. It continuously switches inbetween these modes unless stopped. Arduino pin | role | description ------------|--------|------------- A0 input enevelope pin on sound detector 2 output gate pin on sound detector 6 output LED pin 4 input button pin 7 output DO NOT Disturb linear actuator 8 output DO NOT Disturb linear actuator 11 output FREE to talk linear actuator 12 output FREE to talk linear actuator SDA output LCD serial pin SCL input LCD clock pin GND input ground 5V output 5v My linear actuator code was inspired by https://www.firgelliauto.com/blogs/tutorials/how-do-you-control-a-linear-actuator-with-an-arduino. I used this code to start and ended up breaking it up into two parts and putting that into my if statements. Secondly, my sound detector code was copied from https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels. I basically left most of it the same since it worked well for my application and I labeled it as the sound detector code. Additionally, I used https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide/all#software-example as a launchpad to creating my sound detector code. I ended up not following it for my main code, but my code may be slightly inspired by this source. To understand button wiring and coding, I referenced https://youtu.be/TIBa_RQB3Ek. Lastly, we copied the LCD tutorial code and worked off of that, so our code for the LCD display is also heavily influenced by this tutorial: https://courses.ideate.cmu.edu/60-223/f2022/tutorials/I2C-lcd */ //LCD set up #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C screen(0x27, 16, 2); #define BUTTON_PIN 4 //button pin #define PIN_GATE_IN 2 //sound detector #define PIN_LED_OUT 6 // all LEDs are hooked up to pin 6 #define PIN_ANALOG_IN A0 //sound detector // sound detector variables const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz) unsigned int sample; bool workTimerSwitch; //tells the program it is work mode bool breakTimerSwitch; //tells the program it is break mode //this tells program whether it is break time mode (when 1) or work time mode (when 0) bool breakTimerON; unsigned long startTime; // when the timer starts unsigned long currentTime = 0; // how long the timer has been going bool DEMO_MODE = 1; // Demo mode is turned on if 1 bool startToaster = 0; // variable that indicates that button turned on toaster bool TURN_MIC_ON = 0; // lets the program know whether the LEDs should flash if theres sound void setup() { Serial.begin(9600); pinMode(BUTTON_PIN, INPUT); pinMode(PIN_LED_OUT, OUTPUT); //LCD // initialize the screen (only need to do this once) screen.init(); // turn on the backlight to start screen.backlight(); screen.clear(); //break time actuator pinMode(7, OUTPUT); // Configure pin 7 as an Output pinMode(8, OUTPUT); // Configure pin 8 as an Output digitalWrite(7, HIGH); // Initialize pin 7 as Low digitalWrite(8, HIGH); // Initialize pin 7 as Low //work time actuator pinMode(11, OUTPUT); // Configure pin 11 as an Output pinMode(12, OUTPUT); // Configure pin 12 as an Output digitalWrite(11, HIGH); // Initialize pin 11 as Low digitalWrite(12, HIGH); // Initialize pin 12 as Low } void loop() { unsigned long globalTime = millis(); // the global time //this variable stores whether button was pressed int ON = digitalRead(BUTTON_PIN); // if button is pressed then this if statement swtiches the startToaster //variable on HIGH which will start the program if (ON == 1) { startToaster = 1; } if (startToaster == 1) { currentTime = globalTime - startTime; // calculates currentTime } if (currentTime >= 1500000) { // work timer reached 25 mins Serial.println("25 mins!"); // Retracts Linear Actuator digitalWrite(11, HIGH); digitalWrite(12, LOW); delay(2000); // 2 seconds // Stop Actuator digitalWrite(11, HIGH); digitalWrite(12, HIGH); // extends breaktime linear actuator digitalWrite(7, LOW); digitalWrite(8, HIGH); delay(2000); // 2 seconds digitalWrite(7, HIGH); digitalWrite(8, HIGH); // it is break mode so sound does not need to activate LED TURN_MIC_ON = 0; //LCD screen.home(); screen.print(String ("Break Time!")); startTime = globalTime; // reset breakTimerSwitch = 1; // turns on break time mode } // this is so the program doesn't continue to loop in the workTimer statment // b/c otherwise it would continue to reset startTime which would make currentTime zero // hence why the variable is labeled as a switch if (workTimerSwitch == 1) { startTime = globalTime; workTimerSwitch = 0; } if (breakTimerSwitch == 1) { // break timer switched on breakTimerON = 1; startTime = globalTime; // reset breakTimerSwitch = 0; // switch is turned off so program doesn't loop in statement } if (breakTimerON == 1) { if (currentTime >= 300000) { // 5 mins Serial.println("5 mins!"); // Retracts break time Linear Actuator digitalWrite(7, HIGH); digitalWrite(8, LOW); delay(2000); // 2 seconds // Stop Actuator digitalWrite(7, HIGH); digitalWrite(8, HIGH); // Extend Linear Actuator digitalWrite(11, LOW); digitalWrite(12, HIGH); delay(2000); // 2 seconds // Stops Actuator digitalWrite(11, HIGH); digitalWrite(12, HIGH); // sound detection should now activate LEDs since in work mode TURN_MIC_ON = 1; // LCD screen.home(); screen.print(String ("Work Time!")); startTime = globalTime; // reset breakTimerON = 0; // will make program exit this if statement workTimerSwitch = 1; // switch into work mode } } // SOUND DETECTOR CODE if (TURN_MIC_ON == 1) { unsigned long startMillis = millis(); // Start of sample window unsigned int peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1024; // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(PIN_ANALOG_IN); if (sample < 1024) // toss out spurious readings { if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude double volts = (peakToPeak * 5.0) / 1024; // convert to volts if (volts <= 0.10) // quiet noise levels { Serial.println("Quiet."); digitalWrite(PIN_LED_OUT, 0); } else if ( (volts > 0.10) && ( volts <= 0.30) ) { Serial.println("Moderate."); // moderate noise levels digitalWrite(PIN_LED_OUT, 50); } else if (volts > 0.30) { Serial.println("Loud."); // loud noise levels digitalWrite(PIN_LED_OUT, 200); } } // DEMO MODE if (DEMO_MODE == 1) { // DEMO MODE is turned on if (currentTime >= 6000) { // 1 min // Retracts Linear Actuator digitalWrite(11, HIGH); digitalWrite(12, LOW); delay(2000); // 2 seconds // Stop Actuator digitalWrite(11, HIGH); digitalWrite(12, HIGH); // extends breaktime linear actuator digitalWrite(7, LOW); digitalWrite(8, HIGH); delay(2000); // 2 seconds digitalWrite(7, HIGH); digitalWrite(8, HIGH); // it is break mode so sound does not need to activate LED TURN_MIC_ON = 0; //LCD screen.home(); screen.print(String ("Break Time!")); startTime = globalTime; // reset breakTimerSwitch = 1; // turns on break time mode } if (breakTimerON == 1) { if (currentTime >= 6000) { // 1 min // Retracts break time Linear Actuator digitalWrite(7, HIGH); digitalWrite(8, LOW); delay(2000); // 2 seconds // Stop Actuator digitalWrite(7, HIGH); digitalWrite(8, HIGH); // Extend Linear Actuator digitalWrite(11, LOW); digitalWrite(12, HIGH); delay(2000); // 2 seconds // Stops Actuator digitalWrite(11, HIGH); digitalWrite(12, HIGH); // sound detection should now activate LEDs since in work mode TURN_MIC_ON = 1; // LCD screen.home(); screen.print(String ("Work Time!")); startTime = globalTime; // reset breakTimerON = 0; // will make program exit this if statement workTimerSwitch = 1; // switch into work mode } } } }