Hang We YangTan Le KaNilesyh MohganIrfan EmranNARENDRAN
Published © GPL3+

Rainwater Recycling System

Smart water collection system. Smart water supplement system.

IntermediateFull instructions provided78
Rainwater Recycling System

Things used in this project

Hardware components

Cytron Technologies Rain sensor
×1
Maker UNO
Cytron Technologies Maker UNO
×1
Breadboard (generic)
Breadboard (generic)
×2
12V DC Solenoid Valve
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Float Switch, Vertical
Float Switch, Vertical
×1
5V Relay
×2
5V DC Pump
×1

Software apps and online services

Arduino IDE
Arduino IDE
Visual Studio 2017
Microsoft Visual Studio 2017

Story

Read more

Schematics

Roof Level

Contents:
Rain sensor in the water collector
Arduino Board
LDR Sensor
Potentiometer
breadboard for connection

1st Level

Contents:
Water Flow down to the solenoid valve
Breadboard for connection
Pipe connecting the valve to the tank.

G Level

Contents:
Water Tank
5V DC Pump
Relay controlling the pump
Float Water Level Sensor.

Presentation on how the system works

Code

GUI Code

C#
Microsoft Visual Studio 2019
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace MSES_GUI_Program_Group
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            arduinoPort = new SerialPort();
            arduinoPort.BaudRate = 9600;
            arduinoPort.PortName = "COM8";
            arduinoPort.DataReceived += ArduinoPort_DataReceived;

            try
            {
                arduinoPort.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to open the serial port: " + ex.Message);
            }
        }

        private SerialPort arduinoPort;

        private void ArduinoPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string data = arduinoPort.ReadLine();
            Invoke((MethodInvoker)(() => UpdateUIControls(data)));
        }
        private void UpdateUIControls(string data)
        {
            // Parse the received data
            string[] values = data.Split(',');

            if (values.Length == 6)
            {
                int LDRDNS = int.Parse(values[0]);
                int waterlvlstate = int.Parse(values[1]);
                int Rainsensorstate = int.Parse(values[2]);
                int PoMeterstate = int.Parse(values[3]);
                int Revalve = int.Parse(values[4]);
                int Repump = int.Parse(values[5]);
                if (Rainsensorstate == 1)
                {
                    progressBar3.Value = 0;
                }
                else
                {
                    progressBar3.Value = 1;
                }
                progressBar1.Value = LDRDNS;
                progressBar4.Value = waterlvlstate;
                if (PoMeterstate == 1)
                {
                    progressBar2.Value = 0;
                }
                else
                {
                    progressBar2.Value = 1;
                }
                if (Revalve == 1)
                {
                    progressBar5.Value = 0;
                }
                else
                {
                    progressBar5.Value = 1;
                }
                if (Repump == 1)
                {
                    progressBar6.Value = 0;
                }
                else
                {
                    progressBar6.Value = 1;
                }
            }
        }
        private void SendCommand(string command)
        {
            if (!arduinoPort.IsOpen)
            {
                MessageBox.Show("Serial port is not open.");
                return;
            }

            try
            {
                arduinoPort.WriteLine(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to send command: " + ex.Message);
            }
        }

        private void ONValve_Click(object sender, EventArgs e)
        {
            SendCommand("ONVALVE");
        }

        private void OFFValve_Click(object sender, EventArgs e)
        {
            SendCommand("OFFVALVE");
        }

        private void ONPump_Click(object sender, EventArgs e)
        {
            SendCommand("ONPUMP");
        }

        private void OFFPump_Click(object sender, EventArgs e)
        {
            SendCommand("OFFPUMP");
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (arduinoPort.IsOpen)
                arduinoPort.Close();
        }
    }
}

Arduino Coding

C/C++
const int LDR = A0;
int LDRDN = 0;
const int waterlvl = 12;
int Revalve = 7;
int Repump = 4;
const int Rainsensor = 8;
const int PoMeter = 3;
int LDRDNS = 0;
bool revalveOnButtonState = false;
bool revalveOffButtonState = false;
bool repumpOnButtonState = false;
bool repumpOffButtonState = false;
bool ReValveState = HIGH;
bool RePumpState = HIGH;

void setup() {
  Serial.begin(9600);
  pinMode(LDR, INPUT);
  pinMode(waterlvl, INPUT_PULLUP);
  pinMode(Revalve, OUTPUT);
  pinMode(Repump, OUTPUT);
  pinMode(Rainsensor, INPUT);
  pinMode(PoMeter, INPUT);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
}

void loop() {
  LDRDN = analogRead(LDR);
  int waterlvlstate = digitalRead(waterlvl);
  int Rainsensorstate = digitalRead(Rainsensor);
  int PoMeterstate = digitalRead(PoMeter);

  revalveOnButtonState = digitalRead(2) == LOW;
  revalveOffButtonState = digitalRead(3) == LOW;
  repumpOnButtonState = digitalRead(4) == LOW;
  repumpOffButtonState = digitalRead(5) == LOW;

  String stateString = String(LDRDNS) + "," + String(waterlvlstate) + "," + String(Rainsensorstate) + "," + String(PoMeterstate) + "," + String(ReValveState) + "," + String(RePumpState);
  Serial.println(stateString);

  if (revalveOnButtonState) {
    ReValveState = LOW;
  } 
  else if (revalveOffButtonState) {
    ReValveState = HIGH;
  } 
  else {
    if (Rainsensorstate == HIGH) {
      if (waterlvlstate == HIGH) {
        ReValveState = LOW;
      } else {
        ReValveState = HIGH;
      }
    } else {
      ReValveState = LOW;
    }
  }
  
  if (repumpOnButtonState) {
    RePumpState = HIGH;
  } 
  else if (repumpOffButtonState) {
    RePumpState = LOW;
  } 
  else {
    if (PoMeterstate == LOW) {
      RePumpState = LOW;
    } else {
      if (LDRDN <= 80) {
        RePumpState = LOW;
        LDRDNS = 0;
      } 
      else {
        RePumpState = HIGH;
        LDRDNS = 1;
      }
    }
  }
  digitalWrite(Revalve, ReValveState);
  digitalWrite(Repump, RePumpState);
}

Credits

Hang We Yang

Hang We Yang

1 project • 1 follower
Tan Le Ka

Tan Le Ka

1 project • 1 follower
Nilesyh Mohgan

Nilesyh Mohgan

1 project • 0 followers
Irfan Emran

Irfan Emran

1 project • 1 follower
NARENDRAN

NARENDRAN

20 projects • 22 followers

Comments