Skip to content

Instantly share code, notes, and snippets.

@birkir
Last active May 29, 2021 13:27
Show Gist options
  • Save birkir/4691214 to your computer and use it in GitHub Desktop.
Save birkir/4691214 to your computer and use it in GitHub Desktop.
/**
* Arduino based "2-step launch control"
* Works by interrupt power signal to ignition coil.
* Requires RPM and Clutch signal
*
* @author Birkir Gudjonsson (birkir.gudjonsson@gmail.com)
* @licence http://en.wikipedia.org/wiki/BSD_licenses
*/
// settings
int launch = 4000; // rpm to launch at
int step = 25 * 1000; // 25ms stepper
// inputs
int injectorPin = 1; // injector signal
int clutchPin = 2; // clutch
// outputs
int ignitionCoilPin = 4; // ignition coil power (using MOSFET)
// variables
int rpm = 0;
unsigned long lastInterruptTime;
// setup
void setup()
{
// attach interrupt to injectors
attachInterrupt(injectorPin, rpmCalculation, RISING);
// set clutch mode
setPin(clutchPin, INPUT);
// set ign coil as output
setPin(ignitionCoilPin, OUTPUT);
// enable by default
digitalWrite(ignitionCoilPin, HIGH);
// wait 5 seconds
delay(5000);
}
// loop
void loop()
{
// check if actual rpm is equal or greater than launch rpm, and if clutch petal is down
if (rpm >= launch && digitalRead(clutchPin) == HIGH)
{
// cut power to ignition coil for some milliseconds.
digitalWrite(ignitionCoilPin, LOW);
delayMicroseconds(step);
digitalWrite(ignitionCoilPin, HIGH);
delayMicroseconds(step);
}
}
// calculate rpm
void rpmCalculation()
{
unsigned long now = micros();
rpm = 60 / ((now - lastInterruptTime) / 1000000) / 2;
lastInterruptTime = now;
}
@arnarhelgi
Copy link

Why interrupt the injectors? Just interrupting the ignition coil power should work. Anyways awesome project that I will defiantly try out!

@Adriaankenny
Copy link

halo . when i try to verify the program it gives me an error saying set pin was not declared in this scope, it gives the line error on line 32. i am fairly new to programming so a little help would we grate !

@petro1911
Copy link

Adriaankenny
try to replace setPin with pinMode

@Adriaankenny
Copy link

Thank you , now you say you use an injector signal as input , would an rpm input work ? taping into rpm output from the ecu ? it is a 12 v square wave , will this damage the board ?

@yoyokelektro
Copy link

not work rpm calculation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment