Hello everyone,
This is my very first post but I've been lurking for a few days (continuously)
I love the look, cost, ethos of Arduino and have ended up here from research into RepRap 3D Printers.
I am currently in the embodiment stage of a University Mechanical Design Engineering Project.
We are making a machine that can grind, heat, extrude, cool and spool plastic bottles for use as the RepRap feedstock.
As I say we're on our way and have a few ideas about how it will work. My programming background is a few projects with National Instruments LabVIEW and their CompactRIO.
This was my obvious choice for a control system for our project, but we would ultimately love to have it Open-Source, like RepRap
Enter Arduino!
So I thought I would give it a go and have spent the last day slapping together the sort of code I thought would be necessary to drive our Shredder.
Could someone take a look at it and comment as to its feasibility.
I think its also important to mention that the extruder and spooler will have similar control programmes that would have to all be run by the Arduino simultaneously, is that possible?
I'll stick with Arduino on a personal level anyway, looks fantastic!
Thanks for your time guys!
Chris
//Shredder Code
//code designed to run a shredder to shred plastic bottles.
//all of the components used are described below:
//define constants
const int shredTime = 5000 ; //changing the value of this constant varies the duration the motor is on for
const int ledPrimedPin = 5 ; //an LED that represents the shredder being in the Primed Case, attached to pin 5
const int ledActivePin = 6 ; //an LED that represents the shredder being in the Active Case. attached to pin 6
const int buttonShredPin = 7 ; //a push button used to move into the Active Case, attached to pin 7
const int buttonStopPin = 8 ; //a push button used as a Stop Button [NOT YET USED], attached to pin 8
const int buttonSafetyPin = 9 ; //a group of push buttons connected in series to determine the integrity of the shredding chamber, attached to pin 9
const int shredMotorPin = 10 ; //a Solid State Relay used to connect the Shredder Motor to it's power source, attached to pin 10
const int doorLatchPin = 11 ; //a Solid State Relay used to connect the Magnetic Door Latch to it's power source, attached to pin 11
//define variables
int shredCase = 0 ; //variable represents the case that the programme moves to
int lastShredCase = 0 ; //variable which remembers the last case that the programme was in [NOT USED BUT THOUGHT IT MAY BE NECESSARY?]
int ledPrimedState = HIGH ; //variable used to assign a value to the Primed LED
int ledActiveState = HIGH ; //variable used to assign a value to the Active LED
int buttonShredState = HIGH ; //variable used to store the value of the Shred Button
int buttonStopState = HIGH ; //variable used to store the value of the Stop Button [NOT YET USED]
int buttonSafetyState = HIGH ; //variable used to store the value of the Safety Buttons
int shredMotorState = HIGH ; //variable used to assign a value to the Shredder Motor Relay
int doorLatchState = HIGH ; //variable used to assign a value to the Magnetic Door Latch Relay
//Allocate pins as Input or Output
void setup()
{
pinMode(ledPrimedPin, OUTPUT) ;
pinMode(ledActivePin, OUTPUT) ;
pinMode(buttonShredPin, INPUT) ;
pinMode(buttonStopPin, INPUT) ;
pinMode(buttonSafetyPin, INPUT) ;
pinMode(shredMotorPin, OUTPUT) ;
pinMode(doorLatchPin, OUTPUT) ;
}
//run the actual programme
//this will be a state machine and may take some doing...
void loop()
{
switch(shredCase) {
case 0: //IDLE CASE
ledPrimedState = LOW ; //the LEDs need to be set to high or low in each case
digitalWrite(ledPrimedPin, ledPrimedState) ; //the idle case uses neither.
ledActiveState = LOW ;
digitalWrite(ledActivePin, ledActiveState) ;
buttonSafetyState = digitalRead(buttonSafetyPin) ; //the progression from this case relies on safety switches
if(buttonSafetyState = LOW){ //safety button circuit will be pulled down. LOW is safe, HIGH is unsafe
shredCase = 1 ; //allows the programme to progress to Case 1 on next loop
lastShredCase = 0; //remembers that Case 0 was that which was called for this loop
}
else {
shredCase = 0 ; //the only thing that can happen here is progression or no change.
lastShredCase = 0; //therefore anything other than the safety going LOW forces the Case to not change.
}
break; //break defines the end of the case - I'm hoping that at this point it starts the Loop again?
case 1: //PRIMED CASE
ledPrimedState = HIGH ; //again the LEDs are set
digitalWrite(ledPrimedPin, ledPrimedState) ;
ledActiveState = LOW ;
digitalWrite(ledActivePin, ledActiveState) ;
buttonShredState = digitalRead(buttonShredPin) ; //both the Safety and Shred Buttons are checked
buttonSafetyState = digitalRead(buttonSafetyPin) ;
if(buttonShredState = HIGH && buttonSafetyState = LOW) { //if the Shred Button has been pressed and the Safety Circuit is complete (LOW) then the case progresses
shredCase = 2 ;
lastShredCase = 1 ;
}
else if(buttonShredState = LOW && buttonSafetyState = LOW) { //no change of state if the Shred Button isn't pressed
shredCase = 1 ;
lastShredCase = 1 ;
}
else if(buttonSafetyState = HIGH) { //if the Safety Circuit goes HIGH then the programme returns to the Idle Case, 0.
shredCase = 0 ;
lastShredCase = 1 ;
}
break;
case 2: //ACTIVE CASE
ledPrimedState = HIGH ; //LEDs are set, at the moment it has been decided that both Primed and Active should be on here
digitalWrite(ledPrimedPin, ledPrimed State) ;
ledActiveState = HIGH ;
digitalWrite(ledActivePin, ledActiveState) ;
buttonSafetyState = digitalRead(buttonSafetyPin) ; //since the shred button has already been used, just the safety is read here
if(buttonSafetyState = LOW) { //this action section is the actual action of shredding
doorLatchState = HIGH ;
digitalWrite(doorLatchState, doorLatchPin) ; //first off, the lid is Magnetically held shut. Magnet latch is on a SSR
shredMotorState = HIGH ; //secondly, the Shredder Motor is turned on. Motor also on a separate SSR
digitalWrite(shredMotorState, shredMotorPin) ;
delay(shredTime) ; //the Shred Time is used as a delay, leaving the motor running for a certain amount of time.
shredMotorState = LOW ; //after the wait is over the Motor power is cut
digitalWrite(shredMotorState, shredMotorPin) ;
doorLatchState = LOW ; //after the Motor has powered down, the door is released.
digitalWrite(doorLatchState, doorLatchPin) ;
shredCase = 1 ; //now the programme is sent back to the Primed Case
lastShredCase = 2 ;
}
else if(buttonSafetyState = HIGH) { //the only other outcome is if the Safety Circuit is broken, then the programme returns to the Idle Case
shredCase = 0 ;
lastShredCase = 2
}
break ;
}
}