Injector driver

Hi! I’m trying to control a digital output for a basic injectortester. I want a High (0-20ms) and a Low (0-300ms) and a timer 0-60 but i can’t get it to work. My program looks like this (most copy/paste code):

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//KNAPPAR DEF
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnUP (0)
#define btnDOWN (1)
#define btnSELECT (2)
#define btnNONE (3)
#define btnRIGHT (4)

// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result

if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 90) return btnNONE;
if (adc_key_in < 150) return btnUP;
if (adc_key_in < 300) return btnDOWN;
if (adc_key_in < 650) return btnSELECT;

return btnNONE; // when all others fail, return this…
}
//KNAPPAR DEF
float pulse;

void setup() {
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
lcd.print(" Time to");
lcd.setCursor(0,1);
lcd.print(" Flow!");
delay(3000);
lcd.clear();
}

void loop(){

int sensorValue = analogRead(A1);
lcd.setCursor(0,0);
lcd.print("Pulse: ");
lcd.setCursor(7,0);
lcd.print(pulse);
lcd.setCursor(0,1);
lcd.print(“Select for start”);
lcd_key = read_LCD_buttons();

switch (lcd_key) // depending on which button was pushed, we perform an action
{

case btnUP:
{
pulse = pulse+0.5;
lcd.setCursor(7,0);
lcd.print(pulse);
delay(250);
break;
}

case btnDOWN:
{
pulse = pulse-0.5;
lcd.setCursor(7,0);
lcd.print(pulse);
delay(250);
break;
}

case btnSELECT:
{
delay(250);
lcd_key = read_LCD_buttons();
start:
if(lcd_key!=btnSELECT){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pulse: ");
lcd.setCursor(7,0);
lcd.print(pulse);
lcd.setCursor(0,1);
lcd.print(sensorValue);
digitalWrite(3, HIGH);
delay(pulse);
digitalWrite(3, LOW);
delay(sensorValue - pulse);
sensorValue = analogRead(A1);
sensorValue = sensorValue / 3;
lcd_key = read_LCD_buttons();
if (lcd_key==btnUP)
{
pulse = pulse+0.5;
delay(50);
}
if (lcd_key==btnDOWN)
{
pulse = pulse-0.5;
delay(50);
}

}else{
delay(500);
break;
}
goto start;
}

case btnNONE:
{
break;
}

}
}

Can someone please help me?
Regards Tim

Keep looking. This exact same project has come up here in the last few months.

Next time you post code, use the code tags button <>

Hi! I'm trying to control a digital output for a basic injectortester.

I have no clue what that is.

Your "panel" or whatever it is that's apparently putting-out analog seems screwy to me... Are you getting the expected results from it? Hopefully, you have a really good reason for using analog when you really want digital...

I want a High (0-20ms) and a Low (0-300ms)

Are you having trouble making a pulse, or are you having trouble with the user interface or the LCD?

and a timer 0-60

You want it to run for 60 seconds?, 60 milliseconds?, 60 minutes?

With multiple timers, you'll have to use the method from Blink Without Delay, or study the post at the top of the forum for doing several things at a time.

The delays in your program might cause you problems, since the delay() pauses execution...

Hi, I think you would find the Stopwatch library useful: HERE:

Try the examples then figure out how to read times inside your main loop.

I use this a lot in Home Automation stuff…

BTW are you working on automotive Fuel Injection ‘Injectors’ or what?

DVDdoug:
I have no clue what that is.

Your "panel" or whatever it is that's apparently putting-out analog seems screwy to me... Are you getting the expected results from it? Hopefully, you have a really good reason for using analog when you really want digital...
Are you having trouble making a pulse, or are you having trouble with the user interface or the LCD?

You want it to run for 60 seconds?, 60 milliseconds?, 60 minutes?

With multiple timers, you'll have to use the method from Blink Without Delay, or study the post at the top of the forum for doing several things at a time.

The delays in your program might cause you problems, since the delay() pauses execution...

I'm going to use this for my fuel injector cleaner, it's not exactly what i expected but hope to fine tune it as i learn.
I'm using a DFrobot lcd shield V1 with 5 buttons connected to Analog0 and a 10Kohm potetiometer connected to A1.

*Button Select starts the sequence
*Button Up/Down controls the HIGH (Injector open = 0-20ms)
*The potetiometer controls the LOW (RPM = 300-0ms)
This works!

*I want a timer to set a test time that stops the loop (0-60sec)

Maybe there is a easier way to get the same results?

Regards Tim