aman_a_shastry
Published © GPL3+

Automatic no contact hand sanitiser

Build an automatic hand sanitizing machine using an Arduino !!!

BeginnerFull instructions provided690
Automatic no contact hand sanitiser

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
The wires of the clip have to be attached to the breadboard. Cut off the barrel jack, strip the insulation of the wires and fix the wires to the power rails of the breadboard
×1
Switch
Optional
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Tape, Electrical
Tape, Electrical
You can alternatively use velcro

Story

Read more

Schematics

Circuit diagram

Code

Automatic hand sanitiser code

Arduino
// include Servo and New ping libraries
#include <Servo.h>
#include<NewPing.h>

// declaration of variables
int trigPin = 9;
int echoPin = 10;
float v = 343;
float d = 0;
float pingTime = 0;
 
int servoPin = 2;
int servoPos = 0;
 
int buzzPin = 5;
 
Servo myServo;// create an object called myServo using the servo library
NewPing sonar(trigPin,echoPin);// create an object called sonar using the New ping library, and mention the parameters as the trigger and echo pins
 
void setup()
{   
  Serial.begin(9600);// initialize our serial monitor, to see the distane from a target to the distance sensor
  
  // set pin modes for the declareed pins
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(buzzPin,OUTPUT);
  
  myServo.attach(servoPin);// attach servo in the Arduino world to the pin which it is connected to
  myServo.write(servoPos);// make the servo turn to zero degrees after Arduino is powerd up
}
 
void loop()
{
   d = sonar.ping_cm();// get the distance from the ultrasonic distance sensor in cm
//  digitalWrite(trigPin,HIGH);
//  delayMicroseconds(10);
//  digitalWrite(trigPin,LOW);
//  delayMicroseconds(10);
//  pingTime = pulseIn(echoPin,HIGH);
//  pingTime /= 10000;
//  d = pingTime*343/2;
  delay(500);
  // check is the distance is less than 15cm. If so, set the servo position to 120 degrees, and make the buzzer beep
  if(d < 15){
    servoPos = 120;
    digitalWrite(buzzPin,HIGH);
    delay(100);
    digitalWrite(buzzPin,LOW);
  }
  // if distance is greater than 15cm, keep the servo position to 0 degrees
  else{
  servoPos = 0;
  }
  digitalWrite(buzzPin,LOW); 
  myServo.write(servoPos);// write the end position of the servo
  Serial.println(d);// print the distance from the ultrasonic distance sensor to the serial monitor
}

Credits

aman_a_shastry
5 projects • 6 followers
Contact

Comments

Please log in or sign up to comment.