3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Arduino Controlled Can Crusher With LCD Readout.

Step 4Part 3: Programing and circuit design

Part 3: Programing and circuit design
The Program :

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // LCD on pins 12, 11, 10, 5, 4, 3, 2.
int StartPin = 9;                          // switch input
int motor1Pin = 7;                         // H-bridge leg 1 (pin 2, 1A)
int motor2Pin = 6;                         // H-bridge leg 2 (pin 7, 2A)
int enablePin = 8;                         // H-bridge enable pin
int DirPin = 13;                           // Motor direction select
int DirSwCounter = 0;
int LastDirState = 15;
int Dir = 14;             
int cansCrushed;                       // Initial number of cans crushed set to 0
void setup()
{
// INITIALIZE
pinMode(StartPin, INPUT);
pinMode(DirPin, INPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
lcd.begin(16, 2);
lcd.print("Can Crusher MKII");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Crushed:");
lcd.setCursor(10, 0);
lcd.print((int)cansCrushed);
lcd.setCursor(0, 1);
lcd.print("Weight:");
lcd.setCursor(9, 1);
lcd.print((int)cansCrushed*.034375);      
pinMode(StartPin, INPUT);
pinMode(DirPin, INPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
cansCrushed = 0;
}
void loop()
{
// READ PINS
int DirState = digitalRead(DirPin); 
if (LastDirState == LOW && DirState == HIGH) 
{
DirSwCounter++;
}
LastDirState = DirState;
// PROCESS
if (DirSwCounter % 2 == 0)
{
digitalWrite(Dir, LOW);    
cansCrushed++;
} else {
digitalWrite(Dir, HIGH);
}
if (digitalRead(StartPin) == HIGH && digitalRead(Dir) == LOW)
{
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, LOW);
}
else if (digitalRead(StartPin) == HIGH && digitalRead(Dir) == HIGH)
{
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, LOW);
digitalWrite(motor2Pin, HIGH);
} else {
digitalWrite(enablePin, LOW);
}
}


The wiring diagram for the machine is shown below.
For this design I used Fritzing, it is pretty awesome.
http://www.fritzing.org
Build the circuit board from this design, but don't add the switches yet.

« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
7
Followers
3
Author:MRHint