Katie ChenSumer MohammedTomas VegaPhitchaya Mangpo Phothilimthana
Published

Oscar: The Singing Trash Monitor 

Finally. The solution to overflowing trashcans.

Full instructions provided1,019
Oscar: The Singing Trash Monitor 

Things used in this project

Hardware components

SparkFun RedBoard
SparkFun RedBoard
×1
Breadboard (generic)
Breadboard (generic)
×1
LED lights
×20
Speaker
×1
Motion sensor
×1
Infrared sensor
×1
Frosted acrylic
×1
Clear acrylic
×1
Black acrylic
×1
Audio kit
×1
Male jumpers
×20
Resistors
×4

Story

Read more

Custom parts and enclosures

oscar_distance.stl

Distance Sensor Casing

Schematics

Oshpark

PCB

Code

oscar_led.ino

Java
#include <Wtv020sd16p.h>
#include <DistanceGP2Y0A21YK.h>

int resetPin = 2;  // The pin number of the reset pin.
int clockPin = 3;  // The pin number of the clock pin.
int dataPin = 4;  // The pin number of the data pin.
int busyPin = 5;  // The pin number of the busy pin.

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);
 
int blue = 13;
int green = 12;
int yellow = 11;
int red = 10;

int blueId = 3;
int greenId = 2;
int yellowId = 1;
int redId = 0;

//SENSORS//
//Distance
DistanceGP2Y0A21YK Dist;
int infraRed = A0;
int distance;
int maxDistance = 30; //Set this to the height of your trashcan

//Motion
int calibrationTime = 30;   
int motionSensor = 9;

int state = 1;
// 0 = default (idle)
// 1 = measure trash level

int trashLevel = 0;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(blue, OUTPUT);     
  pinMode(green, OUTPUT);     
  pinMode(yellow, OUTPUT);     
  pinMode(red, OUTPUT);     
  wtv020sd16p.reset();
  
  Serial.begin(9600);
  Dist.begin(A0);
  pinMode(motionSensor, INPUT);
  digitalWrite(motionSensor, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

// the loop routine runs over and over again forever:
void loop() {
  // state = 1 if detecting motion.
  state = digitalRead(motionSensor);
  if(state==1) {
    // The function should return
    // - 0 for full
    // - 1 for almost full
    // - 2 for half
    // - 3 for empty
    trashLevel = getTrashLevel();

    if(trashLevel<=blueId) {
      digitalWrite(blue, HIGH);
    }
    if(trashLevel<=greenId) {
      digitalWrite(green, HIGH);
    }
    if(trashLevel<=yellowId) {
      digitalWrite(yellow, HIGH);
    }
    if(trashLevel<=redId) {
      digitalWrite(red, HIGH);
      playSound(22000);
    }
    delay(3000);
 
    digitalWrite(blue, LOW);
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    digitalWrite(red, LOW); 
  } 
}

int getTrashLevel() {
  int distance = Dist.getDistanceCentimeter();
  distance = map(distance, 0, maxDistance, 0, 3);
  return distance;
}

void playSound(int time) {
  wtv020sd16p.asyncPlayVoice(4);
  delay(time); // This indicates how long the song will play for 
  wtv020sd16p.stopVoice();
}

Credits

Katie Chen

Katie Chen

5 projects • 3 followers
Sumer Mohammed

Sumer Mohammed

11 projects • 5 followers
Tomas Vega

Tomas Vega

9 projects • 19 followers
Maker. I enjoy designing and developing assistive technology.
Phitchaya Mangpo Phothilimthana

Phitchaya Mangpo Phothilimthana

5 projects • 4 followers
I'm a PhD student in EECS. My research is about compilers and programming languages.

Comments