• Follow Us On :

🧠 How to Make a Smart Dustbin with Arduino on Tinkercad – Step-by-Step Guide

👨‍💻 Code Designed By: Rajkamal

🚀 Project Developed By: Kamaldnp (kamaldnp.com)

🔗 Tinkercad Project: Click to View

🎮 YouTube Tutorial: Watch the Video

🗖️ Step-by-Step Instructions

🛠️ Step-by-Step Guide


✅ Step 1: Open Tinkercad

  1. Visit: https://www.tinkercad.com

  2. Create a free account or log in.

  3. Go to Circuits → Click “Create New Circuit”.


✅ Step 2: Add Components to the Workspace

Drag and drop the following components from the components panel:

  • Arduino UNO

  • Ultrasonic Sensor (HC-SR04)

  • Servo Motor (e.g., SG90)

  • LED (optional)

  • Breadboard (optional, for clean wiring)

  • Jumper wires


✅ Step 3: Wiring – Connect All Components

🔌 Ultrasonic Sensor (HC-SR04):

Sensor PinArduino Pin
VCC5V
GNDGND
TrigD5
EchoD6

🔄 Servo Motor:

Servo WireArduino Pin
VCC (Red)5V
GND (Brown/Black)GND
Signal (Yellow/Orange)D7

💡 LED (Optional):

LED PinArduino Pin
Long leg (+)D10 via 220Ω resistor
Short leg (-)GND

✅ Step 4: Upload Code to Arduino

Switch from Blocks to Text and paste the code below. Or click to download:

⬇️ Download Arduino Code

Copy & Paste Arduino Code:

Code copied!

/* Smart Dustbin Arduino Code
Code Designed By: Rajkamal
Project Developed By: Kamaldnp (kamaldnp.com)
Tinkercad Project: https://www.tinkercad.com/things/9SmkCNptuai-smart-dustbin
YouTube Video: https://www.youtube.com/watch?v=e9D5XSDnVWo */

#include 

Servo servo;
const int trigPin = 5;
const int echoPin = 6;
const int servoPin = 7;
const int ledPin = 10;

long duration, distance;
long readings[3];

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(ledPin, OUTPUT);
  servo.attach(servoPin);
  servo.write(0); // Close lid on start
  delay(1000);
  servo.detach();
}

long getDistance() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  return (duration / 2) / 29.1;
}

void loop() {
  for (int i = 0; i < 3; i++) {
    readings[i] = getDistance();
    delay(50);
  }

  distance = (readings[0] + readings[1] + readings[2]) / 3;

  if (distance < 50) {
    servo.attach(servoPin);
    servo.write(0); // Open lid
    delay(3000);
    servo.write(150); // Close lid
    delay(1000);
    servo.detach();
  }

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(200);
}

Leave a Reply

Your email address will not be published. Required fields are marked *