Basic contol... I think

I would like to accomplish the following but seem to be missing something

Run this cycle once when a button is pushed

-Push start Button

-close drain -open valve to fill tank -turn off valve at sensor limit -Open valve for set time -turn on air pump for set time -Open drain -turn on fan for set time

Then wait until button is pushed again to run it again. The times are currently very short for testing but will be much longer(hours) I am VERY new to programming, I'm much more fimilalr with the hardware side Any help would be great!

I don't have the button in the code below.



/* NY Malt, Automated Steep proccess -- Beta test Tom Stringham 1-18-13 */

const int RLVALVE1 = 2; //Steep tank fill Valve const int RLVALVE2 = 3; //Steep tank Drain Valve const int RLBLOWER = 4; //Steep tand airation valve const int RLCO2FAN = 5; //Steep tank C02 extraction fan const int TEMP1 = 6; //Grain bed temp const int IRSEN = 7; //IR sensor for water level int buttonState = 0;

// the setup routine runs once when you press reset: void setup() { // initialize digital pins as output / input. pinMode(RLVALVE1, OUTPUT); pinMode(RLVALVE2, OUTPUT); pinMode(RLBLOWER, OUTPUT); pinMode(RLCO2FAN, OUTPUT); pinMode(TEMP1, INPUT); pinMode(IRSEN, INPUT); int (IRSEN == LOW); }

void loop(){ //Fill and steep 1 digitalWrite (RLVALVE2, HIGH);{ buttonState = digitalRead(IRSEN); if (buttonState == LOW) { //fill tank with water (digitalWrite (RLVALVE1, HIGH)); }

else {(digitalWrite(RLVALVE1, LOW)); //stop filling a sensor limit } } { digitalWrite (RLVALVE1, HIGH); //open fill valve to rinse grain delay (5000); //Keep open for 5 seconds digitalWrite (RLVALVE1, LOW); //Close Valve } { digitalWrite (RLBLOWER, HIGH); //Turn on Airation Pump delay (7000); //Keep on for 7 seconds digitalWrite (RLBLOWER, LOW); //Turn off } { digitalWrite (RLVALVE2, HIGH); //open drain delay (5000); //Keep open for 5 seconds digitalWrite (RLVALVE2, LOW); //Close drain } { digitalWrite (RLCO2FAN, HIGH); //Turn on CO2 exahs fan delay (12000); //Keep open for 12 seconds digitalWrite (RLCO2FAN, LOW); //Turn Off Fan } }

Is it compiling but not running as expected, and if that’s the case you’ll need to describe what’s actually happening. If it’s not compiling, you’ll need to post the error messages.

At first glance, looks like you have a “spare” { as <<<<<'d below

void loop(){
  //Fill and steep 1
  digitalWrite (RLVALVE2, HIGH);{ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  buttonState = digitalRead(IRSE

(Btw, use the code tags (#) not quote…)

It is compiling but not running as expected. I would like it to wait for each event to finish befor moving to the next, this works in all cases but the first:-( where it fills until the sensor is tripped. Also I don't know the code to make the button work to run the loop once. sorry about the long quote, I didn't the the insert code :blush: Thanks


Systems like this are often coded using a state machine. Search the forums - there are examples. Restrict your search to posts by me and you'll find three or four simple ones that might help you get the idea. For a simpler solution though - you're missing a delay after you start filling in the first step.

Thanks wildbill, State machines look promising, I found the one you did for a diesel. I'll study that and get back to here if I have questions.


Testing the switch state is not sufficient. You need to detect that the switch has changed states - from released to pressed or from pressed to released. Then, detect whether the current state is pressed before triggering any actions.

To do this, you need to keep track of the previous state of the switch, updating it at the end of loop().