yaeseonggledelNamikhyun김유민
Published

School Cafeteria's Trash Can Upgrade Project Lv.2

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

BeginnerFull instructions provided16 hours1,094
School Cafeteria's Trash Can Upgrade Project Lv.2

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LilyPad Rainbow LED (strip of 7 colors)
SparkFun LilyPad Rainbow LED (strip of 7 colors)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Circuit Diagram

Code

code

Arduino
code
int trigPin = 9;
3int echoPin = 8;
4int led = 7;
5int led2 = 6;
6int led3 = 5;
7int led4 = 4;
8long distance;
9long duration;
10void setup() {
11Serial.begin(9600);
12pinMode(trigPin, OUTPUT);
13pinMode(echoPin, INPUT);
14pinMode (led,OUTPUT);
15pinMode (led2,OUTPUT);
16pinMode (led3,OUTPUT);
17pinMode (led4,OUTPUT);
18}
19void loop() {
20  ultra();// put your main code here, to run repeatedly:
21  Serial.println(distance);
22  LV0();
23  delay(50);
24  LV1();
25  delay(50);
26  LV2();
27  delay(50);
28  LV3();
29  delay(50);
30  LV4();
31  delay(50);
32    if (distance>=5){
33    digitalWrite(led4,LOW);
34  }
35}
36void ultra(){ // Clears the trigPin
37digitalWrite(trigPin, LOW);
38delayMicroseconds(2);// Sets the trigPin on HIGH state for 10 micro seconds
39digitalWrite(trigPin, HIGH);
40delayMicroseconds(10);
41digitalWrite(trigPin, LOW);// Reads the echoPin, returns the sound wave travel time in microseconds
42duration = pulseIn(echoPin, HIGH);// Calculating the distance
43distance= duration*0.034/2;
44}
45void LV0(){
46  if(distance>30){
47    digitalWrite(led,LOW);
48    delay(100);
49    digitalWrite(led2,LOW);
50    delay(100);
51    digitalWrite(led3,LOW);
52    delay(100);
53    digitalWrite(led4,LOW);
54    delay(100);
55  }
56}
57void LV1(){
58  if(distance<=30 and distance>21){
59    digitalWrite(led,HIGH);
60    delay(100);
61    digitalWrite(led,LOW);
62    delay(100);
63  }
64}/*1단계 led만 점멸등 2,3,4단계는 항상 off*/
65void LV2(){
66  if(distance<=21 and distance>12){
67    digitalWrite(led,HIGH);
68    digitalWrite(led2,HIGH);
69    delay(100);
70    digitalWrite(led2,LOW);
71    delay(100);
72  }
73}/*2단계 led만 점멸등 1단계는 항상 on 3,4단계는 항상 off*/
74void LV3(){
75  if (distance<=12 and distance>5){
76    digitalWrite(led,HIGH);
77    digitalWrite(led2,HIGH);
78    digitalWrite(led3,HIGH);
79    delay(100);
80    digitalWrite(led3,LOW);
81    delay(100);
82  }
83}/*3단계 led만 점멸등 1,2단계는 항상 on 4단계는 항상 off*/
84void LV4(){
85  if (distance<=5){
86    digitalWrite(led,HIGH);
87    digitalWrite(led2,HIGH);
88    digitalWrite(led3,HIGH);
89    digitalWrite(led4,HIGH);
90  }
91}/*4단계 led만 점멸등 1,2,3단계는 항상 on*/

Credits

yaeseong

yaeseong

7 projects • 7 followers
Korean High School Student who wants to expand his knowledge of the World
gledel

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!"
Namikhyun

Namikhyun

5 projects • 2 followers
I do the Arduino programming. But he is still a beginner. A tremendous beginner. Expect, people.
김유민

김유민

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