Corona virus (Covid 19) is spreading all around the world. Hence it's very important to keep our hands sanitized. Here is the simple project to build an electronic hand sanitizer that can be operated using smartphone via bluetooth. IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using nodemcu to as a controller for the project.
Circuit diagram:
Arduino code:
#include <ESP8266WiFi.h>
#include <Servo.h>
Servo servo;
//Static IP address configuration
IPAddress staticIP(192, 168, 225, 81); //ESP static ip
IPAddress gateway(192, 168, 225, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
//Define wifi configuration
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// Create an instance of the server
WiFiServer server(80);
void setup() {
Serial.begin(9600);
// prepare GPIO 4
servo.attach(4);
//Motor in home position
servo.write(90);
servo.detach();
delay(100);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
//Configuring Static IP
WiFi.config(staticIP,gateway,subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
// Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
//Serial.println(req);
//Serial.println("req");
client.flush();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else if(req.indexOf("ON1") != -1)
{
servo.attach(4); // No . 4 is GPIO 4 means servo is attached to pin D2 of NODE MCU.
servo.write(140);
delay(1000);
servo.write(90);
delay(300);
servo.detach();
}
// else if(req.indexOf("OFF1") != -1)
// {
// digitalWrite(D0, HIGH);
// }
else {
client.stop();
return;
}
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
// Send the response to the client
//client.print(s);
delay(1);
Serial.println("Client disconnected");
// The client will actually be disconnected
// when the function returns and 'client' object is destroyed
}
Description:
Most of the code is commented. Some of the important points to highlight
In this code we need to change the gateway according to our network.
Simple method - (For windows)
Open command prompt - type “ipconfig”
Look for “default gateway”. A set of four numbers will be displayed. In my case its 192.168.xxx.1
Note this “xxx” number, goto line in the code where “staticIP” is defined and replace the 3rd number with this number you just found.
Ex: default gateway is 192. 169. 255 .1
So in my code -
IPAddress staticIP (192, 168, 225, 81); //ESP static ip
IPAddress gateway (192, 168, 225, 1);
Next step is changing SSID and password
Replace YOUR_SSID in this line - const char* ssid = "YOUR_SSID" with your wifi name.
Replace YOUR_WIFI_PASSWORD in the line const char* password = "YOUR_WIFI_PASSWORD"; with your wifi password
ANDROID APP SETTINGS:
To test the project , open the android app “LINK HERE” , type IP address of the device and same gateway .
Now type “ON1” keyword into send section and hit send.
In the receive section of the app you will be able to see the response from the arduino device.
Project arrangement:
Android app : Link to app store