Vehicle remote ignition - Some questions.

Sort of like this:

gets command to start> fires ON relay (pin 11)> fires IGNITION relay (Pin 10)> senses car has started from the alternator charge +12v> turns off IGNITION relay> Waits for brake switch input, if none, shuts off car after 10 minutes> starts code from beginning (waits for input from serial/cell shield)

My car's battery is massive, i'm not worried about the draw from arduino, and i would include an OFF switch for the arduino if i was going to be leaving it for a few days.

This is what i've come up with.

int ignitionPin = 12;
int onPin = 11;
int ledPin = 13;
int brakePin = 3;
int alternatorPin = 4;
int usbnumber = 0;
void setup() {
    pinMode(onPin, OUTPUT);
    pinMode(ignitionPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(4,INPUT);
    pinMode(3,INPUT);    
    Serial.begin(9600);
}
void loop() {
    if (Serial.available() > 0) {
        usbnumber = Serial.read();
    }
    if (usbnumber > 0) {
      
        digitalWrite(onPin, HIGH);
        delay(5000); //5 second delay because of glow plugs (diesel)
    if (digitalRead(alternatorPin)==LOW) 
       {digitalWrite(ignitionPin,HIGH);} //Would this mean that it senses theres no voltage at ahe alternator pin, then switch on the ignition relay?
       else
       {digitalWrite(ignitionPin,LOW);} //then would this mean once the ignition relay is on, and the car has actually started, that it would then turn off the ignition relay?
       
    if (digitalRead(brakePin)==LOW) 
       {digitalWrite(ledPin,HIGH);} //LED on the dash just to remind you to put key in before pressing the brake
       else
       {digitalWrite(onPin,LOW);} //turns off the car if brake switch is pressed? then the program loops and wait's for another serial input?
       delay(1000);

         
        usbnumber = 0;
    }
}

Regards, Matt :slight_smile:

EDIT: i just tried this code with a push button and such.
Didn't work, it seems the arduino doesn't wait around for an input, for instance, i send a serial command, the ON relay fires, then after 5 seconds the ignition relay fires, then i press the push button (as if it were the alternator input) and nothing happens.

Now i know the switch is wired up fine, because if i hold the push button down and send a serial command, the ignition relay never comes on.

Sorry for being such a codeing noob :\