One time use only switch

Hi All,

I am new to the forum & wondered if I could get some advice

I have installed a touch sensor into my vehicles starting system

so basically when i touch the sensor the Arduino sends a signal to a relay which then turns the starter motor of the car

the thing is I only want the touch sensor to work once so that the starter doesnt engage whilst the engine is running

At the moment each time I touch the sensor a signal gets sent to the starter relay each time

Is there a way I can make the sensor work just once when it is touched & never again if it is touched after the engine has started

Code below

// When Sig Output is high, touch sensor is being pressed

#define ctsPin 2

// Pin for capactitive touch sensor

int ledPin = 13;

// pin for the LED

void setup()



pinMode(ledPin, OUTPUT);

pinMode(ctsPin, INPUT);


int ctsValue = digitalRead(ctsPin);

if (ctsValue == HIGH)


digitalWrite(ledPin, HIGH);





Serial.println("not touched");





void loop(){




Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here

Inside the loop() function (and untested)

  static bool started = false ;

  if ( touch sensor is touched && !started ) {

  started = true;

  start the engine



YOU have to replace "touch sensor is touched" with the right thing, and
YOU have to replace "start the engine" with the right thing,
YOU have to come up with a way to set the variable started to false again or the car will never start again.

PLEASE PLEASE PLEASE read the locked posts about the correct way to post, especially about using the Arduino IDE to auto-format (CTRL-T on a PC) and using code tags.

Read oil pressure and only allow if the pressure is less than a set point. That way, if the car stalls, you can restart it without rebooting your processor.

And if it falls below the set point while driving? You have more than an errant starter to deal with anyway.

-jim lee

I think you need to put the code for checking the touch sensor in a loop and escape the loop when the touch is detected. It similar to how to use button to start program

Thank you all for your kind help & advice above

I still have alot of learning to do