Automatic Water Dispensing System using Time of Flight Sensor and Submersible Pump

Overview:

Sometimes, we wonder about the convenience of the automated faucet or flush valves commonly found in hotels and malls. The absence of a valve, handle, or knob to dispense water is an idea that provides luxurious comfort and amusement.

This blog explores the construction of an automated water dispensing system that activates once an object, ideally a water jug or bottle, is near the dispenser or faucet. In this project we will use the Arduino Nano as the microcontroller, a TOF (time-of flight) sensor to measure object distance/proximity, and a relay + mini pump to activate/deactivate water supply. 

 

Components:

 

Hardware Components

 

 

Software Components

  • Arduino IDE

 

 

Application Discussion:

  • VL53L0X TOF sensor

A small form factor Time of Flight (ToF) laser-ranging module that can measure distances up to 2m. Unlike conventional technologies, VL53L0X has the smallest footprint and the highest range of performance. 

The sensor can be powered from a 2.6 V to 5.5 V supply thanks to a low-dropout linear voltage regulator on the carrier board that supplies the 2.8 V needed by the VL53L0X. It is also straightforward to connect the breakout board to 3.3 V or 5 V systems thanks to a circuit on the breakout board that adjusts the I2C clock and data lines to the same logic voltage level as the provided VIN.

VIN, GND, SCL, and SDA are the minimum number of connections required to operate the VL53L0X board. The GND pin should be linked to Arduino GND, and the VIN pin should be connected to a 5.5 V source. The SCL and SDA I2C pins are attached to integrated level-shifters that make them safe to use at voltages beyond 2.8 V (they should be connected to an I2C bus running at the same logic level as VIN) which in an Arduino Nano board is A5 and A4, respectively. 

 

  • Relay 1-channel module

An electrical switch that is activated by an electromagnet is a relay module. A different low-power signal, in this example from the Arduino Nano microcontroller, activates the electromagnet. The electromagnet pulls when it is turned on, allowing a circuit to be opened or closed.

 

  • Mini submersible water pump

A budget friendly pump for DIY Arduino projects. It operates from a 2.5V ~ 6V power supply (220mA). The mini pump is submersible and can draw 120 liters of water per hour.

 

Hardware set-up:

PIN Connections

 

Single Channel 5V relay module

  • IN1 Pin is connected to Arduino nano pin D2
  • Normally open (NO) node is connected to the 3.7V (4800mAh) power supply
  • Common node is connected to the submersible mini water pump

 

VL53L0X Time of Flight (ToF) Laser-Ranging Sensor

  • VIN is connected to Arduino nano 5V
  • GND is connected to Arduino nano GND
  • SCL is connected to Arduino nano A5
  • SCA is connected to Arduino nano A4

 

Software set-up:

VL53L0X ToF Sensor library

To start working on the VL53L0X ToF sensor, a library is already available in Arduino IDE. To include the library, we must go to Tools -> Manage Libraries -> Then search for VL53L0X by pololu. We included this library because this contains an example code that is simple and straightforward.

 

Code:

#include <Wire.h>
#include <VL53L0X.h>

#define RELAY_PIN 2
#define PROXIMITY_THRESHOLD 100  // Change this value according to your requirements

VL53L0X sensor;
bool relayState = false;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH);

  Serial.begin(9600);

  Wire.begin();
  sensor.init();
  sensor.setTimeout(500);

  if (!sensor.init()) {
    Serial.println("Failed to initialize VL53L0X sensor!");
    while (1)
      ;
  }

  sensor.startContinuous();
}

void loop() {
  int distance = sensor.readRangeContinuousMillimeters();

  if (sensor.timeoutOccurred()) {
    Serial.println("VL53L0X sensor timeout!");
    return;
  }

  if (distance < PROXIMITY_THRESHOLD) {
    if (!relayState) {
      // Object is near the sensor, open the solenoid valve
      digitalWrite(RELAY_PIN, LOW);
      relayState = true;
    }
  } else {
    if (relayState) {
      // Object is far from the sensor, close the solenoid valve
      digitalWrite(RELAY_PIN, HIGH);
      relayState = false;
    }
  }

  Serial.print("Distance (mm): ");
  Serial.println(distance);

  delay(100);
}

 

Code Breakdown:

 

Code block before setup()

  • Required variables such as the relay pin and proximity threshold are defined to be used in the succeeding lines of codes.

 

Setup()

  • In this part, the sensor is initialized.
  • The relay pin is triggered High initially, because the mini submersible water pump is connected to the normally open (NO) node. This is to ensure that the water pump will be turned on even if the relay doesn’t have power.

 

Loop()

  • The VL53L0X sensor readings are assigned to distance. After which, the distance is compared to the threshold value defined before Setup().
  • If the distance (sensor readings in millimeters) exceeds the threshold value (in this case 200mm) the relay will be turned off, enabling the water pump
  • However, if the distance is below the threshold value of 200mm, the relay is remained turned on and the pump disabled.

 

Video Demo:

 

Conclusion:

This tutorial successfully demonstrates an automatic water dispenser using VL53L0X (ToF) sensor. The automation works like bathroom faucets or flush valves seen in hotels and grand malls. The dispenser provides potable water once the VL53L0X (ToF) sensor detects an object below the distance threshold value.

The integration of GSM technology to send SMS/test message is highly recommended as it will be a vital component when it is decided to place an automated water dispenser publicly. This will enable the owner to monitor the dispenser or station.

 

References:

1-channel relayArduino nanoDistance sensorRelaySubmersible pumpTime of flight sensorTofVl53l0xWater pump

Leave a comment

All comments are moderated before being published