edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
Tarun Patel
Published © LGPL

Automatic Touchless Tap with Arduino

A hygienic, water-saving tap that opens automatically when hands come within 15cm using HC-SR04 and servo.

BeginnerFull instructions provided2 hours4
Automatic Touchless Tap with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04
SparkFun Electronics Ultrasonic Sensor - HC-SR04
×1

Software apps and online services

Arduino IDE
Arduino IDE
Tinkercad
Autodesk Tinkercad

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circuit Diagram

Automatic Touchless Tap connection using Arduino UNO, HC-SR04 and Servo Motor. Tinkercad Link: https://www.tinkercad.com/things/2a92OdCjcOj/

Code

Arduino Code for Touchless Tap

C/C++
Final Arduino code for automatic tap using HC-SR04 and servo. If distance < 15cm, servo opens.
#include <Servo.h>
Servo tapServo;
const int trigPin = 9;
const int echoPin = 10;
const int servoPin = 6;
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  tapServo.attach(servoPin);
  tapServo.write(0);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  if (distance < 15) {
    tapServo.write(90);
    delay(3000);
  } else {
    tapServo.write(0);
  }
  delay(200);
}

Credits

Tarun Patel
1 project • 0 followers

Comments