Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Automatic Liquid Hand Sanitizer and Soap Dispenser

Image of Arduino UNO-Based Automatic Liquid Hand Sanitizer and Soap Dispenser

Circuit Documentation

Summary

This circuit is designed for an Arduino UNO-based Automatic Liquid Hand Sanitizer Dispenser. It includes two HC-SR04 Ultrasonic Sensors, a 5V Relay Module, a 5V Mini Water Pump, a Potentiometer, an MG996R Servo Motor, and an Arduino UNO. The first ultrasonic sensor is used to trigger the water pump via the relay for dispensing hand sanitizer, while the second sensor is used to control the servo motor for a soap dispenser mechanism.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

HC-SR04 Ultrasonic Sensor (x2)

  • Ultrasonic distance sensor
  • Provides 2cm to 400cm non-contact measurement functionality with a ranging accuracy that can reach up to 3mm.

5V Mini Water Pump

  • A small water pump that operates at 5V
  • Used for pumping liquid (hand sanitizer in this case).

Potentiometer

  • A three-terminal resistor with a sliding or rotating contact that forms an adjustable voltage divider.
  • Used for adjusting a parameter in the circuit (not specified in the code).

1 Channel 5V Relay Module

  • An electrically operated switch that allows you to turn on or off a circuit using voltage and/or current much higher than a microcontroller can handle.

MG996R Servo Motor

  • A high-torque servo motor commonly used in RC vehicles, robotics, and other applications where a standard servo motor is required.

Wiring Details

Arduino UNO

  • 5V: Connected to VCC of both HC-SR04 Ultrasonic Sensors, VCC of Potentiometer, VCC+ of Relay Module, and Vcc of MG996R Servo Motor.
  • GND: Connected to GND of both HC-SR04 Ultrasonic Sensors, GND of Potentiometer, VCC- (GND) of Relay Module, GND of MG996R Servo Motor, and negative pin of 5V Mini Water Pump.
  • A0: Connected to Output of Potentiometer.
  • A2: Connected to ECHO of the first HC-SR04 Ultrasonic Sensor.
  • A3: Connected to TRIG of the first HC-SR04 Ultrasonic Sensor.
  • D2: Connected to IN of Relay Module.
  • D6: Connected to Signal Line of MG996R Servo Motor.
  • D8: Connected to ECHO of the second HC-SR04 Ultrasonic Sensor.
  • D9: Connected to TRIG of the second HC-SR04 Ultrasonic Sensor.

HC-SR04 Ultrasonic Sensor

  • VCC: Connected to 5V of Arduino UNO.
  • GND: Connected to GND of Arduino UNO.
  • TRIG: Connected to D9 of Arduino UNO (second sensor) and A3 of Arduino UNO (first sensor).
  • ECHO: Connected to D8 of Arduino UNO (second sensor) and A2 of Arduino UNO (first sensor).

5V Mini Water Pump

  • Positive pin: Connected to N.O. of Relay Module.
  • Negative pin: Connected to GND of Arduino UNO.

Potentiometer

  • VCC: Connected to 5V of Arduino UNO.
  • Output: Connected to A0 of Arduino UNO.
  • GND: Connected to GND of Arduino UNO.

1 Channel 5V Relay Module

  • VCC+: Connected to 5V of Arduino UNO.
  • VCC- (GND): Connected to GND of Arduino UNO.
  • IN: Connected to D2 of Arduino UNO.
  • N.O.: Connected to positive pin of 5V Mini Water Pump.
  • COM: Connected to 5V of Arduino UNO.

MG996R Servo Motor

  • Signal Line: Connected to D6 of Arduino UNO.
  • Vcc: Connected to 5V of Arduino UNO.
  • GND: Connected to GND of Arduino UNO.

Documented Code

/*
 * Arduino UNO-based Automatic Liquid Hand Sanitizer Dispenser
 * Components:
 * - 2x HC-SR04 Ultrasonic Sensors
 * - 1x 5V Relay Module
 * - 1x 5V Mini Water Pump
 * - 1x Potentiometer
 * - 1x MG996R Servo Motor
 * - 1x Arduino UNO
 *
 * Functionality:
 * - Ultrasonic sensor 1 triggers the water pump via relay for hand sanitizer
 * - Ultrasonic sensor 2 triggers the servo motor for soap dispenser
 */

// Pin definitions
const int trigPin1 = A3;
const int echoPin1 = A2;
const int trigPin2 = 9;
const int echoPin2 = 8;
const int relayPin = 2;
const int servoPin = 6;
const int potPin = A0;

// Include Servo library
#include <Servo.h>
Servo soapServo;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(relayPin, OUTPUT);
  soapServo.attach(servoPin);

  // Set initial states
  digitalWrite(relayPin, LOW);
  soapServo.write(0);
}

void loop() {
  // Read distance from ultrasonic sensor 1
  long duration1, distance1;
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1 / 2) / 29.1;

  // Read distance from ultrasonic sensor 2
  long duration2, distance2;
  digitalWrite(trigPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2 / 2) / 29.1;

  // Check distance for hand sanitizer
  if (distance1 < 10) {
    digitalWrite(relayPin, HIGH); // Turn on water pump
    delay(1000); // Pump for 1 second
    digitalWrite(relayPin, LOW); // Turn off water pump
  }

  // Check distance for soap dispenser
  if (distance2 < 10) {
    soapServo.write(90); // Push actuator
    delay(1000); // Hold for 1 second
    soapServo.write(0); // Reset actuator
  }

  // Small delay before next loop
  delay(100);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins, sets up the servo motor, and continuously checks the distance readings from the ultrasonic sensors to control the relay and servo motor accordingly.