Ian KnappJustin Wiseman
Created December 7, 2020

Automatic Can Crusher

This project senses when a can is placed inside it and then crushes it using a motor.

26
Automatic Can Crusher

Things used in this project

Hardware components

Argon
Particle Argon
×2
Stepper Motor
Digilent Stepper Motor
×1
BOOSTXL-ULN2003 ULN2003A Dual Stepper Motor BoosterPack
Texas Instruments BOOSTXL-ULN2003 ULN2003A Dual Stepper Motor BoosterPack
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Geared DC Motor, 12 V
Geared DC Motor, 12 V
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Ultrasonic Sensor Particle Diagram

This circuit diagram shows the wiring between the Argon and the Ultrasonic Sensor.

Stepper Motor Particle Diagram

This circuit diagram shows the wiring between the Argon, the motor driver, and the stepper motor.

Code

Stepper Motor Control

Arduino
This code is uploaded to the second Particle device and is in charge of controlling the stepper motor that rotates our makeshift H-bridge. When the first Particle device publishes that a can is in place, it calls a function that rotates the H-bridge on the back, allowing us to rotate the bridge and reverse the polarity of the motor to both crush the can and move the arm back into place to prepare for the next can.
// This #include statement was automatically added by the Particle IDE.
#include <Stepper.h>



// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

//defining variable for number of cans crushed so far
int numcans = 0;

const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, D2, D3, D4, D5);


//ubidots webhook setup
const char *WEBHOOK_NAME = "Ubidots";
Ubidots ubidots("webhook", UBI_PARTICLE);

//
void canCrush(const char *event, const char *data)
{
   //motor code placeholder
   
  myStepper.step(509);
  delay(60000);
  
    myStepper.step(-1019);
  delay(60000);
   
     myStepper.step(509);
  delay(60000);
   
   //adds a can crushed everytime function is called
   numcans++;
   
   //ubidots code sending
   ubidots.add("Number of Cans Crushed Today", numcans);
    ubidots.send(WEBHOOK_NAME, PUBLIC);
   
   //communicate with other particle
   Particle.publish("can-crushed");
}


void setup() {
    
    myStepper.setSpeed(60);
    Serial.begin(9600);
    
    //receive communication from other particle
Particle.subscribe("can-present", canCrush);
}

void loop() {

}

Ultrasonic Sensor

Arduino
This code is uploaded to the first Particle Argo, which gets a distance reading. This allows the motor and the other Particle device to know when a can that needs to be crushed is present. Once the sensor reads a value of < 2 centimeters, it publishes to the cloud that there is a can in place.
// defines pins numbers
const int trigPin = D4;
const int echoPin = D5;
// defines variables
long duration;
int distance;

void processStart(const char *event, const char *data)
{
    Serial.print("Number of Cans Crushed");
    Serial.println(distance);
}

void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication

Particle.subscribe("can-crushed", processStart);
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
//publish to other particle
if (distance <= 2){
    Particle.publish("can-present");
    delay(150000);
}
}

Credits

Ian Knapp
1 project • 0 followers
Justin Wiseman
1 project • 0 followers

Comments