Pumps controlled by increase or decrease in pressure #pressure #pumps #ROV #Help

i Have got a code for a arduino motorcycle fuel pump controller, but i am struggling to understand some bits in it and where the pressure sensor gets connected to and where it show in the code that the value is being read. I have a bmp085 pressure sensor that connects to 3.3v, but i'm not sure which pressure sensor is being used in the code. . the code for this is pasted below if anyone wants to explain to me it in detail it would be much appreciated. ''// Arduino motorcycle fuel pump controller
// Saved by Simulator for Arduino V0.98
int pwmPin = 9; // output pin supporting PWM
int inPin = 3; // pressure sensor voltage connected to analog pin 3
int val = 0; // variable to store the read value
float volt = 0; // variable to hold the voltage read

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

// values for AEM 0-75 PSI presure sensor
// range of -14.7 PSI to 60.3 PSI and .5 to 4.5V
// .5V = -14.7 PSI, 4.5V= 60.3 PSI
// At 0V the theoritical pressure is -24.075 psi
// That is 18.75 psi per voltage
// Volts= (PSI+24.075)/18.75
// PSI= (18.75*(Voltage))-24.075
// 40 PSI is about 3.42V

// 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 millivolt (Mv) (1024/5.0 volts)
// To get PSI 0-1023 number from Mv divide input volts by .00488
// 40 PSI is about 700.
// 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 <= 700)
analogWrite(pwmPin, valMap); // runs pump until set pressure reached

else if (val > 700) // 700 is about 40 PSI
analogWrite(pwmPin, 0); // shuts pump off

}
''
I took the code and i also tried altering it to my own project where i have to control depth of an rov using 2 buildge pumps that run on 9V. One pump goes up one goes down but so far i was only able to change the code so they both go in the same direction. I am using an arduino shield to control these pumps. The ROV is meant to go down to a depth of choice and stay there so the pumps are controlled by the pressure. When i done the code it didn't let me verify it something in the last 2 lines was not right but i cant figure out what it is. i'm not sure if the pins at the start of the code are right too as the sensor has 2 pins for data the SCL and SDA but the code only asks for one and i am not sure which one to use. code is pasted below if anyone can help it would be much appreciated thanks
''
// Arduino motorcycle 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(500); // pump runs for 1/2 second
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(500); // pump runs for 1/2 second
analogWrite(pwmPin_B, 0); // shuts off the pump
}
void loop()
{
val = analogRead(inPin); // read the input pin

// values for AEM 0-75 PSI presure sensor
// range of -14.7 PSI to 60.3 PSI and .5 to 4.5V
// .5V = -14.7 PSI, 4.5V= 60.3 PSI
// At 0V the theoritical pressure is -24.075 psi
// That is 18.75 psi per voltage
// Volts= (PSI+24.075)/18.75
// PSI= (18.75*(Voltage))-24.075
// 40 PSI is about 3.42V

// 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 millivolt (Mv) (1024/5.0 volts)
// To get PSI 0-1023 number from Mv divide input volts by .00488
// 40 PSI is about 700.
// 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 <= 700)
analogWrite(pwmPin_A, valMap);
analogWrite(pwmPin_B, valMap);// runs pump until set pressure reached
analogWrite(pwmPin_A, 0);
analogWrite(pwmPin_B, 0);// shuts pump off

else if (val > 700); // 700 is about 40 PSI
analogWrite(pwmPin_A, 0); // shuts pump off
analogWrite(pwmPin_B, 0); // shuts pump off

}
''

else if (val > 700);

That semicolon is the body of the else block. Is that what you really want?

Blocks of code, following an if statement need to be enclosed in { and }. Your code says:

if (val <= 700)
   analogWrite(pwmPin_A, valMap);

Then

analogWrite(pwmPin_B, 0);// shuts pump off
else if (val > 700); // 700 is about 40 PSI

An analogWrite() statement does not have an else clause.

Learn to indent properly, Your code looks like shit.

// Saved by Simulator for Arduino V0.98

Tell it to try harder, no code should be left justified like that. And put it in CODE tags (the # button at top of editing area).

And as Paul pointed out, you are missing a few {} pairs, that code will not do what you think.

So fix the {} problem and run it again, if still no go repost with the symptoms.


Rob