Hi I'am new to here so hope I post it properly.Not trying to upset anybody.My project is a can crusher.It is driven by a 180w 12volt motor.But having problems with the program.Have tried everything and spent many a late night trying to get it right.Hopping somebody else might be able to see what I am doing wrong.It is probably the most simple thing. Basically it does work except when the motor is reversing the gate's open again before the motor finishes returning all the way.This allows the next can to load before the motor is fully returned.
#define MRELAY1 8//This is the first gate relay
#define MRELAY2 2//This is for second gate relay
#define MRELAY3 4//This operates a relay switching earth for the motor
#define MRELAY4 3//To switch motor direction reverse
#define MRELAY5 10//To switch motor direction reverse
#define REED1 7//This is to stop the motor in the reverse direction
const int InfraredSensorPin = 11;//This senses a can in the chute
const int MRELAY = 8;
int val2 = 0;
void setup() {
pinMode(MRELAY1, OUTPUT);
pinMode(MRELAY2, OUTPUT);
pinMode(MRELAY3, OUTPUT);
pinMode(MRELAY4, OUTPUT);
pinMode(MRELAY5, OUTPUT);
pinMode(InfraredSensorPin, INPUT);
pinMode(REED1, INPUT);
}
void loop() {
if(digitalRead(InfraredSensorPin) == LOW);
{
delay(3000);
digitalWrite(MRELAY1, HIGH);
delay(2000);
digitalWrite(MRELAY1, LOW);
delay(2000);
digitalWrite(MRELAY5, HIGH);
delay(2000);
digitalWrite(MRELAY5, LOW);
delay(3000);
digitalWrite(MRELAY2, HIGH);
delay(10000);
digitalWrite(MRELAY2, LOW);
delay(3000);
digitalWrite(MRELAY2, HIGH);
digitalWrite(MRELAY4, HIGH);
digitalWrite(MRELAY3, HIGH);
delay(4000);
}
val2 = digitalRead(REED1);
if (val2 == HIGH){
delay(500);
digitalWrite(MRELAY3, LOW);
digitalWrite(MRELAY4, LOW);
digitalWrite(MRELAY2, LOW);
}else{
digitalWrite(MRELAY1, LOW);
}
}
Thank you any help you my be able to give.
Regards
Grant