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.
/*
* 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.