Read input from an analogic pressure switch to stop a solenoid

I'm trying to read a pressure switch/Sensor in order to use it to stop a solenoid valve.
So the valve starts pumping and when the pressure switchs triggers then the valve will stop.
I'm using an analogic pressure switch(image below) and I'm not sure if that's how it works (also I've heard about the multitask on Arduino and maybe that's the problem so it can't read the pressure switch while it's pumping) I would appreciate any kind of help.

const int mtr = 22;
const int va = 23;
const int sensor = 24;

void setup() {
  pinMode(mtr, OUTPUT);
  pinMode(va, OUTPUT);
  pinMode(sensor, INPUT);
}

void loop() {
 do{
  digitalWrite(va, HIGH);}
  while(digitalRead(sensor==HIGH);
  digitalWrite(va, LOW);
 }

 digitalWrite(mtr, HIGH);
 delay(1000);
 digitalWrite(mtr,LOW);

}

You have a motor, valve and sensor. Two outputs and and input.

You have a sensor that is on or off. What do you want the outputs to do when that input is on and when it is off? Just describe the desired operation.

The operation is:

  1. Valve starts pumping
    2.The sensor triggers because of the pressure generated by the valve on a recipient
    3.After the sensor is triggered the valve stops pumping.
    4.The motor starts and then stops

(This is like the first script, it will be larger and the delays will be removed for now I just want the valve on a on or off state depending on the pressure and the sensor)

Hi,
Sorry it may be a language problem, but valves do not pump.

Valves allow things to flow or not flow, they are open or closed.
I hope this helps.

Can you post a diagram of how your pump, valve and pressure sensor are arranged.

Is the sensor between the pump and valve, or between the valve and the recipient?

Thanks.. Tom.. :slight_smile:

Actually the system is a washing machine, so the pressure switch is connected to the Arduino and connected through a house that is in the washing machine. So the valve starts the flow and when the pressure switch triggers then the valve should stop the flow. Thanks Tom :smiley:

Hi,
Okay a washing machine. the pressure switch switches when the water level get to a certain height.

What does the pump do, drain the washing machine?

The image of the pressure switch has not appeared.
Can you post a link to spec/data for the switch please?

Tom.. :slight_smile:

Yeah, so I think it is a language mistake here there's no 'pump' all the time I was referring to a valve (I will eventually add the pump but I think it will be the same problem as the valve since I need to understand the pressure switch)

I was investigating and found the 'external interruptions' functions. So it will read the pressure switch state all the time and identify when there is a change on the state of it (like in a button). So starts flowing water and all the time checks if there's a status change on the pressure switch and when the pressure triggers because of the pressure then will stop the flow. Something like

digitalWrite(valve, HIGH);
 attachInterrupt(digitalPinToInterrupt(3), flow, RISING);

and then the 'void flow()' is just a "digitalWrite(valve, LOW)" instruction that executes when the pressure switch triggers (it think the pressure switch works in the same way as a button, it just connect two plates through a pulse)

(I really don't know why the image doesn't show)

Hi,
OPs image.

So it is a pressure switch for a front loading washing machine.
Do you know the pinout for the switch, is it one switch or two switches.
Do you know how to fit it to a machine and have you tried to see what its output does with water pressure from the depth of the machine?

What is the voltage of the valve solenoid and do you have a power supply for it and any data or specifications?

Before going to code, you have to make sure you hardware is suitable for the job and will provide the correct inputs ti the controller, as well as any outputs and how they will control your valve etc?

What model Arduino are you going to use?

Tom... :slight_smile: