Introduction: Smart Hand Sanitizer

Lately, the world is in the midst of a pandemic that has yet to end. The Coronavirus disease (COVID-19) is an infectious disease caused by a newly discovered coronavirus. Especially in Indonesia, its spread continues to increase which results in a growing number of casualties. Many factor cause the spread of this virus, such as direct contact with other people. Therefore, we got the idea to make a tool called Smart Hand Sanitizer.

Smart Hand Sanitizer is an automatic hand sanitizer uses an ultrasonic sensor to detect an object. This hand sanitizer is designed for individual or company, since this tool uses IoT for counts the number of users based on the number of strain is applied to the hydraulic pump. The objective of making this tool is to minimize direct contact with other users, and we hope this tool can help a company or an individual find out the number of users of this tool, so they could find out whether the placement of this hand sanitizer has been right or not. Therefore, they could move to another places which can be more efficient and reach a larger number of people.

Step 1: Prepare All the Components

Prepare all the components we'll use. The Breadboard, ESP, Ultrasonic Sensor, Jumper, Voltage Regulator L7805CV, Capacitor, DC Jack, Push Button, Stepper Motor, Stepper Motor Driver A4988, and PSU. Here some explanation and the picture of the components.

  1. Breadboard
    The first component we will use is breadboard which is a construction base for prototyping of electronics.

    https://en.wikipedia.org/wiki/Breadboard
  2. Jump Wire
    Jump Wire or also known as Jumper is an electrical wire, or group of them in a cable, with a connector or pin at each end (or sometimes without them – simply "tinned"), which is normally used to interconnect the components of a breadboard or other prototype or test circuit, internally or with other equipment or components, without soldering. In this case, we will use the Jumper Male to Male.

    https://en.wikipedia.org/wiki/Jump_wire
  3. Stepper Motor
    A Stepper Motor is an electric motor whose main feature is that its shaft rotates by performing steps, that is, by moving by a fixed amount of degrees.

    https://www.monolithicpower.com/stepper-motors-basics-types-uses
  4. Stepper Motor Driver A4988
    If we want to use a Stepper Motor, we also have to use a driver for the stepper motor. This A4988 is a microstepping driver for controlling bipolar stepper motors which has built-in translator for easy operation. This means that we can control the stepper motor with just 2 pins from our controller, or one for controlling the rotation direction and the other for controlling the steps.

    https://howtomechatronics.com/tutorials/arduino/how-to-control-stepper-motor-with-a4988-driver-and-arduino/
  5. Ultrasonic Sensor
    An ultrasonic sensor is an electronic device that measures the distance of a target object by emitting ultrasonic sound waves, and converts the reflected sound into an electrical signal. This is one of the most important component, since we will make an automatic device. The sensor will detects interference, in this case is a hand. After the interference activated the sensor, it will move the motor.

    https://www.fierceelectronics.com/sensors/what-ultrasonic-sensor
  6. ESP Wroom 32
    ESP-WROOM-32 is a Wi-Fi module equipped with a chip called ESP32 provided by Espressif Systems and capable of Wi-Fi and Bluetooth (BLE) communication. It is slightly larger than ESP-WROOM-02, but it still is small. The module also has the advantage that Arduino programs can be written (that is, the module can be used as part of Arduino), Wi-Fi communication is supported, and the cost is lower.

    https://www.deviceplus.com/arduino/lets-play-with-esp-wroom-32-on-arduino-environment-construction-setup-led-blinking/
  7. DC Jack
    DC Jack is also known as a DC connector (or DC plug, for one common type of connector) is an electrical connector for supplying direct current (DC) power.

    https://en.wikipedia.org/wiki/DC_connecto
  8. Power Supply
    A power supply is an electrical device that supplies electric power to an electrical load.
    https://en.wikipedia.org/wiki/Power_supply#:~:text=A%20power%20supply%20is%20an,power%20to%20an%20electrical%20load.&text=All%20power%20supplies%20have%20a,deliver%20current%20to%20the%20load.
  9. Voltage Regulator L7805CV
    7805 is a three terminal linear voltage regulator IC with a fixed output voltage of 5V. The important features of the 7805 IC is it can deliver up to 1.5 A of current (with heat sink), has both internal current limiting and thermal shutdown features, and requires very minimum external components to fully function.

    https://www.electronicshub.org/understanding-7805-ic-voltage-regulator/#:~:text=7805%20is%20a%20three%20terminal,incorporated%2C%20Infineon%20Technologies%2C%20etc.

  10. Capacitor
    A capacitor is a device that stores electrical energy in an electric field. It is a passive electronic component with two terminals. In this experiment, we'll need 3 types of capacitors which is 10 μF, 100 nF, and 100 μF.

    https://en.wikipedia.org/wiki/Capacitor
  11. Push Button
    A push-button (also spelled pushbutton) or simply button is a simple switch mechanism to control some aspect of a machine or a process. In this case the push button is used to set the device whether on or off.

    https://en.wikipedia.org/wiki/Push-button

Step 2: Sketch the Schematic

Sketch the schematic based on the picture above. We are using fritzing to make them.

Step 3: Connect All the Components on the Breadboard

After sketching the schematic, connect all the components into the breadboard by following the picture above.

Step 4: Setup the Firebase

In this step, you have to set up the firebase by going to the console.firebase.google.com. Click on "Add Project", enter your project name, and Continue. The next step is choose the Google Analytics would be enable or disable for this project, click on "Continue", and "Create Project".

After the Firebase is ready, click "Realtime Database", then "Create Database". You will be directed to "Set Up Database". Here, you will have to choose the Realtime Database Location as " United States (us-central1)", "Next", and choose the "Start in Lock Mode", and then you have to enable them.

Now, you have the Realtime Database. Fill the workspace by following the picture above.

Step 5: Create the Apps Using MIT App Inventor

After setting up the firebase, we have to set up the MIT App Inventor. Go to the "ai2.appinventor.mit.edu". The first step is Click "Create Apps!" and accept the terms of service. Click "Start New Project", enter your project name (name can't consist of "_" , so for example you want to enter your project name as "Smart Hand Sanitizer". You can write as "Smart-Hand-Sanitizer".)
Firstly, setup the display of the apps by following the picture above. (picture on the left) Then, click "Experimental" on the Palette and click "FirebaseDB". In this case, we are going to add 7 FirebaseDB since we have 7 branch (Date, Hour, Minute, Month, Second, Total User, and Year). Every bucket has their own Database. If you click "FirebaseDB1" on the Components table, the Properties table will show you the Firebase Token, Firebase URL, and Project Bucket. You should fill the "Firebase Token" by the authentication key of your database and "Firebase URL" should be filled by the complete URL (include the https). The "ProjectBucket" will be filled by the Bucket Name we've setup on the Firebase. Do the same thing on other FirebaseDB until all of the Properties of every FirebaseDB filled by the correct data.
If you've finished on setting up the display, you can go to the Blocks and follow the picture above (the picture on the right).

Step 6: Coding

If the Apps is ready, we are going to code the project. The idea of this project is we wanted to make automatized hand sanitizer that could collect data such as the total user of this device and what time it's detected. All this data would be sent to the Apps we've made and will be shown on the Hardware (phone or computer). So, in this case we need to construct the code for the ESP32. The software that we used are Arduino IDE.
Code the Project
The first step of coding the project is including all of the libraries we need. For this project, we need to include 4 libraries which are WiFi.h library is used for connecting to the internet, the Ultrasonic.h is used for the ultrasonic sensor, Time.h is used for getting the real time that we're going to use when sensor detects a hand. The last one is FirebaseESP32.h which used for connecting ESP32 to Firebase and to be able to send data.

#include <WiFi.h>
#include <Ultrasonic.h>
#include <time.h>
#include <FirebaseESP32.h>

After all of the libraries is included, define and initialize the Firebase. Using this code below:

#define FIREBASE_HOST "your-database-url" //without http://
#define FIREBASE_AUTH "your-database-token" //get it from firebase settings

FirebaseData firebasedata;
FirebaseJson json;

The next step is define the stepper motor. We are going to define the pin we're going to use for the dirPin and stepPin. The dirPin is input controls the spinning direction of the motor by pulling it HIGH drives the motor clockwise and pulling it LOW drives the motor counterclockwise. While, the stepPin is input controls the mirosteps of the motor. Each HIGH pulse sent to this pin steps the motor by number of microsteps set by Microstep Selection Pins. The faster the pulses, the faster the motor will rotate. We set the motor to rotate 400 steps and delay on 1000 milliseconds.

#define dirPin 18
#define stepPin 19
int Step = 400;
int Delay = 1000;

Now, we have to setting up the ESP32 using the Network Time Protocol (NTP) server. This is used for getting the real time when the ultrasonic sensor detects a hand. The value of 25200 is got from the location we are using now. For example if we are in Jakarta, the timezone is UTC + 7 hours. Then, we have to convert to the second. So we got the formula, 7*60*60 = 25200. The daylightOffset is using 3600, since time in Jakarta is consistent.

// ESP32 NETWORK TIME PROTOCOL
const char* ntpServer = "pool.ntp.org";   //NTP Server
const long gmtOffset_sec = 25200;        //Jkt UTC+7 = 7 * 60 * 60
const int daylightOffset_sec = 3600;

Declare and initialize the Ultrasonic Sensor. Follow the code below.

// ULTRASONIC SENSOR
Ultrasonic ultrasonic(13, 12); //trigPin, echoPin
int totalUser;
int distance;

For showing the date and time on the apps we have made, we should make an array for every characters.

//Date & Time
char date[3];
char month[20];
char year[5];
char hour[3];
char minute[3];
char second[3];

Here we set the ssid and password of Wifi we're going to connect.

const char* ssid = "your-ssid";
const char* password = "your-pass";

Follow the code below for the Void Setup.

void setup(){
  Serial.begin(115200);

  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP32 Local IP Address
  Serial.println(WiFi.localIP());

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  // Init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}

Then, the Void Loop below consists of how the ultrasonic sensor works. It will detect a hand if the distance is less than 20 cm, then it will call the stepper function. The total user will be added by 1 and get the time. After that, we send the data to Firebase.

void loop(){
  distance = ultrasonic.read();
  if (distance <= 20){
    stepper();
    totalUser = totalUser + 1;
    getTime();
    Firebase.setInt(firebaseData, "/Device 1/Total User", totalUser);
    Firebase.setString(firebaseData, "/Device 1/Date", date);
    Firebase.setString(firebaseData, "/Device 1/Month", month);
    Firebase.setString(firebaseData, "/Device 1/Year", year);
    Firebase.setString(firebaseData, "/Device 1/Hour", hour);
    Firebase.setString(firebaseData, "/Device 1/Minute", minute);
    Firebase.setString(firebaseData, "/Device 1/Second", second);
  }
  delay(1000);
}

Void Stepper is used to rotate the Stepper Motor. Follow the code below:

void stepper () {
  digitalWrite(dirPin, LOW);

  for (int x = 0; x < Step; x++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(Delay);
  }

  digitalWrite(dirPin, HIGH);

  for (int x = 0; x < Step; x++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(Delay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(Delay);
  }
}

Void getTime. This void is used to get the real time. Follow the code below:

void getTime () {
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
  }
  strftime(date, sizeof(date), "%d", &timeinfo);
  strftime(month, sizeof(month), "%B", &timeinfo);
  strftime(year, sizeof(year), "%Y", &timeinfo);
  strftime(hour, sizeof(hour), "%H", &timeinfo);
  strftime(minute, sizeof(minute), "%M", &timeinfo);
  strftime(second, sizeof(second), "%S", &timeinfo);
  /* %A = day of week
     %B = month of year
     %d = day of month
     %Y = year
     %H = hour
     %M = minutes
     %S = seconds
  */
}
}

Step 7: Sketch the Case

We are using wood as our casing. Sketch the case by following these dimensions:

  1. The bottom side of the box
    Length = 19.5 cm
    Width = 10 cm
  2. The back side of the box
    Length = 31.6 cm
    Width = 10 cm
  3. The top end of the case
    Length = 6.5 cm
    Width = 4 cm
  4. The front side of the box
    Length = 10 cm
    Width = 4.5 cm
  5. The upper side of the box
    Length = 18 cm
    Width = 10 cm
  6. The right and left side of the box
    Length = 18.5 cm
    Width = 6.5 cm

    The width of wood we use is 1.5 cm.
    Note: This is just a dimension for the sketch. You can change the dimension as your needs.

Step 8: Make Casing

Cut the wood based on the dimensions you've made.

Step 9: Setting Up All Together

This is the final look of our Smart Hand Sanitizer.