In the world we live in today, hygiene has become more important than ever. A touchless sanitizer dispenser with a load cell-based refill alert system ensures that you stay safe while also offering convenience. The core idea behind this project is to make sanitizing hands easier without the need to touch anything, and at the same time, alert users when the sanitizer level is low, ensuring they never run out at crucial moments.
This system consists of an ultrasonic sensor that detects the presence of a hand, and a load cell that continuously monitors the sanitizer’s quantity. When the load cell detects that the level of sanitizer is getting low, a notification is triggered to remind users to refill the dispenser. This integration of touchless technology with refill alerts ensures cleanliness and convenience.
Components Required
- Arduino Uno
- HC-SR04 Ultrasonic Sensor
- 1Kg Load Cell
- HX711 Module
- 5V Mini Water Pump
- Relay Module
- 9V Battery
- BreadBoard
- Jumper Wires
- Sanitizer Container
- Buzzer
Circuit Diagram
- Connect the Ultrasonic Sensor (HC-SR04):
● VCC → 5V on Arduino
● GND → GND on Arduino
● Trig (Trigger Pin) → D9 on Arduino
● Echo (Echo Pin) → D10 on Arduin o
2. Connect the Load Cell (via HX711 Module):
● E+ → 5V on Arduino
● E- → GND on Arduino
● A+ and A- → Load Cell connections
● DT → D4 on Arduino
● SCK → D5 on Arduino
3. Connect the Water Pump (via Relay Module):
- Relay Input → D6 on Arduino
- VCC → 5V on Arduino
- GND → GND on Arduino
- Pump Power → External 5V Power Supply
Code
#include <Servo.h>
#include "HX711.h"
const int trigPin = 9; // Ultrasonic sensor trigger pin
const int echoPin = 10; // Ultrasonic sensor echo pin
const int relayPin = 6; // Relay module control pin
const int dtPin = 4; // Load cell data pin
const int sckPin = 5; // Load cell clock pin
const int buzzerPin = 7; // Buzzer pin for refill alert
HX711 scale;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
scale.begin(dtPin, sckPin);
}
void loop() {
long duration;
int distance;
// Trigger the ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echo time and calculate distance
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // Convert to cm
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// If a hand is detected within 10 cm, activate the pump
if (distance > 0 && distance <= 10) {
digitalWrite(relayPin, HIGH); // Turn on pump
delay(1000); // Dispense sanitizer for 1 second
digitalWrite(relayPin, LOW); // Turn off pump
}
// Read sanitizer level from load cell
float weight = scale.get_units();
Serial.print("Sanitizer Level: ");
Serial.println(weight);
// If sanitizer level is below 50g, trigger refill alert
if (weight < 50) {
digitalWrite(buzzerPin, HIGH); // Activate buzzer
delay(1000);
digitalWrite(buzzerPin, LOW); // Deactivate buzzer
}
delay(500); // Small delay to stabilize readings
}
CODE EXPLANATION
1. Including Necessary Libraries
- The Servo library controls the servo motor, which operates the dispenser.
- The HX711 library interfaces with the load cell, which is used to measure the sanitizer weight.
#include <Servo.h>
#include "HX711.h"
2. Defining Pin Connections
- trigPin and echoPin are used for the ultrasonic sensor.
- relayPin controls the sanitizer pump.
- dtPin and sckPin connect to the HX711 module for weight measurements.
- buzzerPin activates the refill alert.
const int trigPin = 9;
const int echoPin = 10;
const int relayPin = 6;const int dtPin = 4;
const int sckPin = 5;
const int buzzerPin = 7;
3. Initializing the System
- The setup() function initializes the sensor pins and starts serial communication.
- The HX711 module is initialized to read weight data from the load cell.
HX711 scale;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
scale.begin(dtPin, sckPin);
}
4. Measuring Distance and Dispensing Sanitizer
- The ultrasonic sensor sends a pulse and measures the return time to determine the distance to a nearby object.
- If the detected object (a hand) is within 10 cm, the pump is activated.
long duration;
int distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
5. Pump Activation
- When a hand is detected, the pump runs for 1 second, dispensing sanitizer.
if (distance > 0 && distance <= 10) {
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);
}
6. Monitoring Sanitizer Level
- The load cell reads and prints the sanitizer level in grams.
float weight = scale.get_units();
Serial.print("Sanitizer Level: ");
Serial.println(weight);
7. Triggering Refill Alert
- If the sanitizer level is below 50g, a buzzer alerts the user.
if (weight < 50) {
digitalWrite(buzzerPin, HIGH);
delay(1000);
digitalWrite(buzzerPin, LOW);
}
8. Finalizing the Loop
- A 500ms delay ensures stability in sensor readings before repeating the process.
delay(500);
The loop() function continually checks for a hand within range of the ultrasonic sensor. If a
hand is detected, it triggers the servo motor to dispense sanitizer. It also continuously checks
the load cell for sanitizer levels, triggering a refill alert when the level is low.
How It Works Together
- The ultrasonic sensor detects a hand approaching within 10 cm and triggers the servo
motor to dispense sanitizer.
- The load cell measures the weight of the sanitizer and alerts when it falls below the
preset threshold.
- The servo motor activates the sanitizer pump for 3 seconds to dispense the sanitizer,
then stops.
Observing Functionality
- Normal Mode: The dispenser remains idle.
- Hand Detection: When a hand is placed near the sensor (within 10 cm), the pump dispenses sanitizer.
- Refill Alert: If the sanitizer level drops below a threshold, an LED or buzzer alerts the user.
Common Problems and Solutions
1. Sanitizer Not Dispensing
Cause: The servo motor doesn't activate to dispense sanitiser.
Solution: Check the connections of the servo motor. Ensure that the signal pin is correctly connected to pin D6 on the Arduino. Also, make sure that the servo is working properly by testing it with a simple program.
2. Sensor Not Detecting Hand!
Cause: The ultrasonic sensor does not trigger the dispenser when a hand is placed near.
Solution: Ensure that the ultrasonic sensor is positioned correctly. It should be facing directly downward or toward the hand to detect the distance accurately. Also, check the connections to the Trig and Echo pins.
3. Low Refill Alert Not Triggering
Cause: The refill alert is not being triggered even when the sanitizer is low.
Solution: Check if the load cell is calibrated correctly. Ensure that the weight threshold (lowThreshold) is appropriate for the amount of sanitizer in the dispenser. You may need to adjust the threshold based on the actual weight of the sanitizer container.
4. Servo Runs Continuously
Solution: Verify that the servo motor is receiving the correct instructions. Ensure that dispenserServo.write(0) is being called to stop the servo after dispensing.
Conclusion
This touchless sanitizer dispenser with a refill alert system represents a smart and hygienic solution to maintaining cleanliness, especially in public spaces. By combining automated dispensing with a load cell-based alert system, it ensures users never have to worry about running out of sanitizer while promoting a cleaner, contact-free environment. This system is an excellent step towards more efficient and hygienic sanitation practices!