Arduino 自动垃圾桶制作指南

ChangeCode
转载
发布时间: 2025-08-01 17:52:04 | 阅读数 0收藏数 0评论数 0
封面
垃圾桶及垃圾处理过程往往很繁琐,过度填充垃圾时则更麻烦。但能在你靠近扔垃圾时感应到你的存在,还能追踪内部垃圾容量的垃圾桶,是否可行、是否智能?答案是既可行又智能!是时候借助技术,把家里的垃圾桶改造成智能款了 —— 这只需要两个超声波传感器、一个舵机、一块 evive 开发板,再加上一些手工操作就行。
1

所需材料


2

实现人体感应功能

我们希望垃圾桶能感应到有人靠近扔垃圾。取一个超声波传感器,将其粘贴在垃圾桶正面即可。

3

实现桶盖自动开启功能

当有人靠近时,桶盖需要自动打开。为此,我们要用到舵机和一根线。将舵机粘贴在垃圾桶背面,在舵机的自由轴上安装舵盘,再用线将桶盖与舵盘连接起来。

4

实现垃圾容量检测功能

我们通常需要打开桶盖才能知道垃圾桶内的垃圾量。为了让其自动感应并告知垃圾填充百分比,需再用一个超声波传感器。将该传感器粘贴在桶盖下方。此时,除了将舵机和传感器与Arduino UNO开发板连接外,组装工作基本完成。

5

电路连接

按照图示进行连接,确保所有导线都从垃圾桶内部引出。

6

工作原理

当有人靠近垃圾桶时,正面的超声波传感器会感应到人的存在并通知 Arduino UNO开发板。随后,舵机轴转动,通过拉线打开桶盖。桶盖下方的超声波传感器会感应垃圾量并将信号传至 Arduino UNOArduino UNO会在屏幕上显示垃圾填充百分比。当垃圾量达到 90% 时,Arduino UNO内置的蜂鸣器会发出提醒。一旦达到 90%,正面的超声波传感器在有人靠近时将不再响应,桶盖也不会打开,此时就必须清理垃圾桶了。

7

Arduino 代码

#include<evive.h>

#define trig1 2
#define echo1 3
#define trig2 4
#define echo2 5
#define servo_pin 44
#define lid_close 0
#define lid_open 80
#define buzz 46

#define ultrasonic_1_threshould 15
#define ultrasonic_2_threshould 3

long duration1;
long duration2;
int distance1;
int distance2;
int temp;
unsigned int counter=0;
unsigned int counter2 =0;

Servo myServo;


void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

myServo.attach(44);

pinMode(trig1,OUTPUT);
pinMode(trig2,OUTPUT);
pinMode(echo1,INPUT);
pinMode(echo2,INPUT);

tft_init(INITR_GREENTAB);
tft.setRotation(1);
tft.fillScreen(1);

tft.setCursor(25,10);
tft.setTextSize(2);
tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
tft.print("STEMpedia");

tft.setCursor(35,40);
tft.setTextSize(1.8);
tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
tft.print("SMART DUSTBIN ");

tft.setCursor(30,60);
tft.setTextSize(1.8);
tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
tft.print("DUSTBIN STATUS");

tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
tft.setCursor(0,105);
tft.setTextSize(1.8);
tft.print("FOR MORE INFORMATION VISIT");
tft.setCursor(30,115);
tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
tft.print("thestempedia.com");

}

void loop() {
// put your main code here, to run repeatedly:
distance1 = calculateDistance1();
distance2 = calculateDistance2();
Serial.print("distance1=");
Serial.println(distance1);
Serial.print("distance2=");
Serial.println(distance2);
Serial.println("---------------------------------------");

if(distance1<= ultrasonic_1_threshould)
{
counter2++;
if(counter2>3)
{
myServo.write(lid_open);
counter2=0;
delay(3000);
}
}
else
{
distance2 = constrain(distance2,0,19);
temp = map(distance2,0,19,100,0);
tft.setCursor(50,70);
tft.setTextSize(1.8);
tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
tft.print(temp);
tft.print(" ");
tft.setCursor(65,70);
tft.print("% FULL");
myServo.write(lid_close);
}
if(distance2<=ultrasonic_2_threshould)
{
counter++;
if(counter>8)
{
while(distance2<=ultrasonic_2_threshould)
{
distance2 = calculateDistance2();
counter=0;
siren();
}
}
}
// else
// {
// distance2 = map(distance2,0,19,100,0);
// tft.setCursor(50,70);
// tft.setTextSize(1.8);
// tft.setTextColor(ST7735_WHITE,ST7735_BLACK);
// tft.print(distance2);
// tft.print(" ");
// tft.setCursor(65,70);
// tft.print("% FULL");
//
// myServo.write(lid_close);
//
// }

}

int calculateDistance1()
{
digitalWrite(trig1, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trig1, HIGH);
delayMicroseconds(10);
digitalWrite(trig1, LOW);
duration1 = pulseIn(echo1, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance1= duration1*0.034/2;
return distance1;
}

int calculateDistance2()
{
digitalWrite(trig2, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trig2, HIGH);
delayMicroseconds(10);
digitalWrite(trig2, LOW);
duration2 = pulseIn(echo2, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance2= duration2*0.034/2;
return distance2;
}

void siren()
{
for(int hz = 440; hz < 1000; hz+=25)
{
tone(buzz, hz, 50);
delay(5);
}
// Whoop down
for(int hz = 1000; hz > 440; hz-=25)
{
tone(buzz, hz, 50);
delay(5);
}
}

INO
FBEIPRGJPSNZ2ND.ino
3.85KB
ZIP
FCUOF23JPSNZ33A.zip
315.00KB
8

成品

至此,这款 DIY 智能垃圾桶已准备就绪,将助力废物管理,保持家居清洁!

阅读记录0
点赞0
收藏0
禁止 本文未经作者允许授权,禁止转载
猜你喜欢
评论/提问(已发布 0 条)
评论 评论
收藏 收藏
分享 分享
pdf下载 下载