Conor Doheny
Published © GPL3+

Automatic Trash Can

Press a sensor, and your trashcan will open automatically.

BeginnerFull instructions provided4 hours69
Automatic Trash Can

Things used in this project

Hardware components

reartisan DC 5V 0.5RPM Turbo Worm Geared Motor
×1
Force Sensitive Resistor 0.5 SEN-09375
×1
L298N Motor Controller
×1
Photon 2
Particle Photon 2
×1

Software apps and online services

Serial terminal

Story

Read more

Custom parts and enclosures

Enclosure

Working project in Enclosure

Schematics

Wiring pictures

Wiring pictures

Code

Code

C/C++
int sensorPin = A5;
int sensorValue = 0;
int IN1 = D15;
int IN2 = D16;

void setup() {
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}
void loop() {
  sensorValue = analogRead(sensorPin);
  
  Serial.print(sensorValue);

if (sensorValue > 3) {
    unsigned long currTime = millis();
    unsigned long startTime = millis();
    Serial.println("HIGH");
    while ( currTime < 280000 + startTime){
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2,LOW);
        currTime = millis();
    }
    unsigned long endTime = millis();
    unsigned long endingTime = millis();
    while ( endTime < 280000 + endingTime ){
            digitalWrite(IN1, LOW);
            digitalWrite(IN2, HIGH);
            endTime = millis();
        }
    digitalWrite(IN1, LOW);
    digitalWrite(IN2,LOW);
  } else {
    Serial.println("LOW");
    digitalWrite(IN1, LOW);
    digitalWrite(IN2,LOW);
    delay(3000);
  }
}

Credits

Conor Doheny
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.