找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 14778|回复: 6
收起左侧

Arduino自动化智能垃圾桶制作,感应开合 附程序

  [复制链接]
ID:472844 发表于 2019-7-20 09:31 | 显示全部楼层 |阅读模式
现在正在大力推进垃圾分类投放,这是一个很有意义但是却需要投入大量精力的过程,作为一个工程师,我能做些什么,于是,我想到了制作一个简易的智能垃圾桶,可以感应到人的靠近,自动打开和关闭垃圾桶。

制作出来的实物图如下:
1231231.png 2.jpg
硬件组件:

·       跳线(通用)×16

·       SG90微伺服电机×1

·       超声波传感器 - HC-SR04(Generic)×2

·       面包板(通用)×1

·       ArduinoUNO和Genuino UNO×1

·       EspressifESP8266 ESP-01×1

软件应用程序和在线服务:

·       Blynk

·       ArduinoIDE

手动工具和制造机器:

·       热胶枪(通用)

·       胶带


我对这个项目的期望是,当我靠近这个垃圾桶,我不需要踩脚踏或者其他动作就可以打开垃圾桶,这样子可以帮助我们更加卫生的处理生活垃圾。

Arduino源程序如下:
  1. #define BLYNK_PRINT Serial          // Blynk
  2. #include <ESP8266WiFi.h>            // WIFI
  3. #include <BlynkSimpleEsp8266.h>     
  4. #include<Servo.h>                 //Servo SG90
  5. char auth[] = "483e2a27dc3b4fdcb5108b*******";   // token
  6. char ssid[] = "J**** Sidh***";  // SSID WIFI
  7. char pass[] = "190****";   // PASSWORD WIFI
  8. Servo servo;
  9. #define trigPin 13 //Ultrasonic1
  10. #define echoPin 12 //Ultrasonic1
  11. #define trigPin2 5 //Ultrasonic2
  12. #define echoPin2 4 //Ultrasonic2
  13. #define LED 2 //LED WIFI
  14. #define BLYNK_MAX_SENDBYTES 256 //256 Bytes

  15. void setup()
  16. {
  17.   Serial.begin (9600);
  18.   pinMode(trigPin, OUTPUT);     //Ultrasonic1
  19.   pinMode(echoPin, INPUT);      //Ultrasonic1
  20.   pinMode(trigPin2, OUTPUT);    //Ultrasonic2
  21.   pinMode(echoPin2, INPUT);     //Ultrasonic2
  22.   pinMode(LED, OUTPUT);         //LED
  23.   servo.attach(16);       //Servo
  24.   Blynk.begin(auth, ssid, pass);
  25.   Blynk.email("josie**************@gmail.com", "TrashBin", "Online."); // Test Online Email Sent
  26.   Blynk.notify("Tong Sampah Sudah Online"); //Notify Trash Online
  27.   servo.write(210); // Starting Position Servo
  28. }
  29. void loop()
  30. {
  31.   Blynk.run();
  32.   
  33.    //Ultrasonic1
  34.   long duration, distance;      
  35.   digitalWrite(trigPin, LOW);        
  36.   delayMicroseconds(2);              
  37.   digitalWrite(trigPin, HIGH);
  38.   delayMicroseconds(10);           
  39.   digitalWrite(trigPin, LOW);
  40.   duration = pulseIn(echoPin, HIGH);
  41.   distance = (duration/2) / 29.1;
  42.   Blynk.virtualWrite(V1, distance); //Level
  43.   //Ultrasonic1
  44.                                  
  45.   //Ultrasonic2                                    
  46.   long duration2, distance2;        
  47.   digitalWrite(trigPin2, LOW);        
  48.   delayMicroseconds(2);              
  49.   digitalWrite(trigPin2, HIGH);
  50.   delayMicroseconds(10);           
  51.   digitalWrite(trigPin2, LOW);
  52.   duration2 = pulseIn(echoPin2, HIGH);
  53.   distance2 = (duration2/2) / 29.1;
  54.   Blynk.virtualWrite(V2, distance2); //Level   
  55.   //Ultrasonic2

  56.   // Open Automation
  57.   if (distance >= 30 || distance <= 0)    //Condition when trash open and close automatically
  58.   {
  59.     Serial.println("Out of range");
  60.     servo.write(210);  //menutup
  61.     if (distance2 >= 6 || distance2 <= 0)  //Condition When Trash close reading full or not
  62.     {
  63.       Serial.print(distance2);
  64.       Serial.println(" cm2");
  65.       digitalWrite(LED, HIGH);
  66.       delay(500);
  67.     }
  68.     else
  69.     {
  70.       digitalWrite(LED, LOW);
  71.       delay(3000);
  72.       Serial.println("FULL");
  73.       Blynk.email("jo********@gmail.com", "Subject: TrashBin", "Full"); //if trash full will sending you email every 15minutes
  74.       Blynk.notify("Hey, Tong Sampah Penuh Segera Dikosongkan"); //Notify if trash full with blynk
  75.     }
  76.   }
  77.   else
  78.   {
  79.     Serial.print(distance);
  80.     Serial.println(" cm");
  81.     servo.write(60);      //Open trash
  82.     delay(5000);      //Delay open trash
  83.   }
  84.   delay(500); //Reading hands
  85. }
  86. //Open Automation

  87.   //Open Manually
  88.   BLYNK_WRITE(V3)
  89.   {
  90.   servo.write(param.asInt());//open
  91.   delay(5000);
  92.   }
  93.   BLYNK_WRITE(V5)
  94.   {
  95.    servo.write(param.asInt());
  96.    delay(5000);
  97.   }
  98.   //Open Manually
复制代码

以上代码下载:
智能垃圾桶.zip (23.19 KB, 下载次数: 287)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:428400 发表于 2019-8-2 18:58 | 显示全部楼层
不错,你是一个有想法的人!
回复

使用道具 举报

ID:660320 发表于 2019-12-10 09:52 | 显示全部楼层
我太佩服您啦!  师傅,我可不可以私下联系您呀!
回复

使用道具 举报

ID:684367 发表于 2020-1-26 23:07 | 显示全部楼层
可不可以研究一下语音互动的垃圾桶智能分类
回复

使用道具 举报

ID:779879 发表于 2020-6-15 13:35 | 显示全部楼层
非常好
回复

使用道具 举报

ID:452731 发表于 2020-6-27 22:36 | 显示全部楼层
真的很好!学到了很多
回复

使用道具 举报

ID:908153 发表于 2021-4-19 09:24 | 显示全部楼层
很多作品
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表