//Shredder Code//code designed to run a shredder to shred plastic bottles.//all of the components used are described below:

//define constantsconst int shredTime = 5000 ; //changing the value of this constant varies the duration the motor is on forconst int ledPrimedPin = 5 ; //an LED that represents the shredder being in the Primed Case, attached to pin 5const int ledActivePin = 6 ; //an LED that represents the shredder being in the Active Case. attached to pin 6const int buttonShredPin = 7 ; //a push button used to move into the Active Case, attached to pin 7const int buttonStopPin = 8 ; //a push button used as a Stop Button [NOT YET USED], attached to pin 8const int buttonSafetyPin = 9 ; //a group of push buttons connected in series to determine the integrity of the shredding chamber, attached to pin 9const int shredMotorPin = 10 ; //a Solid State Relay used to connect the Shredder Motor to it's power source, attached to pin 10const int doorLatchPin = 11 ; //a Solid State Relay used to connect the Magnetic Door Latch to it's power source, attached to pin 11

//define variablesint shredCase = 0 ; //variable represents the case that the programme moves toint 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 LEDint ledActiveState = HIGH ; //variable used to assign a value to the Active LEDint buttonShredState = HIGH ; //variable used to store the value of the Shred Buttonint 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 Buttonsint shredMotorState = HIGH ; //variable used to assign a value to the Shredder Motor Relayint doorLatchState = HIGH ; //variable used to assign a value to the Magnetic Door Latch Relay

//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 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 ; }}

1: "if(buttonShredState = HIGH && buttonSafetyState = LOW)" This works flawlessly. It assigns 'HIGH' to buttonShredState and LOW to buttonSafetyState, which makes the && comparison compare HIGH and LOW, which results in false. A double = (==) is the thing you want to use here. Also, it is good practice to contain each comparison in its own set of brackets.

2: lots of comments. Which is good, but most don't say anything. Plenty of things can be geussed from the name of the variable, but the important details aren't mentioned.For instance:

Quote

const int shredTime = 5000 ; //changing the value of this constant varies the duration the motor is on for

shredTime.. the time it takes to shred? Lets have a look at the comment.. the duration the motor is on.. geussed as much. Now.. 5000... seconds? thats over an hour! Try to explain all the criteria the variable works under, and what unit(s) it uses (if any).

And yes, you can make it do multiple things, see the blinkWithoutDelay example on how to avoid delays. You'd probably put what you have in the loop function right now in its own, and turn the delays into delays based on the blinkWithoutDelay example. You could then make a similiar function for the other processes, and simply call each one from loop. The key thought process is, the arduino can only do one thing at a time. So whenever it should be waiting, let it do something else and return to your initial task when the time it should've been waiting is over. The trick is getting it to switch its task

PS: its nice that you add comments, too few people do this. I just figured I'd give you a little bit of advice to make the habbit even better

Is there a certain value of voltage that the Arduino analogue Ins can pick up on?

The default for the 10 bit (0-1023 counts) A/D hardware for the Arduino is 0 to +5vdc, no negative voltage allowed. However by enabling internal voltage references and/or applying an external reference voltage to the aref pin one can have a lower top of range voltage represent 1023 counts.

I do believe it does.But be warned, you can't exceed that roof (it can't output a bigger number).

As for the functions, they're valid function structures. They have a return type (void, as in, it returns nothing), a name, and a collection of parameters (you defined them without any).

Can't help you with the hardware, not my area of expertise

As for using this topic for your generic project inquiries, you may most definitly do this. It keeps the information regarding your project in a single location, making it easier for us to provide assistance.

so bringing the roof down increases the resolution? does that change apply to all analogue pins simultaneously?

Yes it does and it does apply to all the analog pins. However you can change the reference used between the various options at run time. That is you could change a reference then read a specific input pin and then change the reference back to read a different analog input pin. But note that there is a settling time after changing references and one needs to do a few dummy reads before the value is valid. Best to read up on the subject in the Atmel datasheets if planning on using external or optional reference voltages.Lefty

was just wondering what sort of power supply you guys use? I know the wall plug for the arduino can give a bit of juice but obviously I'm going to need something with a bit more kick for a 12V DC Motor that can swallow around 15A.

I know the wall plug for the arduino can give a bit of juice but obviously I'm going to need something with a bit more kick for a 12V DC Motor that can swallow around 15A.

If on a budget a popular route is to use a suitable PC power supply modded for standalone operation. However there are good buys to be found on E-bay and surplus electronics on-line stores for such power supplies. At that current level a switching power supply makes a lot more sense then the old linear power supplies.

So my exams are over and its back to the project. I've got a few questions about physically wiring the stuff up:

1. Pull ups and downs. I get the idea but how do you know how big a resistor you should use?

2. Any general advice for wiring and terminal standards? I'm looking at using an LCD along with all the other bits and it feels like I'm going to be using every pin on the MEGA. How do you avoid getting lost? Is there some generic break-out that allows the use of screw terminals ontop of the standard Arduino headers? What's the wiring convention that Arduinos use on their pins?

3. Any recommended maximum lengths before TTL voltages get lost?

4. I found Arduino through RepRap where they talk about Molex connectors, is this a good standard to adopt?