Hi
Newbie here so greetings to all.
Electrician by Trade but sadly not a programmer.
I am at a dead end with regards to this one, so a bit of help would be appreciated .
I am trying to program a simple train shuttle on a straight piece of track
so, the train Travels from left to right stops at the end of the track for 10 seconds
then travels from right to left and stops for a further 10 seconds.
I am using 2 relays to reverse the polarity
and one relay for killing the power Needed to stop the train at the end of its travel
there is 1 inferred sensor mounted at each end of the track.
I can't seem to get out of the if and else statement
The shabby code so far not finished
Thanks in advance
Laurence
//shuttle
int powerrelay = 1; // relay 1
int posrelay = 2;
int negrelay = 3;
int leftsensorinput = 10;
int rightsensorinput = 11;
int ls = 0; //this variable will read the value from the left sensor
int rs = 0; //this variable will read the value from the right sensor
void setup()
{
pinMode(powerrelay, OUTPUT); //declare the power relay as output
pinMode(posrelay, OUTPUT); //declare the pos relay as output
pinMode(negrelay, OUTPUT); //declare the neg relay as output
pinMode(leftsensorinput, INPUT); //declare infrared sensor as input
pinMode(rightsensorinput, INPUT); //declare infrared sensor as input
}
void loop(){
ls = digitalRead(leftsensorinput); // read input value from the left sensor
if (ls == HIGH) { //check if the input is HIGH
digitalWrite(powerrelay,LOW); // LOW = ON
digitalWrite(posrelay, HIGH); // HIGH = OFF
digitalWrite(negrelay, HIGH); // HIGH = OFF
}
else {
digitalWrite(powerrelay, HIGH); // HIGH = OFF
digitalWrite(posrelay, HIGH); // relay POS turned off
digitalWrite(negrelay, HIGH); // relay NEG turned off
}
{
delay(10000); // wait time for 10 seconds
digitalWrite(powerrelay,LOW); //
digitalWrite(posrelay, LOW); //
digitalWrite(negrelay, LOW); //
}
}

