BLOG POST: INPUT/OUTPUT

My work is an ultrasonic trash can, not only that, I also added an OLED display and buzzer. The trash can can automatically complete the switch of the trash can through ultrasonic induction.

We know that the garbage problem has always been one of the main problems plaguing human society. The ultrasonic wave, display screen, and buzzer are actually not necessary at all. Why would I put my hands there and add an extra step when I could just throw the trash out?

Therefore, what my works actually want to express is the worry about consumerism. I hope that the audience can think of some environmental problems brought about by consumerism through my works. For example, products today often contain many unnecessary functions. This is mainly due to the fierce competition in the market. In order to attract consumers, companies continue to introduce new products and new functions, which leads to more and more complex products. These unnecessary functions often increase product costs, and lead to waste of resources and environmental pollution.

I don't want to deny that consumerism has many benefits, such as improving our living standards, promoting technological progress, and so on. But we cannot ignore some environmental problems caused by consumerism. Enterprises should pay attention to the practicality and sustainability of functions when designing products, so as to reduce the waste of resources and environmental pollution. Consumers should also choose products that suit them according to their own needs, and avoid blindly pursuing new functions.




#include <Arduino.h>
#include <Servo.h>
#define echoPin 2  // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3  // attach pin D3 Arduino to pin Trig of HC-SR04

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int buzzer = 8;
Servo servo_pin_9; //Servo name
// defines variables
long duration; // variable for the duration of sound wave travel
int distance;  // variable for the distance measurement
int angle = 0; //Servo angle

void setup()
{
  pinMode(trigPin, OUTPUT);                         // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT);                          // Sets the echoPin as an INPUT
  pinMode(buzzer, OUTPUT);
  servo_pin_9.attach(9);                            // Control servo signal pin
  Serial.begin(9600);                               // Serial Communication is starting with 9600 of baudrate speed

  Serial.begin(115200);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  // Display static text
  display.println("REYCLE REUSE REDUCE");

}
void loop()
{
  // Clears the trigPin condition
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);


  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)  

  if (distance < 20)
  { digitalWrite(buzzer, HIGH);
    if (servo_pin_9.read() == 90)
    {
      delay(1000);
    }
    else
    {
      angle = servo_pin_9.read();
      while (angle < 90)  //open the trash can slowly
      {
        angle++;
        servo_pin_9.write(angle);
        delay(10);
      }
      delay(1000);
    }
  }
  else
  { digitalWrite(buzzer, LOW);
    if (servo_pin_9.read() == 0)
    {
      delay(200);
    }
    else
    {
      angle = servo_pin_9.read();
      while (angle > 0)  //close the trash can slowly
      {
        angle--;
        servo_pin_9.write(angle);
        delay(10);
      }
      servo_pin_9.write(0);
    }
  }
}








评论