Pump and Noozle controlling

Hi Guys!

I´m making a DIY pretreater machine for myself and I need some help in the code.
Everything is working fine but I would like something what it is not including.

When I push the start button then the motor send the plate to the back. Then It starts the pump and noozle what I set up before starts. The full range is 22500 steps.

What I would like when I set up for example 20.000 steps with the potentiometer then the pump would go until 20.000 steps but the solenoid valve would turn off at 19.500 steps. How would it be pussible?

I write the code here and maybe this is helpful.

`case 4: // 4 = Spray sequence

  // Read speed control knob 
      speedval = analogRead(speedpot);  
      speedval = map(speedval, 0, 1023, 1250, 50); // was 1250 and 450
       digitalWrite(motorDirection, LOW);

       digitalWrite(motorStep, HIGH);
       digitalWrite(motorStep, LOW);


if (stepCount == 10) { // sets the steps taken before turning on the spray nozzle.
  digitalWrite(nozzle, HIGH);
  digitalWrite(pump, HIGH);

if (stepCount == lengthval) { // sets the steps taken before turning on the spray nozzle.
  digitalWrite(nozzle, LOW);
  digitalWrite(pump, LOW);

// Stop at the front
if (stepCount > maxSteps) {
  digitalWrite(nozzle, LOW);
  digitalWrite(pump, LOW);
        platenState = 5; // Set to case 5 so it stops and does nothing but waits for the in button to be pressed 

 case 5:                       // 5 = Idle and Waiting for button presses
        if (value_gobtn == LOW) {
            platenState =3; 
              // Read length control knob 
                 lengthval = analogRead(lengthpot);  
                 lengthval = map(lengthval, 0, 1023, 22500, 200); 

            if (value_purgebtn == LOW) { // Purge button turns on the nozzle solenoid full open
                 digitalWrite(nozzle, HIGH); // Turn on spray nozzle
                 digitalWrite(pump, HIGH); // Turn on pump
                  digitalWrite(nozzle, LOW); // Shut off spray
                  digitalWrite(pump, LOW); // Shut off pump

if steps=maxsteps-500 then turn thing off

Thank you very much for your help

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.