Manivannan
Published © GPL3+

Hands free Sanitizer Module

My project idea is to make a common module which can be fitted in sanitizer bottles irrespective of any size and shapes.

IntermediateFull instructions provided10 hours846
Hands free Sanitizer Module

Things used in this project

Hardware components

Sanitizer bottle
Any sanitizer bottle irrespective of size and shape
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
MAKERFACTORY Robot Servo MF-06
MAKERFACTORY Robot Servo MF-06
×1
Arduino Nano Every
Arduino Nano Every
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Connection between ultrasonic sensor and arduino

connect Pin 10 of arduino -> Trigger pin of Ultrasonic sensor and Pin 8 of arduino -> Echo pin of ultrasonic sensor

Code

Hands free sanitizer

Arduino
Paste this code in Arduino uno and connect Pin 10 of arduino -> Trigger pin of Ultrasonic sensor and Pin 8 of arduino -> Echo pin of ultrasonic sensor
#include <Servo.h>
   Servo myservo; // create servo object to control a servo
   int val; // variable to read the value from the analog pin

const int pingPin = 10; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 8; // Echo Pin of Ultrasonic Sensor

void setup() {
   myservo.attach(9); // attaches the servo on pin 9 to the servo object
      Serial.begin(9600); // Starting Serial Terminal

}

void loop() {
   // reads the value of the potentiometer (value between 0 and 1023)
   // scale it to use it with the servo (value between 0 and 180)
int angle=0;
long duration, inches, cm;
   pinMode(pingPin, OUTPUT);
   digitalWrite(pingPin, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(pingPin, LOW);
   pinMode(echoPin, INPUT);
   duration = pulseIn(echoPin, HIGH);
   inches = microsecondsToInches(duration);
   cm = microsecondsToCentimeters(duration);
   //Serial.print(inches);
   //Serial.print("in, ");
   Serial.println(cm);

   if(cm<12) //hand is placed near sensor
   {
      delay(10);

    for(angle = 0; angle < 180; angle += 1)   // command to move from 0 degrees to 180 degrees //pressing sanitizer
  {                                  
    myservo.write(angle);                 //command to rotate the servo to the specified angle
       Serial.println(angle);
                 
  } 
 
  delay(10);
  
  for(angle = 180; angle>=1; angle-=10)     // command to move from 180 degrees to 0 degrees // removing the pressure in sanitizer bottle
  {                                
    myservo.write(angle);              //command to rotate the servo to the specified angle
           Serial.println(angle);
                 
  } 

   }
   else
{

        Serial.print("cm  ");

      Serial.println(cm);
          myservo.write(0);                 //command to rotate the servo to the specified angle


}

}


long microsecondsToInches(long microseconds) {
   return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
   return microseconds / 29 / 2;
}

Credits

Manivannan

Manivannan

18 projects • 125 followers
Engineer by profession. Solving Real world problems by Passion .

Comments