Automatic Hand Sanitizer Dispenser with COVID19 Live Updates
Hand sanitizer is absolutely indispensable during this pandemic, where many countries are under quarantine and everyone is trying to stay healthy! This project not only distributes hand sanitizer but even shows you the live count of Coronavirus cases!
Coronavirus (Covid19) is taking the whole world by storm. Almost every country is suffering from Coronavirus. WHO declared it a Pandemic disease and many cities are under quarantine, people cannot leave their homes and thousands of people have died. Many websites have Microsoft’s Tracker, Esri’s Covid19 Tracker etc. It provides live updates of coronavirus cases such as
In this project, we will build an Automatic Hand Sanitizer Dispenser with LCD that also displays the live count of Coronavirus cases. ESP32, Ultrasonic Sensor, 16×2 LCD Module, Water Pump and Hand Sanitizer will be used in this project. We use Esri’s API Explorer to get live data of people infected with Covid 19. An ultrasonic sensor is used to check for the presence of hands under the outlet of the disinfectant machine. It continuously calculates the distance between the disinfectant outlet and itself and tells the ESP to turn on the pump when the distance is less than 15 cm, to push the disinfectant out.
ESP32 is used as the main controller, it is a Wi-Fi module that can be easily connected to the Internet. In this project it will be created using ESP32. You can also do this project using Loron and Cellron cards.
Required Components
- ESP32 Development Module
- Ultrasonic sensor
- 16*2 LCD Screen
- Relay Module
- Mini DC Submersible Pump
- Hand sanitizer
API Connection to Get Corona Live Data
Here we need to get the data from internet and then send it to ESP32 for display on 16×2 LCD. For this, an HTTP fetch request is invoked to read the JSON file from the internet. Here we are using the API provided by the Coronavirus Disease GIS Hub . You can easily compile the correct query URL to get the total confirmed and recovered cases for India and change the country/region if you want to use it for a different country.
Now click “Try Now” or paste the query URL in a new browser, the output of this query will look 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}}]}
After getting the JSON data, now create the code to read the JSON data and express it according to our needs. For this, go to the ArduinoJson Assistant and paste the JSON data in the Input section.
Now go to the parsing program and copy the code section that is useful to you. We only need to copy the variables below as only confirmed and recovered cases are needed in India.
Circuit diagram
The complete circuit diagram for this Covid19 Tracker and automatic hand sanitizer dispenser is given below.
The water pump is connected to the ESP32 via a relay module. The Vcc and GND pins of the relay are connected to the Vin and GND pins of the ESP32, and the input pin of the relay is connected to the D19 pin of the ESP32. The Trig and Echo pins of the ultrasonic sensor are connected to the D5 and D18 pins of the Arduino.
Complete connections are given in the table below.
LCD | ESP32 |
VSS | GND |
VDD | 5V |
VO | Potentiometer |
RS | D22 |
RW | GND |
E | D4 |
D4 | D15 |
D5 | D13 |
D6 | D26 |
D7 | D21 |
A | 5V |
K | GND |
Ultrasonic Sensor | ESP32 |
Vcc | Vin |
GND | GND |
Trig | D5 |
ECHO | D18 |
The hardware of this Motion Sensor Hand Sanitizer Dispenser will look like this:
Programming ESP32 for Covid19 Tracker
The full code for the Automatic Hand Sanitizer and the CORONA19 Tracker is at the end of the page. Here are the important parts of the program.
Start the code by adding all the required library files. HTTPClient library is used to retrieve data from HTTP server. ArduinoJson library is used to express data arrays. Here the ArduinoJson library is used to filter the Confirmed and Recovered states from the data string we get from the server.
LiquidCrystal library is used for LCD display Module.
#include <HTTPClient.h> #include <WiFi.h> #include <ArduinoJson.h> #include <LiquidCrystal.h>
NodeMCU ESP32 needs to connect to internet to get data from server. For this, enter your Wi-Fi SSID and password on the lines below.
#const char* ssid = "Galaxy-M20"; #const char* pass = "ac312124";
Then identify the pins where you connect the LCD module, Ultrasonic sensor and Relay module.
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;
Now we enter the API link created earlier. Using this link we will get total confirmed cases and Recovered cases in India. You can change the country name in the URL according to you.
const char *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";
Now in void setup() define Trig and Echo pin of Ultrasonic sensor as input pins and Relay pin as output.
pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(pump, OUTPUT);
After that, check if the ESP is connected via Wi-Fi, if not, it will print “…..” on the serial monitor and wait for the ESP to connect.
WiFi.begin(ssid, pass); #while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); // print ... till not connected } Serial.println("WiFi connected");
Inside the void ultra() function, we will continuously calculate the distance using an ultrasonic sensor, and if the distance is less than or equal to 15cm, it will run the pump for 2 seconds to push the disinfectant out of the pipe. Obviously, when someone puts their hands under the outlet pipe, the distance will decrease and trigger the pump to turn on.
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){ distance = sensor.distance_cm() Serial.print("Opening Pump"); digitalWrite(pump, HIGH); delay(2000); digitalWrite(pump, LOW); ESP.restart(); }}
Now inside the void loop() function, print the JSON data on the serial monitor using the following lines and check if the JSON file is received by the ESP32.
int httpCode = https.GET(); if (httpCode > 0){ //Check for the returning code String payload = https.getString(); }
Now inside the void loop() function, print the JSON data on the serial monitor using the following lines and check if the JSON file is received by the ESP32.
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"];
Testing Automatic Hand Sanitizer with Covid19 Tracker
Finally, our battery powered hand sanitizer dispenser is ready for the test. Just connect the hardware according to the circuit diagram and load the program into the ESP32, you should see the message “Covid19 Tracker” & “Hand Sanitizer” on the LCD at startup, and then after a few seconds it will show the confirmed cases and recovered cases on the screen.
Similarly, you can get this data for any country by making some changes to the API connection. All code is given at the end of the page.
Code
#include #include #include #include #include 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; // Link to /rest/services/ncov_ in the variable below = //"https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=" 'dir. 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++; }
Thank you.