Iasonas Christoulakis
Published © LGPL

Hand Sanitizer

Keep clean and healthy!

IntermediateFull instructions provided12 hours2,936

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Accessory, Screw
Accessory, Screw
×1
Plastic Enclosure, Project Box
Plastic Enclosure, Project Box
×1
Tinned Copper Wire, Solid
Tinned Copper Wire, Solid
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fritzing

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Schematics

BE CAREFUL WHICH PORTS USE IN YOUR CODE

Code

Sanitizer

C/C++
COPY AND PASTE THE CODE TO AVOID MISTAKES
#include <Servo.h>
const int echo = 8;
const int trigger = 7;
const int servo = 9;

int distance;
long duration;
int pos;

Servo myservo;
void setup() 
{

pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(trigger,OUTPUT);
myservo.attach(servo);
myservo.write(0);
Serial.begin(9600);
}
void Sanitizer(){
  Serial.print("Servo is moving");
  for (int i=0;i<4;i++)
  {
   Serial.print("...");
   }
 myservo.write(45);
  delay(100);
 myservo.write(90);
  delay(100);
 myservo.write(135);
  delay(100);
 myservo.write(120); //Adjust how far you want the servo to go.
  delay(1000);
 myservo.write(00);
  delay(3000);
}
void loop() 
{
//Distance calculation
digitalWrite(trigger,LOW);
delay(500);

digitalWrite(trigger,HIGH);
delay(100);
digitalWrite(trigger,LOW);

duration = pulseIn(echo, HIGH);

distance = duration*0.034/2;

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

//Servo job 
//cm
if(distance<1)
{ 
  Sanitizer();
}
}

Credits

Iasonas Christoulakis

Iasonas Christoulakis

9 projects • 31 followers
Biomedical Engineer MedispLab Instructor Former General Manager at IEEE NTUA Student Branch

Comments