jeep kart fuel injection works...... mostly

i got the install done and the engine runs smooth and starts very fast
it revs good but rich for now. i have the kart powering the UNO by the USB.
if i have the UNO powered by the laptop and try to start the kart by that, it does not start
i think i need to power it by the round 12V plug

pretty stocked so far

i notice when the laptop is powering the UNO it will read teh TPS voltage but does not add up the pulse time
it will only add in the first adder but not the rest

byte Hall =     2;           // Digital Input pin for rotation sensor, one pulse per revolution
byte injector = 6;           // Digital Output Pin for turning on the injector solenoid
byte TPS =     A0;           // Analog Input Pin for the throttle
int  pulse_time;             // Duration of injector pulse
int  analog_voltage;

void setup() {

   Serial.begin(9600);                        
   pinMode(Hall, INPUT_PULLUP);
   pinMode(TPS, INPUT);
   pinMode(injector, OUTPUT);

   delay (100);                          //  wait for fuel pressure
   digitalWrite(injector,HIGH);          //  start primer
   delay (10);
   digitalWrite(injector,LOW);           //  end primer
}  

void loop() {

  while (digitalRead(Hall)==LOW) {}       // Do nothing until the sensor goes high

  analog_voltage=analogRead(TPS);         // engine load by throttle positioning

  pulse_time=6;                           // idle ms
 
  if      (analog_voltage>= 150) pulse_time+=4;        // adding up fuel by throttle position
  else if (analog_voltage>= 250) pulse_time+=4;        
  else if (analog_voltage>= 350) pulse_time+=3;        
  else if (analog_voltage>= 450) pulse_time+=2;      
  else if (analog_voltage>= 550) pulse_time+=1;         
  else if (analog_voltage>= 650) pulse_time+=1;       
  else if (analog_voltage>= 750) pulse_time+=1;        
  else if (analog_voltage>= 850) pulse_time+=1;        
  else if (analog_voltage>= 950) pulse_time+=1;        

  Serial.println(pulse_time);                     // bunch of jibberish to ponder
  Serial.println(analog_voltage);

  digitalWrite(injector,HIGH);                    // Turn the injector on
  delay(pulse_time);                              // Amount of time to leave the injector on
  digitalWrite(injector,LOW);                     // Turn the injector off

   while (digitalRead(Hall)==HIGH){}              // Wait for LOW
 
}  // End of loop()

Look at your if/else structure. Suppose the value of analog_voltage is 450.

Your first test (is it greater than or equal to 150?) is true and so all other adders are ignored.

ok so it does only one of the conditions.
for some reason i thought it was adding them all up as it gets past there threshold

EDIT
ooooooooooo i see, so it needs a better way to add in there.

something more like? would this be adding up each one that is true into the pulse time?

 pulse_time=6;                           // idle ms
 
  while  (analog_voltage>= 150) pulse_time+=1;        // adding up fuel by throttle position
  while  (analog_voltage>= 250) pulse_time+=1;       
  while  (analog_voltage>= 350) pulse_time+=1;       
  while  (analog_voltage>= 450) pulse_time+=1;     
  while  (analog_voltage>= 550) pulse_time+=1;         
  while  (analog_voltage>= 650) pulse_time+=1;       
  while  (analog_voltage>= 750) pulse_time+=1;       
  while  (analog_voltage>= 850) pulse_time+=1;       
  while  (analog_voltage>= 950) pulse_time+=1;

video proof

pics of the system

ok is this better, closer or even possible?

int  analog_voltage;
int  pulse_time; 

void loop() {
for (pulse_time=6; analog_voltage>= 150;pulse_time+=2;)
     break 
for (pulse_time=6; analog_voltage>= 250;pulse_time+=2;)
     break 
for (pulse_time=6; analog_voltage>= 350;pulse_time+=2;)
     break 
}

Not sure what that's trying to do. How about:

const byte Hall =     2;           // Digital Input pin for rotation sensor, one pulse per revolution
const byte injector = 6;           // Digital Output Pin for turning on the injector solenoid
const byte TPS =     A0;           // Analog Input Pin for the throttle

int  
    analog_voltage;
byte
    nowHall,
    lastHall;
bool
    bInjFiring;    
unsigned long
    pulse_time,
    tInj;
    
//first table assumes TPS reads low when closed; no additional fuel is needed to +4mS at WOT
const unsigned long
    BasePulseWidth = 6000,
    tps_map[] = { 0, 1000, 1000, 1000, 1000, 2000, 3000, 4000, 4000 };

//original table; TPS reads 0V at WOT?
//unsigned long byte tps_map[] = { 4000, 4000, 3000, 2000, 1000, 1000, 1000, 1000, 1000 };

void setup() 
{
   Serial.begin(9600);                       
   
   pinMode(Hall, INPUT_PULLUP);
   lastHall = digitalRead( Hall );
   
   pinMode(TPS, INPUT);   
   pinMode(injector, OUTPUT);

   delay (100);                          //  wait for fuel pressure
   digitalWrite(injector,HIGH);          //  start primer
   delay (10);
   digitalWrite(injector,LOW);           //  end primer

   bInjFiring = false;
   
}//setup 

void loop() 
{
    nowHall = digitalRead(Hall);
    if( nowHall != lastHall )
    {
        lastHall = nowHall;
        if( nowHall == HIGH )
        {
            //turn on the injector
            bInjFiring = true;
            digitalWrite( injector, HIGH );
            tInj = micros();

        }//if
        else
        {
            //idle base pulse
            pulse_time = BasePulseWidth;
            //open TPS adjustment
            analog_voltage=analogRead(TPS);                 // engine load by throttle positioning
            int idx = map( analog_voltage, 0, 0123, 0, 8 );
            while( idx )
                pulse_time += tps_map[idx--];
                            
        }//else
        
    }//if

    if( bInjFiring )
    {
        if( micros() - tInj >= pulse_time )
        {
            digitalWrite( injector, LOW );
            bInjFiring = false;
            
        }//if
        
    }//if
    
}//loop

What is your TPS output voltage when closed? WOT?

Tps will print about 135 at idle and 900 + some change at full throttle

I just need some conditions of the tps input that increase the fuel delay that i can adjust.
This is a delay amount per crank rotation
So far i am amazed at how well it runs with very little input.

i spent some time running your code and tuning some of it
the motor seems to run pretty rich even after cutting fuel way down.
the UNO shuts down after about 10 seconds so i think i need to get that done now
i have some opto isolator boards coming soon
i have some big Schottky diodes now though
not 100% how to implement them

SB5100-T 100V 5A

man! i did some reading and successfully put this together and it runs great! for minutes…
why is black fins soo much more agressive to the UNO???

byte Hall =     2;           // Digital Input pin for rotation sensor, one pulse per revolution
byte injector = 6;           // Digital Output Pin for turning on the injector solenoid
byte TPS =     A0;           // Analog Input Pin for the throttle
int  pulse_time;             // Duration of injector pulse
//int  analog_voltage;         // TPS input
const int tpsmin = 150;
const int tpsmax = 1000;

void setup() {

   Serial.begin(9600);                        
   pinMode(Hall, INPUT_PULLUP);
   pinMode(TPS, INPUT);
   pinMode(injector, OUTPUT);

   delay (300);                          //  wait for fuel pressure
   digitalWrite(injector,HIGH);          //  start primer
   delay (50);
   digitalWrite(injector,LOW);           //  end primer
}  

void loop() {
   while (digitalRead(Hall)==LOW){}                        // do nothing
   
  int analog_voltage=analogRead(TPS);                      // engine load by throttle positioning
  int load = map(analog_voltage, tpsmin, tpsmax, 0, 5);
  pulse_time=6;                                            // idle ms

  switch (load)
  {
    case 0:
     pulse_time+=0;
     break;

    case 1:
     pulse_time+=3;
     break; 

    case 2:
     pulse_time+=5;
     break;

    case 3:
     pulse_time+=6;
     break; 

    case 4:
     pulse_time+=7;
     break;

    case 5:
     pulse_time+=8;
     break; 
  }
          
  Serial.println(pulse_time);                     // bunch of jibberish to ponder
  Serial.println(load);

  digitalWrite(injector,HIGH);                    // Turn the injector on
  delay(pulse_time);                              // Amount of time to leave the injector on
  digitalWrite(injector,LOW);                     // Turn the injector off

   while (digitalRead(Hall)==HIGH){}              // Wait for LOW
}

turbothis:
why is black fins soo much more agressive to the UNO?????

I don't know what you mean.

well yours if i rev it up some, the UNO will turn off or reset or something
mine just sits there and runs forever.

i need to get some kind of gauge on the UNO to see its injector pulse output and load input
then if the gauges say nothing then the UNO shut off?

anything in my code that can be made better?
i guess like millis instead of delay

I noticed an error in my code but am not sure it plays a role in what you're seeing.

This:

int idx = map( analog_voltage, 0, 0123, 0, 8 );

was intended to be

int idx = map( analog_voltage, 0, 1023, 0, 8 );

Also, how clean is your Hall sensor input signal? Any chatter/noise during transitions?

i did see that and adjusted it to 1000
i have a scope but dont know how to use it for crap! :o

i think this looks fine?

Yup, that looks great.

Honestly, if your code using delay() and while() works, you might just want to leave it there.

Just for s__ts and giggles, you can try this slightly modified version to see if it’s more stable:

const byte Hall =     2;           // Digital Input pin for rotation sensor, one pulse per revolution
const byte injector = 6;           // Digital Output Pin for turning on the injector solenoid
const byte TPS =     A0;           // Analog Input Pin for the throttle

const int kTPSMin = 150;
const int kTPSMax = 1000;

int 
    analog_voltage;
byte
    nowHall,
    lastHall;
bool
    bInjFiring;   
unsigned long
    pulse_time,
    tInj;
   
//first table assumes TPS reads low when closed; no additional fuel is needed to +4mS at WOT
const unsigned long
    BasePulseWidth = 6000,
    tps_map[] = { 0, 1000, 1000, 1000, 1000, 2000, 3000, 4000, 4000 };

//original table; TPS reads 0V at WOT?
//unsigned long byte tps_map[] = { 4000, 4000, 3000, 2000, 1000, 1000, 1000, 1000, 1000 };

void setup()
{
   Serial.begin(9600);                       
   
   pinMode(Hall, INPUT_PULLUP);
   lastHall = digitalRead( Hall );
   
   pinMode(TPS, INPUT);   
   pinMode(injector, OUTPUT);

   delay (100);                          //  wait for fuel pressure
   digitalWrite(injector,HIGH);          //  start primer
   delay (10);
   digitalWrite(injector,LOW);           //  end primer

   bInjFiring = false;
   
}//setup

void loop()
{
    nowHall = digitalRead(Hall);
    if( nowHall != lastHall )
    {
        lastHall = nowHall;
        if( nowHall == HIGH )
        {
            //turn on the injector
            bInjFiring = true;
            digitalWrite( injector, HIGH );
            tInj = micros();

            //idle base pulse
            pulse_time = BasePulseWidth;
            //open TPS adjustment
            analog_voltage=analogRead(TPS);                 // engine load by throttle positioning
            analog_voltage = constrain( analog_voltage, kTPSMin, kTPSMax );
            int idx = map( analog_voltage, kTPSMin, kTPSMax, 0, 8 );
            idx = constrain( idx, 0, 8 );
            while( idx > 0 )
                pulse_time += tps_map[idx--];
                
        }//if
                       
    }//if

    if( bInjFiring )
    {
        if( micros() - tInj >= pulse_time )
        {
            digitalWrite( injector, LOW );
            bInjFiring = false;
           
        }//if
       
    }//if
   
}//loop

But like I said, if yours is doing what you want, why change it?

man i dont understand it at all but your code cuts off after a couple revs. starts right up a little rich but then dies like it starves out of fuel
mine just runs and runs with no trouble :confused:

Well, ya got me. I dunno what to say. I don't see anything that would explain what you report so I suggest just sticking with your code.

ya i dont get it either
makes me always second guess everything

Curious to know if you ever tried that Duratec? How many projects do you have on the go?