hi guys
im wanting to create a injector duty cycle percent with a given pressure iv attached what iv come up with so far, this is my first not looking at examples projects so any help would be appreciated. i wanted to simulate and injector and a pressure change on circuits.io but had no components for that well not premade
heres what i have so far. the biggest issue is i want to take a signal line off the map sensor already in the car, or do you think its best to use a standalone unit
im going to use the nmost transistor as the attached picture
const int injectorpin = 11;
int injectoryduty= 0;
const int sensorPin = A0;
int bstinput= 0;
int duty=0;
void setup() {
pinMode(injectorpin, OUTPUT); // output pin 11
}
void loop() {
int bst = analogRead(sensorPin);
float bstinput = (bst-.32)(10.94-(-13.9))/(1023+ (-13.9));
float bstinput1 = bstinput - 14.5;
if (bstinput1 < 1 ) int duty=0;
if (bstinput1 < 2 ) int duty=0;
if (bstinput1 < 3 ) int duty=0;
if (bstinput1 < 4 ) int duty=0;
if (bstinput1 < 5 ) int duty=0;
if (bstinput1 < 6 ) int duty=20;
if (bstinput1 < 7 ) int duty=30;
if (bstinput1 < 8 ) int duty=40;
if (bstinput1 < 9 ) int duty=40;
if (bstinput1 < 10 ) int duty=40;
if (bstinput1 < 11 ) int duty=40;
if (bstinput1 < 12 ) int duty=40;
if (bstinput1 < 13 ) int duty=40;
if (bstinput1 < 14 ) int duty=40;
if (bstinput1 < 15 ) int duty=40;
if (bstinput1 < 16 ) int duty=40;
if (bstinput1 < 17 ) int duty=40;
if (bstinput1 < 18 ) int duty=40;
int x = 255/100 ;
int injectorduty = dutyx;
analogWrite (injectorpin, injectorduty);
}
I would specify a range in your if statements for example if((bstinput1>= 0)&& (bstinput1 <1)). I believe the way you have it now, if the value is less than one, it will still execute all the lines of code because it is true for everything.
I'm assuming all your formulas are right.
How are you planning on getting the scale for the OE map sensor?
Not really sure what your question is though.
Hi thanks for the reply, perhaps I should use a known pressure sensor rather than the one already in the car that information is hard to come by.
float bstinput = (bst-.32)*(10.94-(-13.9))/(1023+ (-13.9));
This was a formula from some one else project for a boost gauge, if copy and pasting is not aloud apologise for my script sin...
int bst = analogRead(sensorPin);
float bstinput = ((0.004887xbst)x0.5376) // "5/1023= 0.004887"x"analogread 0-1023"=voltage 0.537xvoltage= boost in absolute bar
float bstinput1 = bstinput - 14.5; // (boost abs-outside)
here is what i have now, i found the factor for my map sensor while doing some tests on the unit
const int injectorpin = 11;
const int sensorPin = A0;
int duty=0;
void setup() {
pinMode(injectorpin, OUTPUT); // output pin 13
}
void loop() {
int bst = analogRead(sensorPin);
float bstinput = bst * (5.0 / 1024.0);
float bstinput2 = bstinput * 0.5376;
//int bstinput = ((bst0.004887)0.5376); // "1023/5= 0.004887"x"analogread 0-1023"=voltage voltage0.5376= boost in absolute bar
int bstinput1 = ((bstinput2-1.000)14.7); // (boostabs-outside)x"bar to psi "
if (bstinput1 >= 1 ) int duty=0;
if (bstinput1 >= 2 ) int duty=0;
if (bstinput1 >= 3 ) int duty=0;
if (bstinput1 >= 4 ) int duty=0;
if (bstinput1 >= 5 ) int duty=50;
if (bstinput1 >= 6 ) int duty=50;
if (bstinput1 >= 7 ) int duty=50;
if (bstinput1 >= 8 ) int duty=50;
if (bstinput1 >= 9 ) int duty=50;
if (bstinput1 >= 10 ) int duty=50;
if (bstinput1 >= 11 ) int duty=50;
if (bstinput1 >= 12 ) int duty=40;
if (bstinput1 >= 13 ) int duty=40;
if (bstinput1 >= 14 ) int duty=40;
if (bstinput1 >= 15 ) int duty=40;
if (bstinput1 >= 16 ) int duty=40;
if (bstinput1 >= 17 ) int duty=40;
if (bstinput1 >= 18 ) int duty=40;
int injectorduty = duty2.55;
analogWrite (injectorpin, (duty2.55));
}
iv tried simulating the input of the map sesnor but cant get it to work, if i make the duty at the end = 50 it works so either somethings not correct with my statements or my arduino is faulty. suggestions?
const int injectorpin = 11;
const int sensorPin = A0;
int duty=0;
void setup() {
pinMode(injectorpin, OUTPUT); // output pin 13
Serial.begin(9600);
}
void loop() {
int bst = analogRead(A0);
float bstinput = bst * (5.0 / 1024.0);
float bstinput2 = bstinput * 0.5376;
//int bstinput = ((bst0.004887)0.5376); // "1023/5= 0.004887"x"analogread 0-1023"=voltage voltage0.5376= boost in absolute bar
int bstinput1 = ((bstinput2-1.000)14.7); // (boostabs-outside)x"bar to psi "
//if (bstinput1 >= 1 ) int duty=50;
//if (bstinput1 >= 2 ) int duty=50;
//if (bstinput1 >= 3 ) int duty=50;
//if (bstinput1 >= 4 ) int duty=50;
//if (bstinput1 >= 5 ) int duty=50;
// if (bstinput1 >= 6 ) int duty=50;
//if (bstinput1 >= 7 ) int duty=50;
//if (bstinput1 >= 8 ) int duty=50;
//if (bstinput1 >= 9 ) int duty=50;
//if (bstinput1 >= 10 ) int duty=50;
//if (bstinput1 >= 11 ) int duty=50;
//if (bstinput1 >= 12 ) int duty=40;
//if (bstinput1 >= 13 ) int duty=40;
//if (bstinput1 >= 14 ) int duty=40;
//if (bstinput1 >= 15 ) int duty=40;
//if (bstinput1 >= 16 ) int duty=40;
//if (bstinput1 >= 17 ) int duty=40;
//if (bstinput1 >= 18 ) int duty=40;
Serial.println(bst);
int injectorduty = duty2.55;
analogWrite (injectorpin, (duty2.55));
}
i ran it with the serial view and its working correctly 0v-5v 0-1023
if (bstinput1 >= 13 )duty=60;
that is it working now :0