Co2 Filling Machine

Hello Everyone,

I am looking for some help on a project I have. What I am trying to make is a Co2 filling machine. I have a UNO board that I am working with. What I am trying to do is place a co2 bottle on a scale and press a button to fill the bottle to a set weight weight. Example would be a 5 or 10 pound fill. I have the load cells working and calibrated currently. My problem is when I press my button to run the fill sequence. I cannot get it to close the valve once the weight has been reached. Could someone look at my code and offer suggestions.

#include "HX711.h"

#define DOUT 3
#define CLK 2
#define MANUAL 10 //manual fill button
#define FIVE 9 // 5LB fill
#define TEN 8 // 10LB fill
#define TWENTY 7 // 20LB Fill
#define RST 11 // Tare weight
#define FILL 13 // Fill Valve

float seed = -9560.00;

HX711 scale(DOUT, CLK);

///////////////////////////////////////////////////////////////////////////////////

void setup() {
// put your setup code here, to run once:
pinMode(MANUAL, INPUT_PULLUP); // Manual fill open air valve
pinMode(FIVE, INPUT_PULLUP); //
pinMode(TEN, INPUT);
pinMode(TWENTY, INPUT);
pinMode(RST, INPUT_PULLUP); // reset scale to 0
pinMode(FILL, OUTPUT);

Serial.begin(9600);

scale.set_scale(seed);

scale.tare(); //Reset Scale to 0

}

///////////////////////////////////////////////////////////////////////////////////

void loop() {

float weight = scale.get_units(10);
int RSTRequest =digitalRead(RST);
int FIVERequest = digitalRead(FIVE);

//-------------------------------TARE------------------------------
scale.set_scale(seed);

Serial.print("\tPounds:\t");
Serial.println(scale.get_units(10), 1);

if (RSTRequest == LOW) {
Serial.println("Resetting to zero");
scale.tare();

}

//-------------------------END TARE------------------------

//---------------------5LB Fill------------------------

{if ((FIVERequest == LOW) &&(weight < 5))
Serial.println("5 Pound Fill");
digitalWrite(FILL, HIGH);

}

}

I guess writing HIGH to FILL starts the filling? You never write LOW to it to stop the filling. Maybe when weight >= 5? But first you need to move the { in front of the if to the right place.

Steve

This is my first project ever so please bear with me. Where should I move the { ?

would the off look like

when (weight>=5)
digitalWrite(fill, LOW);

slim542:
This is my first project ever so please bear with me. Where should I move the { ?

would the off look like

when (weight>=5)
digitalWrite(fill, LOW);

You could have just looked at your other if statement to see where the { should be.

There is no "when" statement so perhaps try

//---------------------5LB Fill------------------------

if ((FIVERequest == LOW) &&(weight < 5)){
  Serial.println("5 Pound Fill");
  digitalWrite(FILL, HIGH);
}
if (weight >= 5){
  Serial.println("5 Pound Fill complete");
  digitalWrite(FILL, LOW);
}

There are many more elegant ways you could do it but that might get you started.

Steve

OK, I see what I did with the {. Thank you for your help Steve that code worked. But what about this situation?

//---------------------5LB Fill------------------------

if ((FIVERequest == LOW) &&(weight < 5)){
Serial.println("5 Pound Fill");
digitalWrite(FILL, HIGH);
}
if (weight >= 5){
Serial.println("5 Pound Fill complete");
digitalWrite(FILL, LOW);
}
//------------------5LB END ---------------------------
//------------------10LB fill --------------------------------
if ((TENRequest == LOW) &&(weight < 10)){
Serial.println("10 Pound Fill");
digitalWrite(FILL, HIGH);
}
if (weight >= 10){
Serial.println("10 Pound Fill complete");
digitalWrite(FILL, LOW);
}

//------------------10LB END--------------------------

The 5LB code will turn the relay off before the 10LB code has a chance.

If it was me I think I would have a variable for the intended weight which is set when the appropriate button is pressed. Then I'd move the switch off to the bottom after all the various switch on conditions. So something like (not real code - you get to do some of the work yourself) -

if ((FIVERequest == LOW) &&(weight < 5)){
  targetWeight = 5;
  Serial.println("5 Pound Fill");
  digitalWrite(FILL, HIGH);
  }
if---10
  targetWeight = 10;

any more ifs for various weights then

if (weight >= targetWeight){
  digitalWrite(FILL, LOW);
  }

I think that might do something like you want but you'll have to check it yourself and it's a fairly scrappy design (I'm not good at trying to design someone else's program on the fly).

Steve

AHHHHH, Light Bulb thank you.. Let me get to work..