Group 5 – Week 3

Next step is to create a traffic light display which will indicate how full the bin is. This will be done with the use of three LED lights and a separate ultrasonic sensor which will be located inside the bin.

// Define the LED pins
int redPin = 2;
int amberPin = 3;
int greenPin = 4;

// Define the ultrasonic sensor pins
int triggerPin = 11;
int echoPin = 10;

void setup() {
  // Set the LED pins as outputs
  pinMode(redPin, OUTPUT);
  pinMode(amberPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  
  // Set the ultrasonic sensor pins as inputs
  pinMode(triggerPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  // Start the serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Send a pulse to the ultrasonic sensor to start the measurement
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  
  // Read the echo time and calculate the distance in centimeters
  long duration = pulseIn(echoPin, HIGH);
  float distance = duration * 0.034 / 2;
  
  // Debugging: print the distance to the serial monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  
  // Control the LEDs based on the distance
  if (distance < 5) {
    // Distance is below 5cm, turn the red LED on
    digitalWrite(redPin, HIGH);
    digitalWrite(amberPin, LOW);
    digitalWrite(greenPin, LOW);
  } else if (distance < 8) {
    // Distance is between 5cm and 8cm, turn the amber LED on
    digitalWrite(redPin, LOW);
    digitalWrite(amberPin, HIGH);
    digitalWrite(greenPin, LOW);
  } else {
    // Distance is over 8cm, turn the green LED on
    digitalWrite(redPin, LOW);
    digitalWrite(amberPin, LOW);
    digitalWrite(greenPin, HIGH);
  }
  
  // Wait for a short time before taking the next measurement
  delay(100);
}

The code above is to simulate an isolated version of what we will be using. The depth of the prototype bin is roughly 14cm.

The red LED is told to emit when the ‘rubbish level’ is below 5cm from the top

The amber LED is instructed to emit when the ‘rubbish level’ is between 5cm and 8cm from the top

The Green LED is instructed to emit when the ‘rubbish level’ is over 8cm from the top

The idea of the traffic light system is to tell the user how full the bin is before opening it. This is to potentially save a journey of going to get bin bags before opening the bin.

Creating the bin prototype

A mould made of chemiwood was created, which was used to vacuum-form ABS. However, the first vacuum-forming attempt resulted in webbed edges, which were not visually pleasing. To rectify this, a smaller base plate was used for the second vacuum-forming attempt, which successfully eliminated the webbed edges.

Below is how the prototype looks. We placed the servo motor on the edge so that it is not fixed to the lid meaning that if a failure occurs, the user may still manually open the bin.

Steps for week 4;

  • Combine the traffic light system with the sensor and servo combination from week 2.
  • Add an extra feature so that the LED lights only begin to emit when someone is detected within a certain range of the servo sensor, saving power as this unit is likely to be battery operated.