smart water tank monitor

I wasn't exactly sure what category to post this in because it involves code and schematical questions.

Hello, i have a circuit below that uses an SR-04 ultrasonic distance sensor to measure the height of the water level and use a relay to turn on and off a pump to control the water level and an HLK-5M12 SMPS . I got the schematic from here .

According to the website/schematic the circuit runs on 220v.

Is this correct explanation? When the distance between the water and the sensor become greater( less water in the container) > 30 the motor turns on putting more water in the container and turning the water off when it is less than <6.

I believe it does this by when the distance is greater than >30 the Digispark microcontroller outputs a "HIGH" on T1(NPN transistor) which activates RL1(relay) putting it to N/O and this gives the other 110v plus the original power switch 110v = 220v required to turn on HLK-5M12 which gives the supply voltage that lets you turn on the pump, then the SR-04 turns off the control pin to stop overflow and this process repeats.

Is that correct? Thanks.

#define trigger 3 // sonar trigger
#define echo 2 // sonar echo
#define motor 4 // water pump drive
#define beeper 0 // buzzer drive

const int statusPin = 1; // status indicator drive
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 3000;
float time = 0, distance = 0;
int temp = 0;

void setup()
{
 pinMode(trigger, OUTPUT);
 pinMode(echo, INPUT);
 pinMode(motor, OUTPUT);
 pinMode(beeper, OUTPUT);
 pinMode(statusPin, OUTPUT);
 delay(2000);
}

void loop()
{
 unsigned long currentMillis = millis();
 if (currentMillis - previousMillis >= interval)
 {
 previousMillis = currentMillis;
 if (ledState == LOW)
 {
 ledState = HIGH;
 }
 else
 {
 ledState = LOW;
 }
 digitalWrite(statusPin, ledState);
 }
 digitalWrite(trigger, LOW);
 delayMicroseconds(2);
 digitalWrite(trigger, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigger, LOW);
 delayMicroseconds(2);

 time = pulseIn(echo, HIGH);
 distance = time * 340 / 20000;
 delay(2000);

 if (distance < 6 && temp == 0) // upper threshold in cm
 {
 digitalWrite(motor, LOW);
 digitalWrite(beeper, HIGH);
 delay(3000);
 digitalWrite(beeper, LOW);
 delay(3000);
 temp = 1;
 }

 else if (distance < 6 && temp == 1)
 {
 digitalWrite(motor, LOW);
 delay(3000);
 }

 else if (distance > 30) // lower threshold in cm
 {
 digitalWrite(motor, HIGH);
 delay(3000);
 temp = 0;
 }
}

If You search for similiar projects You will find stuff to read. Any sensor fitted inside the tank will be affected by the high humidity there. A short time ago this happend for another member. Watertank…." I think the title was.

Railroader:
If You search for similiar projects You will find stuff to read. Any sensor fitted inside the tank will be affected by the high humidity there. A short time ago this happend for another member. Watertank…." I think the title was.

Thank you for a response, I have no plan on building this circuit. I am just trying to see if the way i explained it was correct.

Yes, the description looks clear. A simple and easy action of the parts. By the way, handling 220 volt, be careful. I've done it for 55 years and I've got a kick or two….. No 220 volt lines inside the walls of the tank...…

Don't know why some have to make complex circuitry to replace a simple everyday float switch.

bluejets:
Don't know why some have to make complex circuitry to replace a simple everyday float switch.

I agree, if your water source can supply more water flow that can be removed from the tank. Two Ebay float switches fitted to PVC water pipe will tell you to turn turn the water source on and off. Use SSR to the source supply.

Paul