Here is my current project, at heart it is an Arduino Uno. I am currently using a single analog input, but I am planning to use multiple inputs after I get the controller to operate with the single input. The analog input I am using is a fuel pressure sensor. My uno is interpreting this voltage and displaying it as a pressure on my 16x2 lcd. I have a DC brushless fuel pump that accepts a PWM input to control its speed. I have a program written to control this fuel pump speed with the map function. It also prints the current duty cycle of the PWM output to my LCD. The issue that I am running into is that I need to keep the fuel pressure at a constant reading, while being able to increase or decrease the PWM signal to gain more flow from the fuel pump during high demand. There will be a fuel pressure regulator on the fuel system to keep the fuel pressure from rising too high. The duty cycle cannot drop below 20% or the pump will turn off. Here is broken down detail of how I want to program either the constrain or if statement to keep the pump running fast enough. Of course I will have to interpret the voltage readings once I get the fuel pressure sensor calibrated correctly. 43 psi is roughly 2.5 volts.
Fuel Pressure Duty Cycle
44 psi 30%
43.5 psi 40%
43 psi 50%
42.5 psi 75%
42 psi 100%
Once I get this working correctly then I will add another pressure sensor that will read manifold pressure and when it rises to 2 psi of boost (turbo car), I will have it write the pin to high (100%), to prevent a loss of fuel under boost conditions. I have tried several variations of constrain but I have yet to get it to function how I want it to. Please give me some insite as to how I should program this. Here is a copy of my current program, there is no constrain in these programs I did not save them due to the lack of function.
Thanks in advance. Aaron
#include <LiquidCrystal.h>
const int numRows= 2;
const int numCols= 16;
int sensorPin = A0;
const int ledPin= 6;
int sensorValue = 0;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
lcd.begin(numCols, numRows);
lcd.print("Fuelab Prodigy");
lcd.setCursor(0,2);
lcd.print("Pump Controller");
delay(2000);
lcd.clear();
analogWrite(ledPin, 255);
delay(8000);
}
void loop()
{
sensorValue = analogRead(sensorPin);
delay(500);
int val = analogRead(0);
Serial.println(val);
delay(1);
val = map(val, 0, 1023, 255, 0);
analogWrite(ledPin, val);
lcd.clear();
int pressure = sensorValue;
pressure = map(sensorValue, 0, 1023, 0, 90);
lcd.print(pressure);
lcd.setCursor(3,0);
lcd.print("PSI");
lcd.setCursor(0,1);
int pump = val;
pump = map(val, 0, 255, 0, 100);
lcd.print(pump);
lcd.setCursor(3,1);
lcd.print("% Duty Cycle");
}