Thursday, May 4, 2017

Final Product



Problem Statement


  • 40% of food goes uneaten in the U.S.
  • Americans trash $165 billion in wasted food every year
  • U.S. respondents estimated wasting $900 in household food each year
  • 70% of people say they are bothered by the amount of food they waste


For the final project of the Product Design (MEAM 415) course at the University of Pennsylvania, I designed and prototyped an expiration alarm clock called "Waste-Less".  The user inputs their expirations into the device and it alerts the user as expiration dates approach.

















CAD Model:







Design Drawings:








Prototype X1:



Prototype X2:



Prototype X3:




Prototype X4:




Prototype X5:















Monday, May 1, 2017

Arduino Code

#include "Wire.h" // Tells the program to use the Wire library
#include "i2cLCD.h" // Tells the program to use the i2cLCD library
i2cLCD lcd(0); // Tells the program to make an I2C connection to the LCD and then refer to it as lcd int counter = 9;
#include <SparkFunDS1307RTC.h>

int storedMonths[5] = {0, 0, 0, 0, 0};
int storedDays[5] = {0, 0, 0, 0, 0};
int storedYears[5] = {17, 17, 17, 17, 17};
int timeSecond;
int timeMinute;
int timeHour;
int timeMonth;
int timeDay;
int timeYear;
int timeRealMinute;
int buzzerPin = 13;
int gLedPin = 7;
int yLedPin = 5;
int rLedPin = 6;
int buttonOnePin = 8;
int buttonTwoPin = 10;
int buttonThreePin = 9;
int buttonStateOne;
int buttonStateTwo;
int buttonStateThree;
int monthOriginalValue;
int dayOriginalValue;
int yearValue = 17;
int monthValue;
int dayValue;
int timeSetDisplayCount = 0;
int minutesNotSeconds = 0;
int secondsCounter = 0;
int timeRemains = 0;
int secondsRemaining = 0;
int cancelPending = 0;
int displayedValue = 0;
int checkFive = 0;
int digitalDelay = 0;
int displayedNumber = 0;
int originalValue = 0;
int currentValue = 1;
int counterState = 0;
int counter = 0;
int timingSeconds = 0;
int timingMinutes = 0;
int dateNumber = 0;
int dateNumberDisplayed = 0;
int afkTime = 0;
int a = 0;
int b = 0;
int c = 0;
int k = 0;

void setup() {
  Serial.begin(9600);
  lcd.begin(20, 4);
  pinMode(gLedPin, OUTPUT);
  pinMode(yLedPin, OUTPUT);
  pinMode(rLedPin, OUTPUT);
  pinMode(buttonOnePin, INPUT);
  pinMode(buttonTwoPin, INPUT);
  pinMode(buttonThreePin, INPUT);
  rtc.begin();
  rtc.setTime(14, 00, 4, 3, 18, 4, 17);
  rtc.set12Hour();
  homeScreen();
}

void loop() {
  //rtc.update();
  buttonStateOne = digitalRead(buttonOnePin);
  buttonStateTwo = digitalRead(buttonTwoPin);
  buttonStateThree = digitalRead(buttonThreePin);
  secondsCounter = 0;
  delay(50);

  if ((buttonStateTwo == 1) && k == 0) {
    newEntryScreen();
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    k = 1;
  }
  delay(100);
  if ((buttonStateThree == 1) && k == 0) {
    dateManagerScreen();
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    k = 3;
  }

  if ((buttonStateTwo == 1) && k == 1) {
    quantitySecondsScreen();
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    k = 2;
  }
  if ((buttonStateThree == 1) && k == 1) {
    quantityMinutesScreen();
    minutesNotSeconds = 1;
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    k = 2;
  }
  if (k == 2) {
    if (minutesNotSeconds == 1) {
      minutesRemainingScreen();
    } else {
      secondsRemainingScreen();
    }
  }
  if ((buttonStateTwo == 1) && k == 3) {
    monthSet();
    daySet();
    yearSet();
    expirationAddedScreen();
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
  }
  if ((buttonStateThree == 1) && k == 3) {
    dateNumber = 0;
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    manageItemsScreen();
    k = 4;
  }
  if ((buttonStateOne == 1) && k == 4) {
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    homeScreen();
  }
  if ((buttonStateTwo == 1) && k == 4) {
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    storedMonths[dateNumber] = 0;
    storedDays[dateNumber] = 0;
    storedYears[dateNumber] = 0;
    manageItemsScreen();
  }
  if ((buttonStateThree == 1) && k == 4) {
    buttonStateOne = 0;
    buttonStateTwo = 0;
    buttonStateThree = 0;
    dateNumber++;
    if (dateNumber == 5) {
      dateNumber = 0;
    }
    manageItemsScreen();
  }
  afkTime++;
  if ((buttonStateOne == 1) || (buttonStateTwo == 1) || (buttonStateThree == 1)) {
    afkTime = 0;
  }
  Serial.println(afkTime);
  if (afkTime > 100) {
    //sleepMode();
  }
}

void homeScreen() {
  lcd.clear();
  //rtc.update();
  printTime();
  lcd.setCursor(0, 1);
  lcd.print("Next Expire: 3 Days");
  lcd.setCursor(0, 2);
  lcd.print("1 - Timer ");
  lcd.setCursor(0, 3);
  lcd.print("2 - Date Manager");
  noTone(buzzerPin);
  digitalWrite(gLedPin, LOW);
  digitalWrite(yLedPin, LOW);
  digitalWrite(rLedPin, LOW);
  k = 0;
  counter = 0;
  originalValue = 0;
  c = 0;
  b = 0;
  a = 0;
}

void newEntryScreen() {
  lcd.clear();
  lcd.print("1 - Seconds");
  lcd.setCursor(0, 1);
  lcd.print("2 - Minutes");
}

void dateManagerScreen() {
  lcd.clear();
  lcd.print("1 - Add New Item");
  lcd.setCursor(0, 1);
  lcd.print("2 - Manage Dates");
}

void manageItemsScreen() {
  lcd.clear();
  lcd.print(storedMonths[dateNumber]);
  lcd.print("/");
  lcd.print(storedDays[dateNumber]);
  lcd.print("/");
  lcd.print(storedYears[dateNumber]);
  lcd.print("            #");
  dateNumberDisplayed = dateNumber + 1;
  lcd.print(dateNumberDisplayed);
  lcd.setCursor(0, 1);
  lcd.print("1 - Main Menu");
  lcd.setCursor(0, 2);
  lcd.print("2 - Delete Item");
  lcd.setCursor(0, 3);
  lcd.print("3 - Next Item");
  manageItems();
}

void manageItems() {
  buttonStateOne = 0;
  buttonStateTwo = 0;
  buttonStateThree = 0;
  a = 0;
  while (a = 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if (buttonStateOne == 1) {
      homeScreen();
      a = 1;
    }
    if (buttonStateTwo == 1) {
      storedMonths[dateNumber] = 0;
      storedDays[dateNumber] = 0;
      storedYears[dateNumber] = 0;
    }
    if (buttonStateThree == 1) {
      dateNumber++;
      manageItemsScreen();
    }
  }
}

void quantitySecondsScreen() {
  lcd.clear();
  delay(20);
  lcd.print(currentValue);
  lcd.print(" Seconds");
  lcd.setCursor(0, 1);
  lcd.print("1 - Set Quantity");
  lcd.setCursor(0, 2);
  lcd.print("2 - Increase");
  lcd.setCursor(0, 3);
  lcd.print("3 - Decrease");
  setSeconds();
}

void quantityMinutesScreen() {
  lcd.clear();
  delay(20);
  lcd.print(currentValue);
  lcd.print(" Minutes");
  lcd.setCursor(0, 1);
  lcd.print("1 - Set Quantity");
  lcd.setCursor(0, 2);
  lcd.print("2 - Increase");
  lcd.setCursor(0, 3);
  lcd.print("3 - Decrease");
  setMinutes();
}


void setSeconds() {
  timeRemains = 1;
  a = 0;
  while (a == 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    delay(20);
    if (buttonStateThree == 1) {
      currentValue = currentValue - 1;
      quantitySecondsScreen();
    }
    if (buttonStateTwo == 1) {
      currentValue = currentValue + 1;
      quantitySecondsScreen();
    }
    if (buttonStateOne == 1) {
      originalValue = currentValue * 100;
      a = 1;
    }
  }
    if (currentValue > 5) {
    digitalWrite(gLedPin, HIGH);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 5) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, HIGH);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 3) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, HIGH);
  }
}

void setMinutes() {
  timeRemains = 1;
  a = 0;
  while (a == 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    delay(20);
    if (buttonStateThree == 1) {
      currentValue = currentValue - 1;
      quantityMinutesScreen();
    }
    if (buttonStateTwo == 1) {
      currentValue = currentValue + 1;
      quantityMinutesScreen();
    }
    if (buttonStateOne == 1) {
      a = 1;
    }
  }
  if (currentValue > 5) {
    digitalWrite(gLedPin, HIGH);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 5) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, HIGH);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 3) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, HIGH);
  }
}

void expirationAlert() {
  lcd.clear();
  lcd.print("Expiration Alert!!!");
  lcd.setCursor(0, 3);
  lcd.print("Press to Reset");
  c = 0;
  while (c == 0) {
    tone(buzzerPin, 60000);
    digitalWrite(rLedPin, HIGH);
    delay(150);
    noTone(buzzerPin);
    delay(50);
    digitalWrite(rLedPin, LOW);
    tone(buzzerPin, 31);
    delay(150);
    noTone(buzzerPin);
    delay(50);
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if ((buttonStateOne == 1) || (buttonStateTwo == 1) || (buttonStateThree == 1)) {
      c = 1;
    }
  }
  digitalWrite(rLedPin, LOW);
  homeScreen();
}

void secondsRemainingScreen() {
  timingSeconds = 1;
  while (timeRemains == 1) {
    lcd.clear();
    lcd.print(currentValue);
    lcd.print(" seconds remaining");
    lcd.setCursor(0, 3);
    lcd.print("Press to Cancel");
    while (checkFive < 5) {
      buttonStateOne = digitalRead(buttonOnePin);
      buttonStateTwo = digitalRead(buttonTwoPin);
      buttonStateThree = digitalRead(buttonThreePin);
      delay(200);
      checkFive++;
      if ((buttonStateTwo == 1) || (buttonStateThree == 1) || (buttonStateOne == 1)) {
        cancelScreen();
        buttonStateOne = 0;
        buttonStateTwo = 0;
        buttonStateThree = 0;
      }
    }
    currentValue = currentValue - 1;
    checkFive = 0;

    if (currentValue == 0) {
      timeRemains = 0;
      expirationAlert();
    }
    if (currentValue > 5) {
      digitalWrite(gLedPin, HIGH);
      digitalWrite(yLedPin, LOW);
      digitalWrite(rLedPin, LOW);
    }
    if (currentValue < 5) {
      digitalWrite(gLedPin, LOW);
      digitalWrite(yLedPin, HIGH);
      digitalWrite(rLedPin, LOW);
    }
    if (currentValue < 3) {
      digitalWrite(gLedPin, LOW);
      digitalWrite(yLedPin, LOW);
      digitalWrite(rLedPin, HIGH);
    }
  }
  digitalWrite(rLedPin, LOW);
}

void minutesRemainingScreen() {
  if (currentValue > 5) {
    digitalWrite(gLedPin, HIGH);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 5) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, HIGH);
    digitalWrite(rLedPin, LOW);
  }
  if (currentValue < 3) {
    digitalWrite(gLedPin, LOW);
    digitalWrite(yLedPin, LOW);
    digitalWrite(rLedPin, HIGH);
  }
  timingMinutes = 1;
  while (timeRemains == 1) {
    secondsCounter++;
    lcd.clear();
    displayedValue = currentValue - 1;
    lcd.print(displayedValue);
    lcd.print(" minutes");
    secondsRemaining = 60 - secondsCounter;
    lcd.setCursor(0, 1);
    lcd.print(secondsRemaining);
    lcd.print(" seconds remaining");
    lcd.setCursor(0, 3);
    lcd.print("Press to Cancel");
    while (checkFive < 5) {
      buttonStateOne = digitalRead(buttonOnePin);
      buttonStateTwo = digitalRead(buttonTwoPin);
      buttonStateThree = digitalRead(buttonThreePin);
      delay(200);
      checkFive++;
      if ((buttonStateTwo == 1) || (buttonStateThree == 1) || (buttonStateOne == 1)) {
        cancelScreen();
        buttonStateOne = 0;
        buttonStateTwo = 0;
        buttonStateThree = 0;
      }
    }
    checkFive = 0;
    if (secondsCounter > 60) {
      currentValue = currentValue - 1;
      secondsCounter = 0;
      secondsRemaining = 60;
    }
    if (currentValue == 0) {
      timeRemains = 0;
      expirationAlert();
    }

  }
}


void monthSet() {
  a = 0;
  monthValue = 1;
  monthSetScreen();
  while (a == 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if (buttonStateThree == 1) {
      monthValue = monthValue - 1;
      monthSetScreen();
    }
    if (buttonStateTwo == 1) {
      monthValue = monthValue + 1;
      monthSetScreen();
    }
    if (buttonStateOne == 1) {
      monthOriginalValue = monthValue * 100;
      a = 1;
    }
  }
}

void daySet() {
  a = 0;
  dayValue = 1;
  daySetScreen();
  while (a == 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if (buttonStateThree == 1) {
      dayValue = dayValue - 1;
      daySetScreen();
    }
    if (buttonStateTwo == 1) {
      dayValue = dayValue + 1;
      daySetScreen();
    }
    if (buttonStateOne == 1) {
      dayOriginalValue = dayValue * 100;
      a = 1;
    }
  }
}


void yearSet() {
  a = 0;
  yearSetScreen();
  while (a == 0) {
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if (buttonStateThree == 1) {
      yearValue = yearValue - 1;
      yearSetScreen();
    }
    if (buttonStateTwo == 1) {
      yearValue = yearValue + 1;
      yearSetScreen();
    }
    if (buttonStateOne == 1) {
      a = 1;
    }
  }
}


void monthSetScreen() {
  lcd.clear();
  lcd.print(monthValue);
  lcd.print("/XX/17");
  lcd.setCursor(0, 1);
  lcd.print("1 - Select Month");
  lcd.setCursor(0, 2);
  lcd.print("2 - Next Month");
  lcd.setCursor(0, 3);
  lcd.print("3 - Previous Month");
}


void yearSetScreen() {
  lcd.clear();
  lcd.print(monthValue);
  lcd.print("/");
  lcd.print(dayValue);
  lcd.print("/");
  lcd.print(yearValue);
  lcd.setCursor(0, 1);
  lcd.print("1 - Select Year");
  lcd.setCursor(0, 2);
  lcd.print("2 - Next Year");
  lcd.setCursor(0, 3);
  lcd.print("3 - Previous Year");
}

void daySetScreen() {
  lcd.clear();
  lcd.print(monthValue);
  lcd.print("/");
  lcd.print(dayValue);
  lcd.print("/17");
  lcd.setCursor(0, 1);
  lcd.print("1 - Set Day");
  lcd.setCursor(0, 2);
  lcd.print("2 - Next Day");
  lcd.setCursor(0, 3);
  lcd.print("3 - Previous Day");
}

void expirationAddedScreen() {
  lcd.clear();
  lcd.print("New Expiration Set:");
  lcd.setCursor(0, 1);
  lcd.print(monthValue);
  lcd.print("/");
  lcd.print(dayValue);
  lcd.print("/");
  lcd.print(yearValue);
  delay(2000);
  storedMonths[dateNumber] = monthValue;
  storedDays[dateNumber] = dayValue;
  storedYears[dateNumber] = yearValue;
  dateNumber++;
  monthValue = 0;
  dayValue = 0;
  homeScreen();
}

void cancelScreen() {
  lcd.clear();
  cancelPending = 1;
  lcd.print("Are you sure that ");
  lcd.setCursor(0, 1);
  lcd.print("you want to cancel?");
  lcd.setCursor(0, 2);
  lcd.print("1 - YES");
  lcd.setCursor(0, 3);
  lcd.print("2 - NO");
  delay(1000);
  while (cancelPending == 1) {
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    delay(100);
    if (buttonStateThree == 1) {
      cancelPending = 0;
      buttonStateThree = 0;
      if (timingSeconds == 1) {
        secondsRemainingScreen();
      } else {
        minutesRemainingScreen();
      }
    }
    if (buttonStateTwo == 1) {
      homeScreen();
      buttonStateTwo = 0;
    }
  }
}
void printTime() {
  lcd.print(String(rtc.hour()) + ":");
  lcd.print(String(rtc.minute()));
  if (rtc.is12Hour()) {// If we're in 12-hour mode
    if (rtc.pm()) { // Use rtc.pm() to read the AM/PM state of the hour
      lcd.print(" PM     ");
    }
    else {
      lcd.print(" AM     ");
    }
  }
  lcd.print(String(rtc.month()) + "/" +   // Print month
            String(rtc.date()) + "/");  // Print date
  lcd.print(String(rtc.year()));        // Print year
}

void sleepMode() {
  a = 0;
  buttonStateOne = 0;
  buttonStateTwo = 0;
  buttonStateThree = 0;
  delay(50);
  while (a == 0) {
    lcd.noDisplay();
    buttonStateOne = digitalRead(buttonOnePin);
    buttonStateTwo = digitalRead(buttonTwoPin);
    buttonStateThree = digitalRead(buttonThreePin);
    if ((buttonStateOne == 1) || (buttonStateTwo == 1) || (buttonStateThree == 1)) {
      lcd.display();
      homeScreen();
      delay(1500);
      a++;
    }
  }
  afkTime = 0;
}

Disqus Shortname

Ads Inside Post

Comments system