Coding to maintain pressure on fuel pump.

Hello, first off I would like to say I am a complete noob when it comes to a lot of this stuff and have never messed with arduino code yet so please forgive my noobness :smiley:
I took a PLC college course once but that was ages ago.

So, I have a modified car with a large fuel pump and fuel return. So whenever extra fuel is sent to the engine(normal driving) it is then returned to the fuel tank thus absorbing heat from the engine bay and shortening the life of the fuel pump. I want to use a PWM to control pump speed so that I only recieve the fuel I need under normal driving and a Arduino micro-controller to control the PWC speed control. My plan is to wire my existing fuel pressure sensor as a input to the micro-controller. The output of the my sensor is .5 to 4.5V. I believe it is a 0 to 150psi sensor but I can't find very definitive information on that. https://www.aeroforcetech.com/files/Aeroforce_5v_150_psig_Oil_Fuel.pdf
My math may very will be off but lets say I wanted to maintain a fuel pressure of 55psi, Then I would want to maintain a voltage input of 1.966.
I plan on using this PWC
Amazon.com

Along with this Micro-controller
https://www.amazon.com/dp/B01N4LP86I/?coliid=I3KIOMBIF89MNU&colid=3PS8JYBF5UNR6&psc=1&ref_=lv_ov_lig_dp_it
Will these work for this application?
How would I go writing the code on this and in simple terms how would I wire these 2 boards together?

Lastly if I created a bypass, so that during full throttle a separate relay would provide the fuel pump with a direct connection to the battery providing full power. (Because under full throttle my fuel pressure regulator actually increases the fuel pressure by 9 psi.) Could this in anyway damage the controllers? Also do I have to ground the fuel pump to the PWM board or can I just ground it to the chassis?

Thanks in advance and I appreciate any help.

05silgto:
The output of the my sensor is .5 to 4.5V. I believe it is a 0 to 150psi sensor but I can't find very definitive information on that.

Ratiometric sensors like that output 10-90% of their VCC.
The above statement is only correct if the supply is exactly 5.0 volt (which it rarely is).
Therefore it's more accurate to calculate in A/D values, not in volts.

Start by wiring the sensor to 5volt/ground/A0 of the Uno, and run this (untested) test sketch.
Don't think about controlling the actual pump until you got this sensor under control.

An Uno is good for testing, but I think a small formfactor Arduino (Nano etc.) is easier to hide in a car.
Not sure about the H-bridge. Are you planning to run the fuel pump forward and reverse?
Don't under estimate powering the Arduino from a potentially 'dirty' car supply.
A car rated 12>5volt buck converter might be needed.
Leo..

const byte sensorPin = A0;
float sensorRating = 150.0; // 150psi sensor
int offset = 102; // zero pressure adjust
int fullScale = 922; // max pressure (span) adjust
float pressure; // final pressure

void setup() {
  Serial.begin(9600);
}

void loop() {
  pressure = (analogRead(sensorPin) - offset) * sensorRating / (fullScale - offset);
  
  Serial.print("Pressure: ");
  Serial.print(pressure, 1); // one decimal place
  Serial.println(" psi");
  delay(500);
}

Thanks for the help!
I should have plenty of room for the micro-controller and H-bridge but as long as it works I can switch to this mini nano, its cheaper anyway.

I only need the fuel pump to spin in one direction so If you know of a better h-bridge that can handle 15amp continuous for the price that would be great.

The sensor is already wired in the car to a analog gauge. I was also gonna wire it to the Arduino also. The sensor receives 5 volts from a regulated power supply. I can power the Arduino from the regulated power supply but it looks like this mini nano needs 7-12 volts of input.
I haven't bought the Arduino or H-bridge just yet, want to plan everything first and make sure I have the right components selected.
So basically I solder the sensor output to the A0 of the Arduino Nano and hook up the car battery(12v) to the input voltage of the Arduino Nano. Then I ground the Arduino Nano to the chassis of the car and upload/test the code.

Does this sound correct? Thanks again and sorry for any dumb questions.
I can also plug a multi-meter to the sensor output with the fuel pressure at my desired psi to get an exact voltage to maintain if that helps.

You may have a few problems here .
If you are running at low speed and suddenly try to accelerate , then the pump
And it’s control loop will take time to build up the pressure again and you’ll get a flat spot .
Most high pressure fuel injection systems use a regulator in the fuel line to keep a constant pressure at the injectors, and recirculate the extra fuel - that is standard practice, and responds rapidly , only very recently are they going to speed control pumps ( BMW) to maintain closed loop constant pressure.
Running your pump at lower speed won’t especially make it last longer, it may even overheat ?

The method you described with the return and the fuel regulator is how my system is currently setup. It recirculates way more fuel than it needs through the engine bay while cruising and heats up all the fuel in the tank thus causing the fuel pump to become very noisy after 30 minutes and shortens the life of the pump. I have two 400lph fuel pumps. One only comes on under boost and the other one is always on and is the pump I'm trying to control. My setup usually runs off of e-85 and therefore needs 30% more fuel than it would if it was running off of gasoline. According to my calculations 500lph is the max amount of fuel my car would ever need at max output. Cruising around my car makes no boost and 400lph is overkill for anything other than WOT as you can see from this dyno graph dyno hosted at ImgBB — ImgBB . I plan on wiring this up in a way that when the second fuel pump activates via pressure switch at a couple pounds of boost it creates a bypass via relay for the other fuel pump so that it also runs at 100% which the mechanical fuel regulator will maintain a set pressure.
I don't know much about coding if at all to be honest but based on my research it looks like there is a way that I can program the pump to turn on 100% if the fuel pressure drops below a certain amount as a fail safe. If all of this is not enough, I can also wire up my scan gauges which you can set an anniucator for a minimum thottle position and when activated will send an electric signal to a relay to turn the pump to 100% power. I really just need help with the coding and how to wire up the PWM and micro-controller as all of this is completely new to me.
E-85 lacks many of the lubricants that normal gas has and is considered a dry fuel, therefore it wears down the fuel pumps much faster. I had one fuel pump already fail after only 8 months(still under warranty).
This would reduce the noise coming from the pump, increase pump life and reduce heat.

I did some calculations and it looks under WOT 50% duty cycle would be good up to about 2500 rpm. Assuming that the pump produces 380lph with the check valve.

Graph-fuel flow to fuel pressure under specs in link below.

https://www.aemelectronics.com/products/fuel-delivery/high-flow-fuel-pumps/400lph-inline-high-flow-fuel-pump

I don't know if this is possible or the best way to do this but lets say I want my set pressure to be at 58psi which I also will set my mechanical fuel regulator for.
At 58 psi duty cycle will be 30%
At 57.9 duty cycle will be 40%
At 57.8 duty cycle will be 50%
and so on.

On the highway I can maintain about 80mph at 2200 rpms which 30% duty cycle should be more than enough.

Okay, I found some code from someone doing something similar and I fixed any errors I could find in it. I changed the values to fit my needs as best I could. I still need to clean up the rest and delete any extra coding and improve what I can.

// Arduino GTO fuel pump controller
// Saved by Simulator for Arduino V0.98
int pwmPin_A = 3; // output pin supporting PWM
int pwmPin_B = 11; // output pin supporting PWM
int inPin = 4; // pressure sensor voltage connected to analog pin 3
int val = 5; // variable to store the read value
float volt = 0; // variable to hold the voltage read

void setup()
{
pinMode(pwmPin_A, OUTPUT); // sets the pin as output
analogWrite(pwmPin_A, 128); // primes the pump at half power
delay(2000); // pump runs for 2 seconds
analogWrite(pwmPin_A, 0); // shuts off the pump
pinMode(pwmPin_B, OUTPUT); // sets the pin as output
analogWrite(pwmPin_B, 128); // primes the pump at half power
delay(2000); // pump runs for 2 seconds
analogWrite(pwmPin_B, 0); // shuts off the pump
}
void loop()
{
val = analogRead(inPin); // read the input pin

// values for 0-150? PSI presure sensor
// range of 0 PSI to 150? PSI and .5 to 4.5V
// .5V = 0 PSI?, 4.5V= 150 PSI?
// At 0V the theoritical pressure is 0 psi?
// That is psi per voltage
// Volts=
// PSI= (*(Voltage))
// 58 PSI is about 1.93V?

// Input pin takes voltage .5 to 4.5 for
// this sensor and converts it to a number between 0 and 1023
// Each number is .00488 V (1024/5.0 volts)
// To get PSI 0-1023 number from Mv divide input volts by .00488
// 58 PSI is about 396.
// PWM pin converts this to a number between 0 and 255
// where 0 is 0% duty cycle and 255 is 100% duty cycle

// using map to invert PWM output so higher duty cycle at lower pressure
int valMap = analogRead(inPin);
valMap = map(val, 0, 1023, 255, 0); // This inverts the pump's duty cycle
// to allow it to run 100% at 0 pressure and about 25% at higher pressure
// using the 0-255 PWM value. Lower PWM can be restricted to 50% (128) by using 255, 68.

if (val <= 396){
analogWrite(pwmPin_A, valMap);
analogWrite(pwmPin_B, valMap);// runs pump until set pressure reached
analogWrite(pwmPin_A, 255);
analogWrite(pwmPin_B, 255);
}
if (val > 396){ // 396 is about 58 PSI
analogWrite(pwmPin_A, 0); // shuts pump off
analogWrite(pwmPin_B, 0); // shuts pump off

}}