Conversion project carbureted engine to electronic injection with Arduino

Hi everybody, i’m doing a basic engine injection project with arduino, for this project i’ve a Arduino UNO board with ATMega328P and the motor is from a Seat 127 with carburetion, the problem is that i’ve some question and problems with my code. I hope somebody can help me.

I want when I accelerate the injector injects fuel faster, and when the temperature is high or low inject more or less fuel fast.

I did some things about it.

Well this is the code and i’ll be grateful for any help.

int pinInyector = 9;                    //Output pin for the injector
volatile int state = LOW;               //Initial state interruption
const int temp = 8;              // Temp sensor
const int throttle = 10;

int valor = 0;
int ledindicador = 6;                   // Led to see the injection time


void setup()
{
  pinMode(pinInyector, OUTPUT);         //Pin configured to output signal to injector
  attachInterrupt(0, interrup, RISING);
  pinMode(temp, INPUT);
  pinMode(ledindicador, OUTPUT);
  pinMode(throttle, INPUT);      


  Serial.begin(9600);
 
   digitalWrite(9, HIGH);
   delay(1500);
   digitalWrite(9, LOW);
   delay(63);
}                       




void interrup()
{
  digitalWrite (pinInyector, HIGH); //Fuel injected 50 milliseconds
  delay (50);
  digitalWrite (pinInyector, LOW);  //Interrupts injection 50 milliseconds
  delay (50);
  digitalWrite (pinInyector, HIGH); //Fuel injected 50 milliseconds
  delay (50);
  digitalWrite (pinInyector, LOW);  //Stops feeding to detect a new flank
}

void loop()
{
  
  
int valortemp = analogRead(temp);
int power = analogRead(throttle);

  while(temp > 256)
  {
if(throttle >= 0)
{
    digitalWrite(pinInyector, HIGH);
    digitalWrite(ledindicador, HIGH);
    delay(30);
    digitalWrite(pinInyector, LOW);
    digitalWrite(ledindicador, LOW);
    delay(30);
}
    if(valortemp > 540)
    {
      digitalWrite(pinInyector, HIGH);
      digitalWrite(ledindicador, HIGH);
      delay(50);
      digitalWrite(pinInyector, LOW);
      digitalWrite(ledindicador, LOW);
      delay(50);
    }
     if(valortemp <= 256)
    {
    digitalWrite(pinInyector, HIGH);
    digitalWrite(ledindicador, HIGH);
    delay(100);
    digitalWrite(pinInyector, LOW);
    digitalWrite(ledindicador, LOW);
    delay(100);
    }
    if(valortemp <= 96)
    {
    digitalWrite(pinInyector, HIGH);
    digitalWrite(ledindicador, HIGH);
    delay(150);
    digitalWrite(pinInyector, LOW);
    digitalWrite(ledindicador, LOW);
    delay(150);
    }
    


  }
}

Thanks for your time :slight_smile:

You cannot call delay() in an interrupt routine as it will hang the processor forever.