So i am trying to control 3 dc motors with relays and limit switches ,but something always gone wrong ,
i've tryed several diferent codes but ... nothing.
Here my code for now:
int const S3Pin = 13;
int const K3Pin = 2;
int const S1Pin = 12;
int const K2Pin = 3;
int const S2Pin = 11;
int const K1Pin = 4;
int const S4Pin = 10;
int const K2rpin = 5;// relay output for reverse direction
int const K3rpin = 6; //relay output for reverse direction
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(S3Pin, INPUT);
pinMode(K3Pin, OUTPUT);
pinMode(S1Pin, INPUT);
pinMode(K1Pin, OUTPUT);
pinMode(S2Pin, INPUT);
pinMode(K2Pin, OUTPUT);
pinMode(K2rpin, OUTPUT);//relay output for reverse direction
pinMode(K3rpin, OUTPUT);//relay output for reverse direction
pinMode(S4Pin, INPUT);
digitalWrite(K1Pin,LOW);
digitalWrite(K2rpin,LOW);
digitalWrite(K2Pin,LOW);
digitalWrite(K3rpin,LOW);
if (digitalRead(S3Pin) == LOW) { //this lines i hope to find Zero Point of machine
digitalWrite(K3Pin, HIGH); //this lines i hope to find Zero Point of machine
}
while (digitalRead(S3Pin) == LOW) //this lines i hope to find Zero Point of machine
{
}
while(1);
digitalWrite(K3Pin, LOW); //this lines i hope to find Zero Point of machine
}
void loop() {
if(digitalRead(S1Pin)==HIGH and (S3Pin)==LOW)
{digitalWrite(K2Pin, HIGH);
}
while(digitalRead(S3Pin)==LOW)
{
}
digitalWrite(K2Pin, LOW);
delay(500);
digitalWrite(K3Pin, HIGH);
while(digitalRead(S4Pin)==LOW)
{
}
digitalWrite(K3Pin, LOW);
digitalWrite(K2rpin,HIGH);
delay(15000);
digitalWrite(K2rpin,HIGH);
digitalWrite(K3rpin,HIGH);
while(digitalRead(S3Pin)==LOW)
{
}
digitalWrite(K3rpin, LOW);
while(digitalRead(S1Pin)==HIGH and (S3Pin)==LOW)
{digitalWrite(K1Pin,LOW);
}
delay(100);
loop;
}
So can someone tell me where i gone wrong i help me build it .