PIR Sensor for Automatic Trash Can Lid

Project Overview

This project creates a touchless automatic trash can lid that opens when you wave your hand or approach with trash. A PIR sensor detects motion, and a servo motor lifts the lid. After a few seconds, the lid closes automatically.

Difficulty: Beginner
Estimated time: 2-3 hours
Estimated cost: $20-30

How It Works

A PIR sensor mounted on the trash can lid or front detects motion. When motion is detected, a servo motor rotates to lift the lid. After a set delay, the servo returns to its closed position. An optional button can be added for manual control.

Materials Needed

  • Arduino Nano or Arduino Uno (1)
  • HC-SR501 PIR sensor (1)
  • Servo motor (MG995 or SG90)
  • Trash can with hinged lid
  • Mounting hardware (brackets, screws)
  • Jumper wires
  • Power supply (5V 2A or battery pack)
  • Project enclosure

Circuit Diagram

Connection Table

VCC

5V

GND

GND

OUT

Digital Pin 2

Red (VCC)

5V

Brown (GND)

GND

Orange (Signal)

Digital Pin 9

One side

Digital Pin 3

Other side

GND

Arduino Code

// Automatic Trash Can Lid Opener
#include <Servo.h>

Servo lidServo;

const int pirPin = 2;
const int servoPin = 9;
const int buttonPin = 3;
const int ledPin = 13;

const int closedPos = 0;
const int openPos = 90;

unsigned long lastTriggerTime = 0;
const unsigned long openDuration = 3000;

bool lidOpen = false;
bool motionDetected = false;
bool buttonHeld = false;

void setup() {
  Serial.begin(9600);
  
  pinMode(pirPin, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  
  lidServo.attach(servoPin);
  lidServo.write(closedPos);
  digitalWrite(ledPin, LOW);
  
  delay(60000);
}

void openLid() {
  lidServo.write(openPos);
  lidOpen = true;
  lastTriggerTime = millis();
  digitalWrite(ledPin, HIGH);
}

void closeLid() {
  lidServo.write(closedPos);
  lidOpen = false;
  digitalWrite(ledPin, LOW);
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  bool button = digitalRead(buttonPin) == LOW;
  
  if (button && !buttonHeld) {
    buttonHeld = true;
    if (lidOpen) closeLid();
    else openLid();
  }
  if (!button) buttonHeld = false;
  
  if (motion && !motionDetected && !lidOpen) {
    motionDetected = true;
    openLid();
  }
  
  if (!motion && motionDetected) motionDetected = false;
  
  if (lidOpen && !buttonHeld && (millis() - lastTriggerTime > openDuration)) {
    closeLid();
  }
  
  delay(100);
}

Installation Steps

  1. Mount servo on trash can using brackets or epoxy
  2. Attach servo horn to lid with a rigid arm
  3. Position PIR sensor on front of trash can at waist height
  4. Place Arduino in small enclosure attached to the back of the trash can
  5. Power with USB adapter or battery pack
  6. Wave hand in front of sensor to test
  7. Adjust servo positions in code if needed

Project Extensions

  • Add battery level indicator
  • Add voice recognition module for voice activation
  • Add small fan to spray air freshener when lid opens
  • Add LED strip inside lid to illuminate when open
  • Add ultrasonic sensor to detect when trash can is full

Conclusion

This automatic trash can lid opener makes kitchen cleanup more hygienic and convenient. With simple materials and basic coding, you can upgrade any standard trash can to a touchless model.

Leave a Reply

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

Component Pin Arduino Pin
PIR Sensor PIR Sensor PIR Sensor Servo Motor Servo Motor Servo Motor Push Button Push Button