Build a Microcontroller Hand Sanitizer Dispenser to Prevent Coronavirus Spread

Original idea and source via Circuit Digest.

In a very short time, coronavirus has killed hundreds of people around the globe – and It doesn’t seem to be slowing down. We have to learn to fight it through proper hygiene and sterilization, since that is the only way to prevent its further spread. In this post, we explain how to build an automatic microcontroller hand sanitizer dispenser using a few simple steps and codes. The dispenser includes an LED screen to show live Covid updates from around the world so you can keep posted about Covid cases.

About this project

For this project, we’ll be using Esri’s API explorer to receive live updates regarding Covid19 cases. The ultrasonic sensor will detect the presence of hands under the outlet. It will measure the distance between itself and the outlet and indicate to the ESP to activate the pump. The distance in this project is 15 centimeters, which means that the pump will be activated whenever the distance is less than 15 centimeters.

ESP32 is a Wi-Fi module and is used as the main controller in this project.

Components required for the project

Ultrasonic sensor
⦁ ESP32 Dev module
⦁ 16*2 LCD
⦁ Mini DC submersible pump
⦁ Relay module
Hand sanitizer

Getting started with the Microcontroller Hand Sanitizer Dispenser

Start by setting up API link to get live Coronavirus updates

To get those updates, you need to get that data from the internet and send it to ESP32 for display on the LCD. It can be accomplished by initiating an HTTP ‘get’ request that will read the JSON file from the source. You can use the API by Coronavirus disease GIS hub to get recent confirmed cases. See the screenshots below.

Source via Circuit Digest.
Source via Circuit Digest.

When you click “Try Now” the output of the query will look something like this:

{“objectIdFieldName”:”OBJECTID”,”uniqueIdField”:{“name”:”OBJECTID”,”isSystemMaintained”:true},”globalIdFieldName”:””,”geometryType”:”esriGeometryPoint”,”spatialReference”:{“wkid”:4326,”latestWkid”:4326},”fields”:[{“name”:”Country_Region”,”type”:”esriFieldTypeString”,”alias”:”Country/Region”,”sqlType”:”sqlTypeOther”,”length”:8000,”domain”:null,”defaultValue”:null},{“name”:”Province_State”,”type”:”esriFieldTypeString”,”alias”:”Province/State”,”sqlType”:”sqlTypeOther”,”length”:8000,”domain”:null,”defaultValue”:null},{“name”:”Confirmed”,”type”:”esriFieldTypeInteger”,”alias”:”Confirmed”,”sqlType”:”sqlTypeOther”,”domain”:null,”defaultValue”:null},{“name”:”Recovered”,”type”:”esriFieldTypeInteger”,”alias”:”Recovered”,”sqlType”:”sqlTypeOther”,”domain”:null,”defaultValue”:null},{“name”:”Deaths”,”type”:”esriFieldTypeInteger”,”alias”:”Deaths”,”sqlType”:”sqlTypeOther”,”domain”:null,”defaultValue”:null},{“name”:”Active”,”type”:”esriFieldTypeInteger”,”alias”:”Active”,”sqlType”:”sqlTypeOther”,”domain”:null,”defaultValue”:null}],”features”:[{“attributes”:{“Country_Region”:”India”,”Province_State”:null,”Confirmed”:194,”Recovered”:20,”Deaths”:4,”Active”:170}}]}

Now we need to generate a code that would read that JSON data and change it for the project. To do that, simply go to ArduinoJSON assistant and copy/paste the JSON data in the input FIELD. See the image below.

Source via Circuit Digest.

After parsing the data, scroll down to the Parsing program and copy useful sections of the code. In the example below, the code represents variables that will display data regarding confirmed and recovered Covid-19 cases.

Source via Circuit Digest.

How to build a microcontroller hand sanitizer dispenser

If you connect every component and sensor in the right spot, it is very unlikely that this would fail. Below is the circuit diagram for the hand sanitizer dispenser.

Source via Circuit Digest.

In the diagram, a Relay module connects the water pump to the ESP32. The VCC and GND pins of the relay module connect to the VIN and GND pins of the microprocessor, and the D19 pin of ESP32 connect with the input pin of the relay module.

Here is a list of complete connections:

  • LCD connects to ESP32
  • VSS connects to GND
  • VDD connects to 5V
  • `VO connects to the potentiometer
  • ARS connects to D22
  • RW connects to GND
  • E connects to D4
  • D4 connects D15
  • D5 connects to D13
  • D6 connects to D26
  • D7 connects to D21
  • A connects to 5V
  • K connects to GND
  • The ultrasonic sensor connects to ESP32
  • VCC connects to VIN
  • GND connects to GND
  • Trigger connects to D5
  • Echo connects to D18

How to program ESP32 for tracking Covid updates?

Start by including all the necessary library files.

⦁ HTTP client library will fetch the data from the HTTP server.

⦁ ArduinoJSON library will parse the data.

⦁ The liquid-crystal library will be used for LCD modules.

See the code below.

#include <HTTPClient.h>
#include <WiFi.h>
#include <ArduinoJson.h>
#include <LiquidCrystal.h>

Next, connect NodeMCU ESP32 to the internet to fetch data from the server. Enter your Wi-Fi password and SSID as follows:

const char* ssid = "Galaxy-M20";
const char* pass = "ac312124";

Next, define the pins for the Ultrasonic sensor, LCD module, and relay module. As shown below.

const int rs = 22, en = 4, d4 = 15, d5 = 13, d6 = 26, d7 = 21;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 5;
const int echoPin = 18;
const int pump = 19;

After you have defined the pins, add the API link you generated earlier.

constchar*url="https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Country_Region=%27India%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered";

Next, in the void setup(), define the Echo and Trigger pins of the Ultrasonic sensor as the input pins and define the relay pin as the output.

See the code below.

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pump, OUTPUT);

Now check for the connection between ESP and the internet. If its not connected, you can wait for the connection by adding “…” on the monitor.

WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print … till not connected
}
Serial.println("WiFi connected");

Next, in the void ultra() function, add the code for distance calculation. In this example, if the distance is equal or less than 15 centimeters, the pump will be activated to dispense sanitizer. See the code below.

void ultra(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0340 / 2;
Serial.println("Distance");
Serial.println(distance);
if (distance <= 15){
Serial.print("Opening Pump");
digitalWrite(pump, HIGH);
delay(2000);
digitalWrite(pump, LOW);
ESP.restart();
}
}

Next, in the void loop(), check weather the JSON data has been received using the following code:

int httpCode = https.GET();
if (httpCode > 0) { //Check for the returning code
String payload = https.getString();

Next, use the parsing program (Arduino Assistant) to get covid-19 updates. See the code below.

JsonArray fields = doc["fields"];
JsonObject features_0_attributes = doc["features"][0]["attributes"];
long features_0_attributes_Last_Update = features_0_attributes["Last_Update"];
int features_0_attributes_Confirmed = features_0_attributes["Confirmed"];
//int features_0_attributes_Deaths = features_0_attributes["Deaths"];
int features_0_attributes_Recovered = features_0_attributes["Recovered"];

How to test automatic hand sanitizer?

After you have checked all the codes, it’s time to put the machine to test.

After you have connected the hardware as shown in the circuit diagram and uploaded the program to the microprocessor, you should see the words “Covid19 tracker” and “hand sanitizer” on the LCD. After a few seconds, the screen will show confirmed and recovered cases.

Your finished project should look something like this:

Source via Circuit Digest.

Here’s the complete code for the project:

#include <HTTPClient.h>
#include <WiFi.h>
#include <ArduinoJson.h>
#include <LiquidCrystal.h>

const char* ssid = "Galaxy-M20";
const char* pass = "ac312124";
int count;
const int rs = 22, en = 4, d4 = 15, d5 = 13, d6 = 26, d7 = 21;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 5;
const int echoPin = 18;
const int pump = 19;
long duration;
int distance;
const char* url = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_…(Country_Region=%27India%27)&returnGeometry=false&outFields=Country_Region,Confirmed,Recovered";
void setup() {
Serial.begin(115200);
delay(2000);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pump, OUTPUT);
digitalWrite(pump, LOW);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Covid19 Tracker");
lcd.setCursor(0,1);
lcd.print("Hand Sanitizer");
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print … till not connected
}
Serial.println("WiFi connected");
}
void ultra(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0340 / 2;
Serial.println("Distance");
Serial.println(distance);
if (distance <= 15){ Serial.print("Opening Pump"); digitalWrite(pump, HIGH); delay(2000); digitalWrite(pump, LOW); ESP.restart(); } } void loop() { ultra(); HTTPClient https; String data; https.begin(url); int httpCode = https.GET(); if (httpCode > 0) { //Check for the returning code
String payload = https.getString();
char charBuf[500];
payload.toCharArray(charBuf, 500);
//Serial.println(payload);
const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(4) + JSON_OBJECT_SIZE(1) + 2 * JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + 3 * JSON_OBJECT_SIZE(6) + 2 * JSON_OBJECT_SIZE(7) + 690;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, payload);
JsonArray fields = doc["fields"];
JsonObject features_0_attributes = doc["features"][0]["attributes"];
long features_0_attributes_Last_Update = features_0_attributes["Last_Update"];
int features_0_attributes_Confirmed = features_0_attributes["Confirmed"];
//int features_0_attributes_Deaths = features_0_attributes["Deaths"];
int features_0_attributes_Recovered = features_0_attributes["Recovered"];
if (count < 3){ //Serial.println(features_0_attributes_Confirmed); lcd.setCursor(0, 0); lcd.print("IN Confirmed:"); lcd.print(features_0_attributes_Confirmed); //Serial.println(features_0_attributes_Recovered); lcd.setCursor(0, 1); lcd.print("IN Recovered:"); lcd.print(features_0_attributes_Recovered); } if (count > 3){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wash Hands");
lcd.setCursor(0, 1);
lcd.print("Avoid Contacts");
}
if (count > 6){
count = 0;
}
}
else {
Serial.println("Error on HTTP request");
}
https.end();
count++;
}

If you are looking to sanitizer your home, you can build a UV sanitizing robot with simple steps. Find the tutorial here.

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

Source via Circuit Digest.

One thought on “Build a Microcontroller Hand Sanitizer Dispenser to Prevent Coronavirus Spread

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: