Push button starter (first sketch)

This is my first sketch. I’m working on a push button start system for my vehicle.
I have a few seeduino xiao’s and some generic hardware (relays, switches, etc).
I haven’t worked on the actual wiring yet, I’m just working on principle. I’ve been working on this for hours now. Basically i have 2 relays, one to control the main power switch, the other to control the starter solenoid. One push of the button will turn on the main power, a second will start the vehicle, a third will kill it. Upon writing this i realize i need to have the starter relay only activate until the vehicle cranks or a set maximum amount of time. Any advice would be extremely helpful.

#define Main 7
#define Start 8

int led = 6;
int button = 1;
int buttonCount = 0;
int buttonVar = 0;

void setup() {
// put your setup code here, to run once:
pinMode (1, INPUT_PULLUP);
pinMode (6, OUTPUT);
pinMode (Main, OUTPUT);
pinMode (Start, OUTPUT);


void loop() {
// put your main code here, to run repeatedly:
int buttonVar = digitalRead(1);

if (buttonVar = 1) {
buttonCount = buttonCount + 1;
for (int buttonSwitch = 0; buttonSwitch <= 2; buttonSwitch + 1) {

switch (buttonCount) {
case 2:
digitalWrite(Start, HIGH);
digitalWrite(Main, HIGH);
case 1:
digitalWrite(Main, HIGH);
digitalWrite(Start, LOW);
digitalWrite(Main, LOW);


Using a microprocessor to detect when the engine has successfully started is not a simple thing.

I suggest you do NOT use one button for everything - it has the potential to make for a confusing user experience. For example someone might accidentally press the button 3 times when they only intended to press it twice. At the very least I suggest a separate stop button.

A simple button start system will make your vehicle very easy to steal.

If this is a vehicle for use on public roads you need to get approval from your vehicle insurer before you make the change.

Automotive relays require 12v so cannot be controlled directly from an Arduino. You need a transistor (or another Arduino compatible relay) between the Arduino and the automotive relay.


You will also have to account for button bounce - a single press of a button is typically read as multiple keypresses in quick succession (over the span of a few ms) by the Arduino.

Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What model Arduino are/will you be using?

Thanks.. Tom.. :slight_smile: