Automatic water filling system

Hello,

I'm designing a system to automatically fill a water tank.
I'll explain how it works first.
The tank is connected to a 300gpd RO system. Pressure is applied so I don't need a pump.
I have a level switch, float switch(NC contacts), and an electronic ball valve solenoid.
The tank has a spring loaded base so when tank is low it will be light enough to engage the level switch.

So far at this point now. I have connected all except for the float switch.
I've done quite a bit of research and I've come to the conclusion that I need more help. I'm an expert with electronics however my coding falls short.

Here's my code. I know there are errors.
I don't need you to fix it or write the code, I just need a push in the right direction. Thanks,

int limit =6;
int valve =8;
int level =4;

void setup() {

pinMode( limit, INPUT_PULLUP);
pinMode( valve, OUTPUT);
pinMode (level, INPUT);\

Serial.begin(9600);
}

void loop() {

if
digitalRead(limit == HIGH);
{
digitalWrite(valve, HIGH);
Serial.print ("Tank is getting low");
}
else digitalRead(level == LOW); //since float is NC
Serial.print ("Tank is Full");
{

digitalWrite(valve, LOW);
}
}

     if 
    digitalRead(limit == HIGH);    
    {
      digitalWrite(valve, HIGH);
       Serial.print ("Tank is getting low");
    }
     else digitalRead(level == LOW); //since float is NC
    Serial.print ("Tank is Full");    
    { 
      
      digitalWrite(valve, LOW);
    }

Lots of errors.

Look at the reference page for “if()”.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

What is the Arduino supposed to do that a more reliable and much simpler switch can't accomplish?

This is not the correct format for digital input commands:

   digitalRead(limit == HIGH);

To gain some experience and learn the language and special features of the Arduino, we strongly recommend that you work through some of the simple example programs that come with the software development package (the IDE).

With Arduino, you also need a driver for the solenoid.

Alexander2020:
I'm an expert with electronics

What you want is dead simple, be sure to get the biggest most expensive Arduino you can waste money on.

I don't see you needing as much as an AND gate you can wire up your expert self. Perhaps an inverter is called for?

Best of luck with your project!

@Alexander2020 will be spending a short time away from the forum.

All it takes to make an AND gate is 2 switches and some wire. Wire the switches in series, it is an AND gate.

For the non-experts, an AND gate is good for when you want 2 things ON at once to signify 1 event.

Wire the switches in parallel, it's an OR gate. Other gates need trickier wiring.

When we had no personal computers or even electronic calculators, that's the stuff the wiz kids built.

Use a single pole double throw switch on the tank so when the tank is full it opens the circuit.
When the tank is up the circuit is closed and the valve opens

If you use a DPDT switch. It can power the valve open and power it closed.

GoForSmoke:
What you want is dead simple, be sure to get the biggest most expensive Arduino you can waste money on.

I don't see you needing as much as an AND gate you can wire up your expert self. Perhaps an inverter is called for?

I did it! No, thanks to goforsmoke who is a very childish person. GATES! LOL that is child's play. This is for a 480V 3 phase machine, you don't use gates....
This is an Arduino forum why would suggest someone to do it differently?

Anyway figured it out. My code below. Works exactly how I wanted it.

int limitsw =6; //limit switch
int  valve  =8; //ball valve
int floatsw =4; //float switch
int limitB =0; //limit before state
int limitA =0; //limit after state
int floatB =0; //float before state
int floatA =0; //float after state

void setup() {
 
 pinMode( limitsw, INPUT_PULLUP);
 pinMode( valve, OUTPUT);
 pinMode( floatsw,INPUT_PULLUP);
 limitA = digitalRead(limitsw);
 floatA = digitalRead(floatsw);

 Serial.begin(9600);
}
void switchstat1 (){
 limitB = limitA;
 limitA = digitalRead(floatsw);
 
}
void switchstat2(){
 floatB = floatA;
 floatA = digitalRead(limitsw);
}

void openvalve() {

 digitalWrite(valve, HIGH);
}
void closevalve (){
 digitalWrite(valve, LOW);
}
void loop() {
 switchstat2 ();
 if ((limitA==1)&&(limitB==0))
 {
   openvalve();
   Serial.print("Tank is empty");
 }
 switchstat1();
 if ((floatA==0)&&(floatB==1)) {
 
 closevalve();
 Serial.print("Tank is full");
 }
 
}

There you happy?

So, the limit switch state is held in a variable called "floatA", and the float switch state is held in a variable called "limitA"..

Good luck remembering the reason for that, in six months time.

Please remember to use code tags when posting code

AWOL:
So, the limit switch state is held in a variable called "floatA", and the float switch state is held in a variable called "limitA"..

Good luck remembering the reason for that, in six months time.

Please remember to use code tags when posting code

I was wondering if anyone would notice that. For reasons I'm uncertain of, my code worked in reverse (limit switch turned off valve & float would turn on valve) so when I changed it like what you see it worked so I just left it.

My first post here so I'm uncertain of code tags.

Alexander2020:
My first third post here so I'm uncertain of code tags.

You use them when you post code.
Nothing at all uncertain about them.

They're explained in the prominent sticky threads titled "Read this before posting" (or similar)

Alexander2020:
My first post here so I'm uncertain of code tags.

Puts the code in a box like this

Alexander2020:
My first post here so I'm uncertain of code tags.

Code tags are the special characters you use to make your code appear neatly in a box.
You can edit your post.
On the bottom right are some options
Other / modify.
At the Beginning of your code put in a left braket. [ then the word code followed by a right bracket ]
Then at the end of your code do the same but between the brackets use the forward slash. /code
If i were to do it as it need to be the forum would interpret it and post the box.

Here,.I've got a spare pair - you can have them [code][/code]

Arduino magic does what sensors/switches alone will not. I guess it takes an expert at something to believe that.

We don't use more than TTL signal in or out of Arduino, we switch high voltage current with relays whether coil or solid state type and it is ALL just as usable with just switches, sensors, small components that we can connect to Arduino yet.....

somehow a magic chip is required says the expert.

Wow that's lame.