So simple but eluding me

This is my first Arduino project, and I am trying to do something very simple but it's just not clicking, even after watching videos and reading. I am trying to create a water tank with a level sensor that turn on a pump motor when the sensor gets low and turns it off when it is high. And this I got working well. But I also want to have a safety sensor that will override what the other sensor is doing and turn the water off so there is no chance of overflow should the first water sensor ever fail. I am testing on Tinkercad and on my Arduino/IDE.
Thanks in advance.

const int waterSensor=12 ; //tank water sensor
const int waterSensorS=11 ; //safety water sensor
const int pumpMotor=2 ;  //waterpump
int switchState=0 ;
int sensorValue=digitalRead(waterSensor);

void setup () { 
  pinMode(pumpMotor,OUTPUT);
  pinMode(waterSensor,INPUT);
  pinMode(waterSensorS,INPUT);
} 
void loop () { 
  switchState=digitalRead (waterSensor) ;
  if (switchState==LOW) {
    digitalWrite(pumpMotor,HIGH) ;
    switchState=digitalRead (waterSensorS) ;
  if (switchState==LOW) {
    digitalWrite(pumpMotor,LOW) ;
    } 
  else { 
    digitalWrite(pumpMotor,LOW);
     delay(5000);
  }}

Safety circuits are done in hardware, not software. Put in a NC overflow switch that cuts power to the pump and/or opens the spill valve. Its called a "safety" circuit because it operates when all else fails.

Is there a problem with the code or hardware?

Keep in mind that the Arduino is completely inert and unresponsive while executing delay(). Avoid using delay during critical tasks.

Finally, as already mentioned, if the pump controller is stuck ON for any reason, the only way to stop the pump is to disconnect the pump power source. A completely independent float switch could serve that purpose.

It's a very small tank maybe a quart in size, I just don't want it to overflow in the desk.

It's with the code, it works fine on the hardware using

const int waterSensor=6 ;
const int pumpMotor=5 ;
int switchState=0 ;
int sensorValue=digitalRead(waterSensor);

void setup () { 
  pinMode(pumpMotor,OUTPUT);
  pinMode(waterSensor,INPUT);
} 
void loop () { 
  switchState=digitalRead (waterSensor) ;
  if (switchState==LOW) {
    digitalWrite(pumpMotor,HIGH) ;
    } 
  else { 
    digitalWrite(pumpMotor,LOW);
     delay(5000);
  }}

But when I add the rest it quits working.

Personally, I’d put the safety switch before the high-level switch.
That way it has no reason to turn the pump on if the level is already at the overflow point.

And what would be "the rest"?

How are the switches wired?

Please post a pic of a hand-drawn wiring diagram, with pins, connections and parts clearly labeled. Also, post links to the pump, pump power supply and pump controller.

Here is a link to the Tinkercad, I have the safety switch disconnected.

Water Pump

When you physically build this system, HOW will the tank be filled? From the bottom, the side, or the top? IF from the top. waves and splashing will make the limit switch rapidly go on and off.

It will be filled from a tank sitting on the floor below, the water is pumped up with a small 9v .5A submersible pump, because of motion was the reasoning for the 5 second delay to engage the pump.

I have no tinkercad login and I never will register to tinkercad
If I click your link I just see this

and no code at all
So please start a free-to-use free-of-registering WOKWI-simulation of your project

I was initially going to try Wokwi but it didn't have motors or other items I thought I could use so I went with Tcad instead since it had more options. Here is a screenshot of what I have.

Wouldn't an LED suffice as an indicator?

Yes but Wokwi doesn't have external power supply's or battery's either and I don't want to power everything from the 5 volt source. I tested several simulators and it's just too lacking to bother with.

I don't particularly like Tinkercad either but it fits my need best for this project.

Hi,
Can you please draw a proper schematic diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

How have you got your switches wired?

If you are switching input to 5V, have you got a 10K pull down resistor on the input pin to gnd?

If you are switching input to gnd, have you got a 10K pull up resistor on the input pin to 5V?

You cannot leave an input pin open circuit and assume it is at gnd.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

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