0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

智能垃圾桶DIY教程

454398 来源:wv 2019-08-30 09:37 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

第1步:项目

垃圾桶设计为在超声波距离传感器检测到人员时打开。当传感器没有检测到任何人3秒钟时,它会向后运行电机直到它按下按钮。温度和湿度传感器(DHT)在垃圾桶中记录条件并计算内容物何时会腐烂。液晶显示屏显示时间,直到清空为止。

步骤2:零件清单

1 - Arduino MEGA 2560

1 - 面包板

1 - 10k欧姆电位器

1 - LCD屏幕(与Hitachi HD44780驱动程序兼容)

1 - DHT11

3 - 10k欧姆电阻

1 - 220欧姆电阻

1 - 电机控制L298N带H桥

1 - 12伏直流电机

1 - 12伏电源

1 - 超声波传感器HC-SR04

1 - 按钮

步骤3:机械设置

为了打开垃圾桶,我们制作了一个机械臂。它有两个接头,连接到电机和垃圾桶的盖子。就像在第一张照片中一样。

在秒图中可以看到它安装在电机上。

对于电机,我们钻了一些孔并使用了拉链。可以看到在第三张照片中安装在垃圾箱内。手臂粘在盖子顶部

对于超声波测距仪,我们在垃圾桶前面钻了2个孔,直径= 16mm,间距为1厘米(见4和5图片)。/p》

对于其他部件,我们刚刚为拉链或螺钉钻孔。在为其钻孔之后,LCD用螺栓和结安装在盖子上。带拉链的arduino和马达驱动器

臂部件采用3D打印。原理图是在Autofusion 360中制作的,并使用了以下文件:

第4步:Fritzing

第一张图显示了如何系统已连线。

步骤5:代码

代码分为五个不同的功能,每个功能控制一个不同的传感器或一个传感器的一部分。为了利用代码,必须为每个函数创建一个“新选项卡”。

arduino项目文件夹必须包含每个函数的代码作为文件。

为了程序运行不间断我们使用millis()和micros()而不是delay()。

该程序还需要以下库,这些库都可以在库管理器中找到:

LiquidCrystal v1.0.7(内置)

Adafruit Unified Sensor 1.0.2

DHT传感器库v1.3.0

主程序:

//Global variables are defined here. They‘re read through out the entire program.

//Local variables are defined within each function. They can only be changed or read within the function.

//Records whether the ultrasonic sensor has detected something.

//It’s controlled within the DistanceSensor function. It will stay on for four seconds when something is within range.

//Everytime it registers something it refreshes the timer.

boolean Distance_Close;

//Remembers if trashcan is open or closed. One is open and zero is closed.

bool TrashcanState;

//Monitors for local variables.

int ButtonMonitor;

int DistanceMonitor;

int CloseMonitor;

unsigned long TimeOpenMonitor;

unsigned long TimeUsedMonitor;

int DetectedMonitor;

int TemperatureMonitor;

int HumidityMonitor;

//Sets the pin numbers.

const int DCmotorIn1 = 5;

const int DCmotorIn2 = 6;

const int TrigPin = 8;

const int EchoPin = 7;

const int ButtonPin = 9;

const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 22, d7 = 24; //Pin numbers for the LCD.

//Libraries, make sure to install all of them.

//All libraries can be found inside the Library Manager.

//“Adafruit Unified Sensor Library” must also be installed in order for dht to work even though it is not loaded.

#include

#include “DHT.h”

#define DHTPIN 3 //Defines which pin should be used for the temperature and humidity sensor

#define DHTTYPE DHT11 //Defines which type of DHT is used. If you have a DHT22 replace DHT11 with DHT22.

DHT dht(DHTPIN, DHTTYPE); //Loads the defined pin and type.

LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //Tells the program which pins are installed.

void setup() {

// Code that needs to be run once:

Serial.begin(9600); //Starts communication with the monitor. Make sure that the monitor have the same BAUD speed.

//Determine if pins are reading or writing.

pinMode(TrigPin,OUTPUT);

pinMode(EchoPin,INPUT);

pinMode(DCmotorIn1, OUTPUT);

pinMode(DCmotorIn2, OUTPUT);

pinMode(ButtonPin,INPUT);

dht.begin();

lcd.begin(16, 2); //Sets the dimension of the LCD

}

void loop() {

// put your main code here, to run repeatedly:

DistanceSensor(); //Constantly checks if someone is near the trashcan

OpenTrashcan(); //Checks if the trashcan should opened.

CloseTrashcan(); //Checks if the trashcan should be closed.

LCD();

TempHumid();

//Creates a table for monitoring all the different variables.

Serial.print(“Trashcan State : ”);

Serial.print(TrashcanState);

Serial.print(“ ”);

Serial.print(“Distance_Close: ” );

Serial.print(Distance_Close);

Serial.print(“ ”);

Serial.print(“Button: ” );

Serial.print(ButtonMonitor);

Serial.print(“ ”);

Serial.print(“Temperature: ” );

Serial.print(TemperatureMonitor);

Serial.print(“ ”);

Serial.print(“Humidity: ” );

Serial.print(HumidityMonitor);

Serial.print(“ ”);

Serial.print(“Distance: ” );

Serial.println(DistanceMonitor);

控制距离传感器的功能:

int DistanceSensor(){

//Local variables used only in this function

unsigned long TimeUsed;

unsigned long Wait;

unsigned long WaitExtra;

unsigned long TimeOpen;

bool Detected;

long Duration;

int Distance;

TimeUsed = micros(); //Reads how long the arduino have been on in microseconds.

//Writes the local variables into global variables for monitoring

DetectedMonitor = Detected;

DistanceMonitor = Distance;

//Make the ultrasonic sensor send out a sonic wave and starts two timers.

//It is activated after 12 microseconds as the timer is exceeded and the function restarts.

if (WaitExtra 《 TimeUsed){

digitalWrite(TrigPin,HIGH); //Sends out a sonic wave

Wait = TimeUsed + 10; //Takes the current time and adds 10 microseconds to create a timer

WaitExtra = TimeUsed + 12; //Takes the current time and adds 12 to create a timer

}

//Turns off the sonic wave and reads how long it took for it to return.

//Afterwards it calculates the distance it have traveled.

//The distance is calculated in cm.

if (Wait 》= TimeUsed){

digitalWrite(TrigPin,LOW); // Stops the sonic wave

Duration = pulseIn(EchoPin,HIGH); //Reads how long it took for the wave to return in microseconds.

Distance = Duration*0.034/2; //Calculates the distance

}

//Checks if anyone is within a certain distance.

//This can be changed depending on when you want it to trigger.

//Remember this can‘t be less than 2 cm (0.79 inches) unless you use a different sensor.

if ((Distance 》= 10) && (Distance 《= 30)){

Detected = 1; //Something is detected

}

else{

Detected = 0; //Nothing has been detected

}

//Allows the Distance_Close to be set if someone if within the distance set.

//Refreshes if something is detected again.

if (Detected == 1){

TimeOpen = TimeUsed + 4000000; //Refreshes or sets the time that must pass to reset Distance_Close.

}

//Sets Distance_Close to 1, if the time set in detected hasn’t been exceed.

if (TimeOpen 》 TimeUsed){

Distance_Close = 1;

}

//Sets Distance_Close to 0, if the time set in detected has been exceed.

if (TimeOpen 《= TimeUsed){

Distance_Close = 0;

}

}

控制LCD的功能:

int LCD(){

lcd.setCursor(0, 0); //Begins writing at the top row, from the beginning

lcd.print(“Temperature: ”); //Writes “temperature” on the LCD

lcd.print(TemperatureMonitor); //Writes the number measured by the DHT

lcd.setCursor(0,1); //Begins writig at the bottom row, from the beginning

lcd.print(“Humidity: ”); //Writes “humidity” on the LCD

lcd.print(HumidityMonitor); //Writes the number measured by the DHT

}

打开垃圾桶:

bool OpenTrashcan() {

//If someone is detected within a set range in DistanceSensor, the trashcan open.

if ((TrashcanState == 0) && (Distance_Close == 1)){

//Sets the motor to run at full speed in a certain direction. In our case it is CLOCKWISE???

analogWrite(DCmotorIn1, 0);

analogWrite(DCmotorIn2, 255);

//Stops the entire program to make sure it doesn‘t stop while opening.

delay(600);

//After the delay is over the motor is turned off.

analogWrite(DCmotorIn1, 0);

analogWrite(DCmotorIn2, 0);

//Tells the rest of the program that the trashcan is open.

TrashcanState = 1;

}

}

关闭垃圾桶的功能:

bool CloseTrashcan() {

//Local variable to control the button.

int button;

button = digitalRead(9); //Continually check if the button is pressed or not

//Local variable saved as a global varaible for monitoring

ButtonMonitor = button;

//If the trashcan is open and no one has been within the range of the DistanceSensor for the set time the trashcan closes.

if ((TrashcanState == 1) && (Distance_Close == 0)){

//Starts the motor at full power. It turns COUNTER CLOCKWISE???

analogWrite(DCmotorIn1, 255);

analogWrite(DCmotorIn2, 0);

}

//If the trashcan is open and the button is pressed, the trashcan will close.

if ((button == 1) && (TrashcanState == 1)){

//Stops the motor

analogWrite(DCmotorIn1, 0);

analogWrite(DCmotorIn2, 0);

TrashcanState = 0; //Sets the trashcan as open.

}

}

读取温度和湿度的函数:

int TempHumid(){

//Local variables used only in this function

unsigned long TimeUsed;

unsigned long Wait;

TimeUsed = millis(); //Counts how long the program have been running in millis

//Reads the temperature and humidity every 2.5 seconds.

if (Wait 《 TimeUsed){

int Humidity;

int Temperature;

Humidity = dht.readHumidity(); //Reads the current humidity in percentage.

Temperature = dht.readTemperature(); //Reads the current temperature in celcius.

HumidityMonitor = Humidity; // The humidity is saved in a global variable for monitoring.

TemperatureMonitor = Temperature; // The temperature is saved in a global variable for monitoring.

Wait = TimeUsed + 2500; //Takes the current time and adds 2500 milliseconds to create a timer.

}

}

为了获得灵感和帮助,我们使用了以下来源:

超声波传感器

https://howtomechatronics.com/tutorials/arduino/u.。.

DHT11

http://www.circuitbasics.com/how-to-set-up-the-dh。 。.

该代码基于DHT库提供的示例。它被命名为DHTtester。

L298电机驱动模块

https://www.instructables.com/id/How-to-use-the-L 。..

LCD

https://www.arduino.cc/en/Tutorial/HelloWorld

第6步:评估

自动垃圾桶功能齐全,但还有很多不足之处。

第一个问题是它无法检测何时打开。这可以通过安装伺服而不是直流电机来解决,通过使用可以检测何时打开的按钮或类似物。

秒的问题是超声波传感器有角度和一些困难时间材料太吸音了。它可以通过使用PIR传感器来解决。如果安装了PIR传感器,它可以成角度以便更有可能检测到人。

代码也缺少显示何时应该清空垃圾桶的部分以及可以判断垃圾桶何时清空的部分被清空了。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 智能垃圾桶
    +关注

    关注

    3

    文章

    53

    浏览量

    11063
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    盲区≤50mm!大禹超声波双探头传感器实现垃圾桶精准满溢监测

    要求,大禹电子凭借深厚的技术积淀,推荐产品超声波双探头测距传感器。这款传感器以其卓越的性能,契合了智能垃圾桶的监测需求,为环卫管理提供了可靠的数据支撑。 小盲区,大视野:精准捕捉每一寸空间 单探头超声波传感
    的头像 发表于 05-15 14:11 117次阅读
    盲区≤50mm!大禹超声波双探头传感器实现<b class='flag-5'>垃圾桶</b>精准满溢监测

    家用智能垃圾桶控制板方案设计原理以及设计中需要注意的事项

    智能垃圾桶的核心目标是通过传感器和微控制器,实现自动开盖、垃圾压缩、状态监测、联网通信等功能,从而提升卫生与便利性。 主要功能: 1红外感应开盖:手或物体靠近感应区域(通常15-35cm),桶盖自动
    发表于 03-25 15:36

    红外+按键多模感应!纳祥科技智能感应垃圾桶方案0.5秒极速响应

    传统垃圾桶手动开盖易沾染细菌且操作不便,尤其在厨余垃圾处理场景中,卫生隐患问题较为突出。而随着智能家居的普及,感应式垃圾桶需求激增,其非接触操作更卫生,已广泛渗透到生活的方方面面。基于
    的头像 发表于 02-26 15:29 342次阅读
    红外+按键多模感应!纳祥科技<b class='flag-5'>智能</b>感应<b class='flag-5'>垃圾桶</b>方案0.5秒极速响应

    LoRa智能网关在智慧城市市政设施监控中的功能作用

    如下: 一、方案架构:分层设计,数据高效流转 终端感知层 设备部署 :在路灯、井盖、消防栓、垃圾桶等设施上安装LoRa终端节点,集成电流电压传感器、倾斜角传感器、水压流量传感器、满溢检测传感器等。 数据采集 :终端节点实时
    的头像 发表于 02-10 17:26 343次阅读

    LoRa智能网关在智慧城市市政设施监控中的解决方案

    市政设施(如路灯、井盖、消防栓、垃圾桶)数量庞大、分布范围广,传统人工巡检方式效率低下且难以实时监控。物通博联利用LoRa智能网关的广覆盖与高容量特性,构建城市级市政物联网,实现对市政设施的远程监测
    的头像 发表于 01-20 17:27 825次阅读
    LoRa<b class='flag-5'>智能</b>网关在智慧城市市政设施监控中的解决方案

    智能垃圾桶红外和TOF高精度感应方案

    ​         垃圾桶这么一个不起眼的小玩意在智能化以后其实也有大市场,智能垃圾桶的零售端价格从几十元到几百甚至上千元。 传统垃圾桶
    的头像 发表于 01-07 09:55 426次阅读
    ​<b class='flag-5'>智能</b><b class='flag-5'>垃圾桶</b>红外和TOF高精度感应方案

    工业智能网关赋能餐厨垃圾处理设备远程监控与智慧运维

    行业背景 餐厨垃圾若未能及时妥善处理,不仅会造成影响市容、污染水质、传播疾病等负面影响,还易引发食品安全隐患,危害人体健康。随着城市规模持续扩大与消费水平稳步提升,厨余垃圾产生量日益增多,对餐厨
    的头像 发表于 12-19 10:58 474次阅读
    工业<b class='flag-5'>智能</b>网关赋能餐厨<b class='flag-5'>垃圾</b>处理设备远程监控与智慧运维

    【启扬方案】基于RK3576的智能垃圾分类站应用解决方案

    伴随着城市化进程的加速和环境问题的日益凸显,人们对于环境保护的关注度也在不断提高,垃圾分类处理成为社会发展的重要议题。为有效解决垃圾分类和管理的难题,智能垃圾分类站应运而生。
    的头像 发表于 12-04 17:29 1135次阅读
    【启扬方案】基于RK3576的<b class='flag-5'>智能</b><b class='flag-5'>垃圾</b>分类站应用解决方案

    RFID在垃圾分类中的核心优势

    RFID在垃圾分类中的核心优势精准溯源每个居民或单位的垃圾桶配备唯一编码的RFID标签,系统可记录每次投放的时间、地点和责任人,实现垃圾来源可追溯。自动识别分类在智能
    的头像 发表于 09-23 11:08 709次阅读
    RFID在<b class='flag-5'>垃圾</b>分类中的核心优势

    辉芒微单片机FT60F112-RB作为智能感应垃圾桶的主控芯片!

    感应垃圾桶中,当红外传感器检测到人体靠近信号时,FT60F112-RB 能迅速做出反应,控制电机开启垃圾桶盖,其快速响应时间为用户带来了便捷体验。​   从工作电压范围来看,1.9V 至 5.5V 的宽电压区间赋予了它强大的适用性。无论是采用干电池供电,还是通过 USB
    的头像 发表于 09-09 19:31 960次阅读
    辉芒微单片机FT60F112-RB作为<b class='flag-5'>智能</b>感应<b class='flag-5'>垃圾桶</b>的主控芯片!

    赋能智慧生活:广州唯创电子WT588F02B语音芯片引领智能垃圾桶新体验

    在科技日新月异的今天,智能家居正以前所未有的速度融入我们的日常生活,重新定义着舒适与便捷。作为家庭清洁场景中的重要一环,智能垃圾桶也不再仅仅是容纳废弃物的容器,而是进化为兼具智能化、人
    的头像 发表于 08-20 08:52 670次阅读
    赋能智慧生活:广州唯创电子WT588F02B语音芯片引领<b class='flag-5'>智能</b><b class='flag-5'>垃圾桶</b>新体验

    广州黄埔城管携手海康威视打造垃圾分类智慧管理系统

    走进广州黄埔社区,"无异味、无污渍、无混投"的垃圾投放点已成为新日常。四色分类垃圾桶整齐摆放,清新空气与整洁环境让居民倍感舒心。
    的头像 发表于 08-06 10:28 1096次阅读

    超声波传感器解决方案‌ 的详细技术设计

    这两年来,随着物联网、人工智能、云计算、大数据等技术在智慧环卫领域的逐步下沉渗透,使得城市环卫的数字化作业模式也愈加成熟。广为熟知的便是垃圾分类管理。垃圾分类管理采用垃圾桶
    的头像 发表于 08-04 08:47 842次阅读
    超声波传感器解决方案‌ 的详细技术设计

    RFID标签在垃圾分类的应用

    二、RFID标签在垃圾分类中的优势高效率:RFID可以快速批量读取垃圾信息,大幅缩短操作时间,提高垃圾分类效率。准确性:RFID减少了人工操作的错误率,提高了垃圾分类的准确性和可靠性。
    的头像 发表于 07-31 16:48 919次阅读
    RFID标签在<b class='flag-5'>垃圾</b>分类的应用