Introduction

In this article, I will explain the concept of an IoT based smart trash can. It will automatically open when we take waste to it; and when it is full, a light will come on automatically
Parts Of List
Hardware Parts
  • Arduino Uno
  • UltraSonic Sensor-2
  • Servo motor
  • LED
  • Buzzer
  • Bread Board
  • HookUp wires.
Software Parts
  • Arduino IDE.
Parts Explanation
UltraSonic Sensor
  • It is used to produce a high-frequency sound effect.
  • It can measure the signal from the sender to the receiver.
  • The echo is to be determined from the object.
Figure1 UltraSonic Sensor.
ServoMotor
  • It is small and cost-effective.
  • It is used for small robotics and radio controls.
Figure 2 ServoMotor
Buzzer
  • A buzzer is a sound maker which can alert you to a problem
  • Then in the buzzer which can have the gnd and vcc
Figure 2 Buzzer
Connection
Step 1 UltraSonic Sensor-1 to Arduino
  • Connect the Vcc of the Ultrasonic Sensor to the 5v of the Arduino Uno.
  • Connect the Gnd of the Ultrasonic Sensor to the Gnd of the Arduino Uno.
  • Connect the First Trigger of the Ultrasonic Sensor to the 5 of the digital Input in the Arduino Uno.
  • Connect the First Echo of the Ultrasonic Sensor to the 4 of the digital Input in the Arduino Uno.
Step 2 UltraSonic Sensor-2 to Arduino
  • Connect the Vcc of the Ultrasonic Sensor to the 5v of the Arduino Uno.
  • Connect the Gnd of the Ultrasonic Sensor to the Gnd of the Arduino Uno.
  • Connect the First Trigger of the Ultrasonic Sensor to the 7 of the digital Input in the Arduino Uno.
  • Connect the First Echo of the Ultrasonic Sensor to the 6 of the digital Input in the Arduino Uno.
Step 3 Servo Motor To Arduino
  • Connect the Vcc of the ServoMotor to the 5v of the Arduino Uno and also connect the vcc in the 8th pin of the Arduino.
  • Connect the Gnd of the ServoMotor to the Gnd of the Arduino Uno.
Step 4 Buzzer To Arduino
  • Connect the Vin of the buzzer to the 2 of the Arduino Uno.
  • Connect the Gnd of the buzzer to the Gnd of the Arduino Uno.
Step 5 Led To Arduino
  • Connect the Led1 to Negative pin to the Arduino Uno
  • Connect the Led1 to positive pin 8 to the Arduino Uno
  • Connect the Led2 to Negative pin to the Arduino Uno
  • Connect the Led2 to positive pin 9 to the Arduino Uno
  • Connect the Led3 to Negative pin to the Arduino Uno
  • Connect the Led3 to positive pin 10 to the Arduino Uno
  • Connect the Led4 to Negative pin to the Arduino Uno
  • Connect the Led4 to positive pin 11 to the Arduino Uno
Figure Of the Connection
Figure 4 Connection
Programming
  1. #define pingTrig2 7
  2. #define pingEcho2 6
  3. #define pingTrig 5
  4. #define pingEcho4
  5. #define buzzer 2
  6. #include < Servo.h >
  7. Servo myservo()
  8. void setup() {
  9. Serial.begin(9600);
  10. PinMode[PingTrig2, OUTPUT];
  11. PinMode[PingEcho2, OUTPUT];
  12. PinMode(8, OUTPUT);
  13. PinMode(9, OUTPUT);
  14. PinMode(10, OUTPUT);
  15. PinMode(11, OUTPUT);
  16. PinMode(Buzzer, OUTPUT);
  17. PinMode(pingTrig, OUTPUT);
  18. PinMode(pingEcho, OUTPUT);
  19. myservo, attach(3);
  20. }
  21. Void Loop() {
  22. lond duration2 distance2;
  23. digitalWrite(pingTrig2.LOW);
  24. delay Microsecconds(2);
  25. digitalWrite(pingTrig2.HIGH);
  26. delay Microsecconds(10);
  27. digitalWrite(pingTrig2.LOW);
  28. digitalWrite(buzzer, LOW);
  29. duration2 = PulseIn(pingEcho2, HIGH);
  30. distance2 = duration 2 / 20 / 2;
  31. if (distance 2 > 15) {
  32. open close();
  33. } else {
  34. mysowo,
  35. write(0)
  36. lighting();
  37. digitalwrite(buzzer, low)
  38. }
  39. void openclose() {
  40. long during, inches, cn;
  41. digitalwrite(pingTrig, LOW);
  42. delay Microseconds(02);
  43. digitalwrite(pingTrig, HIGH);
  44. delay Microseconds(10);
  45. digitalwrite(pingTrig, Low);
  46. duration = pulseIn(pingEcho, High);
  47. cn = duration / 29 / 2;
  48. if (cn < 10) {
  49. myservo.write(50);
  50. delay(100);
  51. } else {
  52. myservo.write(0);
  53. }
  54. delay(1000);
  55. void lighting() {
  56. digitalWrite(buzzer, HIGH);
  57. digitalWrite(8, HIGH);
  58. digitalWrite(9, HIGH);
  59. delay(300);
  60. digitalWrite(8, LOW);
  61. digitalWrite(9, LOW);
  62. digitalWrite(10, High);
  63. digitalWrite(11, High);
  64. delay(300);
  65. digitalWrite(10, Low);
  66. digitalWrite(11, Low);
  67. delay(300);
  68. }
Explanation
  • It will sense when we want to put waste in the can and when the can is full a light will come on.
Output
Figure 5 Output 1
Figure 6 Output 2