標(biāo)題: Arduino自動化智能垃圾桶制作,感應(yīng)開合 附程序 [打印本頁]

作者: zhongzl728    時間: 2019-7-20 09:31
標(biāo)題: Arduino自動化智能垃圾桶制作,感應(yīng)開合 附程序
現(xiàn)在正在大力推進(jìn)垃圾分類投放,這是一個很有意義但是卻需要投入大量精力的過程,作為一個工程師,我能做些什么,于是,我想到了制作一個簡易的智能垃圾桶,可以感應(yīng)到人的靠近,自動打開和關(guān)閉垃圾桶。

制作出來的實(shí)物圖如下:

硬件組件:

·       跳線(通用)×16

·       SG90微伺服電機(jī)×1

·       超聲波傳感器 - HC-SR04(Generic)×2

·       面包板(通用)×1

·       ArduinoUNO和Genuino UNO×1

·       EspressifESP8266 ESP-01×1

軟件應(yīng)用程序和在線服務(wù):

·       Blynk

·       ArduinoIDE

手動工具和制造機(jī)器:

·       熱膠槍(通用)

·       膠帶


我對這個項(xiàng)目的期望是,當(dāng)我靠近這個垃圾桶,我不需要踩腳踏或者其他動作就可以打開垃圾桶,這樣子可以幫助我們更加衛(wèi)生的處理生活垃圾。

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
復(fù)制代碼

以上代碼下載:
智能垃圾桶.zip (23.19 KB, 下載次數(shù): 287)





作者: 難得糊涂2018    時間: 2019-8-2 18:58
不錯,你是一個有想法的人!
作者: agony203    時間: 2019-12-10 09:52
我太佩服您啦!  師傅,我可不可以私下聯(lián)系您呀!
作者: wenli7302    時間: 2020-1-26 23:07
可不可以研究一下語音互動的垃圾桶智能分類
作者: bajie34    時間: 2020-6-15 13:35
非常好
作者: azi197417    時間: 2020-6-27 22:36
真的很好!學(xué)到了很多
作者: lihongbin112    時間: 2021-4-19 09:24
很多作品




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1