Namikhyungledel김유민
Published

School Cafeteria's Trash Can Upgrade Project Lv.2

Let's make a device to look inside the trash can.

IntermediateShowcase (no instructions)16 hours761
School Cafeteria's Trash Can Upgrade Project Lv.2

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Male/Male Jumper Wires
×10
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LilyPad Rainbow LED (strip of 7 colors)
SparkFun LilyPad Rainbow LED (strip of 7 colors)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

For laser cutters

Schematics

Circuit Diagram

Code

Trash can with ultrasonic sensors

C#
The notes were in Korean.
int trigPin = 9;
int echoPin = 8;
int led = 7;
int led2 = 6;
int led3 = 5;
int led4 = 4;
long distance;
long duration;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode (led,OUTPUT);
pinMode (led2,OUTPUT);
pinMode (led3,OUTPUT);
pinMode (led4,OUTPUT);
}
void loop() {
  ultra();// put your main code here, to run repeatedly:
  Serial.println(distance);
  LV0();
  delay(50);
  LV1();
  delay(50);
  LV2();
  delay(50);
  LV3();
  delay(50);
  LV4();
  delay(50);
    if (distance>=5){
    digitalWrite(led4,LOW);
  }
}
void ultra(){ // Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);// Sets the trigPin on HIGH state for 10 micro seconds
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;
}
void LV0(){
  if(distance>30){
    digitalWrite(led,LOW);
    delay(100);
    digitalWrite(led2,LOW);
    delay(100);
    digitalWrite(led3,LOW);
    delay(100);
    digitalWrite(led4,LOW);
    delay(100);
  }
}
void LV1(){
  if(distance<=30 and distance>21){
    digitalWrite(led,HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
  }
}/*1단계 led만 점멸등 2,3,4단계는 항상 off*/
void LV2(){
  if(distance<=21 and distance>12){
    digitalWrite(led,HIGH);
    digitalWrite(led2,HIGH);
    delay(100);
    digitalWrite(led2,LOW);
    delay(100);
  }
}/*2단계 led만 점멸등 1단계는 항상 on 3,4단계는 항상 off*/
void LV3(){
  if (distance<=12 and distance>5){
    digitalWrite(led,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,HIGH);
    delay(100);
    digitalWrite(led3,LOW);
    delay(100);
  }
}/*3단계 led만 점멸등 1,2단계는 항상 on 4단계는 항상 off*/
void LV4(){
  if (distance<=5){
    digitalWrite(led,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,HIGH);
    digitalWrite(led4,HIGH);
  }
}/*4단계 led만 점멸등 1,2,3단계는 항상 on*/

Credits

Namikhyun
5 projects • 2 followers
I do the Arduino programming. But he is still a beginner. A tremendous beginner. Expect, people.
gledel
100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
김유민
9 projects • 2 followers
" Never do things others can do and will do if there are things others cannot do or will not do. "

Comments