Sequential gearbox operation

Hi, I’m currently trying to design a programme for a sequential gearbox operation. I will be controlling two sets of solenoids each set controlling a gearbox cable.

I will have 2 main inputs:

Input 1 - Gear up
Input 2 - Gear down

I will have 8 outputs, one for each solenoid.

There are 12 different outcomes depending on inputs+current state. Each outcome operating the solenoids in a certain pattern to mimic a gear change. E.g. output 1 operates solenoid a & b, output 2 operates solenoid a&c… etc

I also need to display the current state on a display, maybe a 7 bit display?

I wanted to know if this is a feasable project with a Arduino?

Any help would be hugely appreciated, please go easy as i’m a bit of a noob. I have attached a flow chart of the whole operation.

I have lots more drawings and tables so i can upload those too if needs be.

Thanks Jonni

A few pictures to show the project in more detail.

Thanks Jonni

It looks like your 'flowchart' is trying to be a state diagram. Perhaps if you drew it as a state diagram it would make more sense. Your states have two exits at the same time and some of your decision points (diamonds) don't have both True and False outputs.

Your first diagram shows opposing "pull" and "push" solenoids to move a thing to any of three positions. I think you will need some centering springs to get to the middle position because there is no guarantee that when you activate opposing 'push' and 'pull' solenoids the thing will center. If you put in the centering springs you can eliminate the 'push' solenoids and cut the complexity in half.

You may want to put a delay on the downshift to Neutral and Reverse. Imagine coasting to a stop at a light and trying to take off only to find you were in 4th gear! Start wanging on the downshift button and if you overshoot you are now in Neutral, or worse: Reverse.

Hi thanks for the reply.

Yes my bad on the flowchart, i've never really used them before so just used it as a way to describe what i hope to achieve.

I thought about centering it with springs but this would require the solenoids to be constantly active which i thought would've been a problem at the time i drew it. Also this would require the pull solenoids to not only apply enough force to engage a gear but also means its fighting against the spring. This wouldn't be a problem but i'm struggling for a powerful enough solenoid as it is :/

And very good shout on the N and R delays, i didn't think of that. I'd be an interesting insurance claim when i reversed over someone... :)

I've started writing the code but only really named the inputs and outputs. How do i start programming what 'state' the gearbox is currently in? Could someone chime in with some tips?

Thanks Jonni

Typically you would use an integer and label the states with numbers but you can get fancy by using an 'enum' (enumeration). This is just a list of names that are automatically assigned numbers:enum {STATE_REVERSE, STATE_NEUTRAL, STATE_FIRST, STATE_SECOND, STATE_THIRD} State; By default the first name is give the value 0 and the number increments by one.

Inside the loop() is a big switch/case statement that selects the code for the current state.

void loop() {
    switch (State) {
    case STATE_REVERSE:
        // Code for when we are in Reverse
        break;  
    case STATE_NEUTRAL:
       // Code for when we are in Neutral
        break;
    }
}

In each state you check for the conditions that would cause a transition to a new state. After you act on the condition (turn outputs on or off, for example) you change the value of State to put the system in the new state. You will stay in a state until something causes a state transition.

If you need a delay between actions, add a state. On the transition to that state, save millis(). In that state you do nothing but check to see if the time has elapsed (a la BlinkWithoutDelay). When the delay time has elapsed, go on to the next state. You need a state for every delay. Some people add a second new state just to save millis() before going on to the delay state but I tend to do it in the state transition code. There are libraries that try to make all this coding easier.

Hi much appreciated :D

I've just written up my first ever program, i have no idea if its correct but verifys okay. Any chance you could have a quick look over it for me, I've put the delay for reverse in the actual second solenoid movement of Neutral>Reverse as it works the same.

As for your description of separate states for delays between gears that's ace as i couldn't figure out a way to stop the state changing twice if i accidentally pulled the gear stick twice in a row :)

Also can i put a small program at the bottom which just controls a display depending on Gearstate? (Large 7 Seg?)

Here’s the program.

Shifter_program_complete__with_neutral_button.ino (6.73 KB)

If this is a manual box, how is the clutch controlled?

eg Renault have made semi-auto boxes like this, and they have problems.... Not an easy job.

And if an auto box, do you intend to replace the existing control lever? if not, how will you arrange priority between the two?

regards

Allan

allanhurst:
If this is a manual box, how is the clutch controlled?

eg Renault have made semi-auto boxes like this, and they have problems… Not an easy job.

And if an auto box, do you intend to replace the existing control lever? if not, how will you arrange priority between the two?

regards

Allan

It will be using a manual box with a manually operated clutch. Although this is only a prototype in my GTO and hope to evolve it into a pneumatic system with automatic clutch for my track car.

Anyone had chance to look over my program?

Thanks Jonni

const int Solenoid1 = 13;

const int Solenoid2 = 12;

const int Solenoid3 = 11;

const int Solenoid4 = 10;

const int GearUP = 9;

const int GearDown = 8;

const int GearNeutral = 7;

const int SEGA = 6;

const int SEGB = 5;

const int SEGC = 4;

const int SEGD = 3;

const int SEGE = 2;

const int SEGF = 1;

const int SEGG = 0;

int Gearstate;

void setup() {
  // put your setup code here, to run once:

pinMode(Solenoid1, OUTPUT);

pinMode(Solenoid2, OUTPUT);

pinMode(Solenoid3, OUTPUT);

pinMode(Solenoid4, OUTPUT);

pinMode(SEGA, OUTPUT);

pinMode(SEGB, OUTPUT);

pinMode(SEGC, OUTPUT);

pinMode(SEGD, OUTPUT);

pinMode(SEGE, OUTPUT);

pinMode(SEGF, OUTPUT);

pinMode(SEGG, OUTPUT);

pinMode(GearUP, INPUT);

pinMode(GearDown, INPUT);

pinMode(GearNeutral, INPUT);

int Gearstate = 1;

}

void loop() {

  // Neutral -----------------------------------------------------------------------------------------

 if (Gearstate == 1) {

  digitalRead(GearUP && GearDown);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid1, HIGH);

    delay(100);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    delay(300);

    Gearstate = 2;
    
  } else {
    
    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 1;

    }

    if (GearDown == HIGH) {
    
    digitalWrite(Solenoid3, HIGH);

    delay(1500);

    digitalWrite(Solenoid2, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid4, LOW);

    delay(300);

    Gearstate = 0;
    
  } else {
    
    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 1;
  }
 }

// First GEAR -----------------------------------------------------------------------------------------------------

 if (Gearstate == 2)

 { digitalRead(GearUP && GearDown);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid2, HIGH);

    digitalWrite(Solenoid3, LOW);

    delay(200);

    Gearstate = 3;
    
  } else {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 2;

    }

    if (GearDown == HIGH) {
    
    digitalWrite(Solenoid4, LOW);

    delay(100);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid2, LOW);

    digitalWrite(Solenoid3, LOW);

    delay(300);

    Gearstate = 1;
    
  } else {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 2;
  }
 }// Second GEAR -----------------------------------------------------------------------------------------------------

 if (Gearstate == 3)

 { digitalRead(GearUP && GearDown);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid2, LOW);

    delay(100);

    digitalWrite(Solenoid1, LOW);

    delay(100);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid3, LOW);

    delay(300);

    Gearstate = 4;
    
  } else {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, HIGH);

    Gearstate = 3;

    }

    if (GearDown == HIGH) {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid2, LOW);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid3, LOW);

    delay(300);

    Gearstate = 2;
    
  } else {
    
    digitalWrite(Solenoid1, HIGH);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, HIGH);

    Gearstate = 3;
  }
 }// Third GEAR -----------------------------------------------------------------------------------------------------

 if (Gearstate == 4)

 { digitalRead(GearUP && GearDown);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid2, HIGH);

    delay(300);

    Gearstate = 5;
    
  } else {
    
    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 4;

    }

    if (GearDown == HIGH) {
    
    digitalWrite(Solenoid4, LOW);

    delay(100);

    digitalWrite(Solenoid1, HIGH);

    delay(100);

    digitalWrite(Solenoid2, HIGH);

    digitalWrite(Solenoid3, LOW);

    delay(300);

    Gearstate = 3;
    
  } else {
    
    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, HIGH);

    Gearstate = 4;
  }
 }
 // Fourth GEAR -----------------------------------------------------------------------------------------------------

 if (Gearstate == 5)

 { digitalRead(GearUP && GearDown);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid2, LOW);

    delay(100);

    digitalWrite(Solenoid3, HIGH);

    delay(100);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid1, LOW);

    delay(300);

    Gearstate = 6;
    
  } else {
    
    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 5;

    }

    if (GearDown == HIGH) {
    
    digitalWrite(Solenoid2, LOW);

    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    delay(300);

    Gearstate = 4;
    
  } else {
    
    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid2, HIGH);

    Gearstate = 5;
  }
 }

 // Fifth GEAR -----------------------------------------------------------------------------------------------------

 if (Gearstate == 6)

 { digitalRead(GearDown);

 if (GearDown == HIGH) {
    
    digitalWrite(Solenoid4, LOW);

    delay(100);

    digitalWrite(Solenoid3, LOW);

    delay(100);

    digitalWrite(Solenoid2, HIGH);

    digitalWrite(Solenoid1, LOW);

    delay(300);

    Gearstate = 5;
    
  } else {
    
    digitalWrite(Solenoid4, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid3, HIGH);

    digitalWrite(Solenoid2, LOW);

    Gearstate = 6;
  }
 }
 // Reverse -----------------------------------------------------------------------------------------------------

 if (Gearstate == 0)

 { digitalRead(GearUP);

  if (GearUP == HIGH) {
    
    digitalWrite(Solenoid2, LOW);

    delay(100);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid1, LOW);

    delay(300);

    Gearstate = 1;
    
  } else {
    
    digitalWrite(Solenoid3, HIGH);

    digitalWrite(Solenoid1, LOW);

    digitalWrite(Solenoid4, LOW);

    digitalWrite(Solenoid2, HIGH);

    Gearstate = 0;

    }   
  }
  {digitalRead(GearNeutral);

  if (GearNeutral == HIGH) {

    digitalWrite(Solenoid2, LOW);

    digitalWrite(Solenoid4, LOW);

    delay(100);

    digitalWrite(Solenoid3, LOW);

    digitalWrite(Solenoid1, LOW);

    Gearstate = 1;
  }
 }
}
int Gearstate = 1;

Because this is inside setup() you are creating a local variable named Gearstate and setting it to 1. That will have no effect on the global variable of the same name. If you want to change the value of the global variable, don't re-declare it as local:

    Gearstate = 1;

Note that if a shift fails or your car is not in Gearstate == 1 (whatever that means) when you start the sketch, your sketch will be out of sync with reality. You should probably add some switches so your sketch can sense the current gear. You should also have a clutch switch so you can avoid shifting with the clutch engaged.

Thanks guys, i have amended the code to sense the gearUP & gearDown inputs on the fly.

I have also amended the int gearstate issue.

In terms of sensing gears then i can use the 6 analog pins i'm not using to sense each gearstate using micro switches attached to the actual cable positions yes?

As for the clutch switch i have already put that in before the other switches so that the Arduino can't sense any gear changes unless the clutch is pressed in.

I have the 7 Seg now running off the Arduino but i think ill be short 2 pins if i add the feed from each gear...

There are 20 digital I/O pins in total right, and Godiva recommended not to use 0 & 1. So that leaves me 18.

3 INPUTS from gears selectors

4 OUTPUTS to Solenoids

7 OUTPUTS to 7 SEG

6 INPUTS from Gearstates

Total 20 :/ Any ideas, maybe? I could lose a 7 SEG OUTPUT and still retain functionality but what else?

johnwasser:
your car is not in Gearstate == 1 (whatever that means)

Gearstate = 1 is Neutral

Surely setting Gearstate to 1 in the setup, via ‘Gearstate = 1’, means that everytime i turn the system on it resets to neutral (Gearstate = 1) no?

Also would

if (digitalRead(X) == HIGH) && (digitalRead(Y) == HIGH) {

Work and only activate that bit if both Y and X Pins were active?

But if i write

'Gearstate = 1'

In the setup then doesnt that set the gearset set to equal 1 so when the loop commences it'll read that gearstate = 1 and then run the neutral code? or is that not how it works.

But yes the mechanical arrangement always resets to neutral once power is cut to the system.

So effectively your're making a 'preselector' gearbox as used on old buses/lorries?

They could preselect any gear from the existing one using hydraulics alone.....

regards

Allan

No worries :)

Heres my tweaked code, i think i'm getting somewhere now...

const int Solenoid1 = 13;

const int Solenoid2 = 12;

const int Solenoid3 = 11;

const int Solenoid4 = 10;

const int GearUP = 9;

const int GearDown = 8;

const int GearNeutral = 7;

const int SEGA = 6;

const int SEGB = 5;

const int SEGC = 4;

const int SEGD = 3;

const int SEGE = 2;

const int SEGF = 15;

const int SEGG = 14;

const int W = 16;

const int X =17;

const int Y =18;

const int Z =19;

int Gearstate;

void setup() {
// put your setup code here, to run once:

pinMode(Solenoid1, OUTPUT);

pinMode(Solenoid2, OUTPUT);

pinMode(Solenoid3, OUTPUT);

pinMode(Solenoid4, OUTPUT);

pinMode(SEGA, OUTPUT);

pinMode(SEGB, OUTPUT);

pinMode(SEGC, OUTPUT);

pinMode(SEGD, OUTPUT);

pinMode(SEGE, OUTPUT);

pinMode(SEGF, OUTPUT);

pinMode(SEGG, OUTPUT);

pinMode(GearUP, INPUT);

pinMode(GearDown, INPUT);

pinMode(GearNeutral, INPUT);

pinMode(W, INPUT);

pinMode(X, INPUT);

pinMode(Y, INPUT);

pinMode(Z, INPUT);

Gearstate = 1;

}

void loop() {

// Neutral -----------------------------------------------------------------------------------------

if (Gearstate == 1) 

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid1, HIGH);

  delay(100);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  delay(300);  {

  if ((digitalRead(X) == HIGH) && (digitalRead(Z) == HIGH))

 {Gearstate = 2;}

 else {Gearstate = 1;}}
}
  else {
  
  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 1;

  }

  if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid3, HIGH);

  delay(1500);

  digitalWrite(Solenoid2, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid4, LOW);

  delay(300);

  {

  if ((digitalRead(Y) == HIGH) && (digitalRead(W) == HIGH))

 {Gearstate = 0;}

 else {Gearstate = 1;}}

 }

 else {
  
  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 1;
}}


// First GEAR -----------------------------------------------------------------------------------------------------

if (Gearstate == 2)

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid2, HIGH);

  digitalWrite(Solenoid3, LOW);

  delay(200);

  { if ((digitalRead(X) == HIGH) && (digitalRead(Y) == HIGH))

 {Gearstate = 3;}

 else {Gearstate = 2;}}
  
} else {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 2;

  }

  if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid4, LOW);

  delay(100);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid2, LOW);

  digitalWrite(Solenoid3, LOW);

  delay(300);

  Gearstate = 1;
  
} else {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 2;
}
}// Second GEAR -----------------------------------------------------------------------------------------------------

if (Gearstate == 3)

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid2, LOW);

  delay(100);

  digitalWrite(Solenoid1, LOW);

  delay(100);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid3, LOW);

  delay(300);

  {if ((digitalRead(Z) == HIGH) && (digitalRead(X) == LOW) && (digitalRead(W) == LOW))

 {Gearstate = 4;}

 else {Gearstate = 3;}}
  
} else {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, HIGH);

  Gearstate = 3;

  }

  if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid2, LOW);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid3, LOW);

  delay(300);

  {if ((digitalRead(X) == HIGH) && (digitalRead(Z) == HIGH))

 {Gearstate = 2;}

 else {Gearstate = 3;}}
  
} else {
  
  digitalWrite(Solenoid1, HIGH);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, HIGH);

  Gearstate = 3;
}
}// Third GEAR -----------------------------------------------------------------------------------------------------

if (Gearstate == 4)

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid2, HIGH);

  delay(300);

  {if ((digitalRead(Y) == HIGH) && (digitalRead(X) == LOW) && (digitalRead(Y) == LOW))

 {Gearstate = 5;}

 else {Gearstate = 4;}}
  
} else {
  
  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 4;

  }

  if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid4, LOW);

  delay(100);

  digitalWrite(Solenoid1, HIGH);

  delay(100);

  digitalWrite(Solenoid2, HIGH);

  digitalWrite(Solenoid3, LOW);

  delay(300);

  {if ((digitalRead(X) == HIGH) && (digitalRead(Y) == HIGH))

 {Gearstate = 3;}

 else {Gearstate = 4;}}
  
} else {
  
  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, HIGH);

  Gearstate = 4;
}
}
// Fourth GEAR -----------------------------------------------------------------------------------------------------

if (Gearstate == 5)

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid2, LOW);

  delay(100);

  digitalWrite(Solenoid3, HIGH);

  delay(100);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid1, LOW);

  delay(300);

  {if ((digitalRead(W) == HIGH) && (digitalRead(Z) == HIGH))

 {Gearstate = 6;}

 else {Gearstate = 5;}}
  
} else {
  
  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 5;

  }

  if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid2, LOW);

  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  delay(300);

  {if ((digitalRead(Z) == HIGH) && (digitalRead(W) == LOW) && (digitalRead(X) == LOW))

 {Gearstate = 4;}

 else {Gearstate = 5;}}
  
} else {
  
  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid2, HIGH);

  Gearstate = 5;
}
}

// Fifth GEAR -----------------------------------------------------------------------------------------------------

if (Gearstate == 6)

{ if (digitalRead(GearDown) == HIGH) {
  
  digitalWrite(Solenoid4, LOW);

  delay(100);

  digitalWrite(Solenoid3, LOW);

  delay(100);

  digitalWrite(Solenoid2, HIGH);

  digitalWrite(Solenoid1, LOW);

  delay(300);

  {if ((digitalRead(Y) == HIGH) && (digitalRead(W) == LOW) && (digitalRead(X) == LOW))

 {Gearstate = 5;}

 else {Gearstate = 6;}}
  
} else {
  
  digitalWrite(Solenoid4, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid3, HIGH);

  digitalWrite(Solenoid2, LOW);

  Gearstate = 6;
}
}
// Reverse -----------------------------------------------------------------------------------------------------

if (Gearstate == 0)

{ if (digitalRead(GearUP) == HIGH) {
  
  digitalWrite(Solenoid2, LOW);

  delay(100);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid1, LOW);

  delay(300);

  Gearstate = 1;
  
} else {
  
  digitalWrite(Solenoid3, HIGH);

  digitalWrite(Solenoid1, LOW);

  digitalWrite(Solenoid4, LOW);

  digitalWrite(Solenoid2, HIGH);

  Gearstate = 0;

  }   
}

if (digitalRead(GearNeutral) == HIGH) {

  digitalWrite(Solenoid2, LOW);

  digitalWrite(Solenoid4, LOW);

  delay(100);

  digitalWrite(Solenoid3, LOW);

  digitalWrite(Solenoid1, LOW);

  Gearstate = 1;
}

[code]

I've just written up my first ever program,

Good luck to you. You have chosen quite an ambitious and potentially dangerous project to start with. If this is a passenger vehicle, make sure you do very thorough functionality testing with the vehicle immobilized (such as lifting the drive wheels) and at very low crawling speed before actually having a live human take it for a spin.

The basic summary of what you want to do is to active solenoids in a specific sequence in response to certain button presses. This is exactly the kind of job microcontrollers are made for, and is likely well within an Arduino's capabilities. The program itself will be easy enough and is a good choice for a starting project to learn about microcontrollers (discounting the safet implications). The only real difficulties you should have with writing the code will be overcoming your own inexperience.

A few people have already started helping you with the software side, so I want to bring up a different issue that might cause you even more of a headache than the software: hardware. This is not a computer program running in the safe ivory tower of your computer monitor, protected from the hustle and bustle by layer upon layer of abstraction in the operating system; this program, and the chip it's running on, directly touches the real world.

Since you're dealing with a gearbox, presumably there's an internal combustion engine involved. Engines are hell for electronics. Take a read through this motorcycle quickshifter to read about the troubles rickerman had with frying chips and phantom button presses when running a Nano off his motorcycle's alternator.

You need to take precautions so that spikes and brownouts on the power supply do not cause your microcontroller and support chips to break or malfunction. You need to harden your switch inputs so that EMI from the engine doesn't cause spurious button presses. You will need some way to check if the transmission has actually shifted the way you commanded it to and is actually in the gear you think it's in.

When designing your program, don't just think about how to make it work, also think about all the ways that it might fail to work, and design it to operate safely. This may include sanity checks on the commands (don't shift into R straight from 4th gear, for example), detecting hardware faults (such as a servo not working), making sure your inputs are robust against environmental influences, and many other things.

Don't expect this to be a weekend job.

Jiggy-Ninja: Good luck to you. You have chosen quite an ambitious and potentially dangerous project to start with. If this is a passenger vehicle, make sure you do very thorough functionality testing with the vehicle immobilized (such as lifting the drive wheels) and at very low crawling speed before actually having a live human take it for a spin.

The basic summary of what you want to do is to active solenoids in a specific sequence in response to certain button presses. This is exactly the kind of job microcontrollers are made for, and is likely well within an Arduino's capabilities. The program itself will be easy enough and is a good choice for a starting project to learn about microcontrollers (discounting the safet implications). The only real difficulties you should have with writing the code will be overcoming your own inexperience.

A few people have already started helping you with the software side, so I want to bring up a different issue that might cause you even more of a headache than the software: hardware. This is not a computer program running in the safe ivory tower of your computer monitor, protected from the hustle and bustle by layer upon layer of abstraction in the operating system; this program, and the chip it's running on, directly touches the real world.

Since you're dealing with a gearbox, presumably there's an internal combustion engine involved. Engines are hell for electronics. Take a read through this motorcycle quickshifter to read about the troubles rickerman had with frying chips and phantom button presses when running a Nano off his motorcycle's alternator.

You need to take precautions so that spikes and brownouts on the power supply do not cause your microcontroller and support chips to break or malfunction. You need to harden your switch inputs so that EMI from the engine doesn't cause spurious button presses. You will need some way to check if the transmission has actually shifted the way you commanded it to and is actually in the gear you think it's in.

When designing your program, don't just think about how to make it work, also think about all the ways that it might fail to work, and design it to operate safely. This may include sanity checks on the commands (don't shift into R straight from 4th gear, for example), detecting hardware faults (such as a servo not working), making sure your inputs are robust against environmental influences, and many other things.

Don't expect this to be a weekend job.

Thanks, given me a few points to think from :)

Power is an issue, is there a possibility of running the whole system, inputs, outputs the lot from a separate 5V battery? as its only main current draw is activating relays and running the arduino.

As for feedback check the new code, I've attached a code that checks if the correct gear engaged, if it did then the code advances to the next gearstate. If not then it stays in the current gearstate. (i could improve this by a failed gearchange resulting in the gearstate resetting to 1-neutral, therefore the wheels won't lock up if my solenoids have had a paddy)

I have a delay on N to R which i can improve on by maybe having to hold an input to engage it or even a totally different input, things to work on.

Regarding protecting from emf this is something i have no experience of and would need to be looked at in serious detail as a phantom 'GearDown' input at 7000rpm in 4th would be disastrous...

The car in question has been a long project from the start that i have installed a standalone ecu, twin turbo'd and even done a auto>manual and AWD>RWD swap. That's my specialty and coming into this world and knowing the squareroot of jack has been a bit of a shock :/