Introduction: Auto Trash by Arduino

This instructable is so called Auto Trash, but do not overlook it, it just open the lid when you closed to it. This is a not a fancy toy, you can actually buy a factory make from warehouse store, but the price is often beyond your imagination. I made this instructable for experiment purpose, I had previously made the H-bridge motor driver (https://www.instructables.com/id/Bipolar-Stepper-Motor-Driver/) that could be useful here, I connected the driver with bipolar stepper motor to arduino broad and the supersonic transducer.

Step 1: The Litter Bin

I choose a small litter bin, originally I wanted to install a large bin, but the motor was not powerful enough to pull up the lid. I installed a small rod extended the back side of the lid, and pull the rod with a wire connected to the motor disc or crank shaft. Actually this can be done with servo motor, I just transplanted the assembly from large bin to small bin.

Step 2: The Code

The connection is shown here

#include <Stepper.h>

const int stepsPerRevolution = 20;

// change this to fit the number of steps per revolution // for your motor

// initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {

// put your setup code here, to run once:

// set the speed at 60 rpm:

myStepper.setSpeed(60);

pinMode(7, OUTPUT);//trig

pinMode(6, INPUT);//echo

}

void loop() {

// put your main code here, to run repeatedly:

myStepper.step(0);

if (scan()<15) {

myStepper.step(stepsPerRevolution);

delay (1500);

myStepper.step(-stepsPerRevolution);

delay (1000);

watchdogSetup();

}

}

long scan() {

long duration;

digitalWrite(7, LOW);

delayMicroseconds(2);

digitalWrite(7, HIGH);

delayMicroseconds(10);

digitalWrite(7, LOW);

duration = pulseIn(6, HIGH);

return (duration/2) / 29.1;

}

void watchdogSetup(void){

WDTCSR |= (1<<WDCE) | (1<<WDE);

WDTCSR = (1<<WDIE) | (1<<WDW) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0);

ISR(WDT_vect) {

// Watchdog timer interrupt.

}

Step 3: A Special Feature

I noticed the bipolar motor consumed 1A current at 5V even no movement, the motor pitches are engaged, this made the motor hot without any work done, but when I reset the board the current can ceased, so I add a watchdogsetup() code to reset the board, check the end of video.