Does this ever happen with you that someone walks into your room and then does not close the door on their way out? This happens with me a lot, whenever my Mother or my siblings were coming to my room, they left the door open which was creating a disturbance to my studies or affecting the interaction with my friends. I knew that my request for Door closer will not be taken favourably and hence I made this door closer myself from the knowledge I gained through this course.
The movement of the door is controlled by a motor driver, which is controlled by Esp32 over a local webserver. The power is provided by a rechargeable battery.
When I press the close button on the website, the motor starts rotating in the clockwise direction picking and wrapping up the string in its wheel, which in turn pulls the door.
When I press the open button on the website, the motor starts rotating in the opposite direction unwrapping all the strings and now the door is free to be open by human power. This was a necessary gesture as I am using geared motor and they can’t be rotated by an external power.
I have also provided a stop button so you can tell the motor when to stop once all the string is unwrapped else it would just coil again and start closing the door again. I thought of using fixed time intervals for the anticlockwise rotation but suppose if I just want the door a little open for some air or only half-open so my dog could go and come. This won’t have been possible if I would have used fixed time intervals. Hence, the stop button was very necessary.
I have also used a limit switch in my circuit. For some reason, if the door is half opened or not precisely in its open position and I press the close button the motor will keep rotating even after the door closes, this will break my string and ruin my door and my motor. We don’t want that hence, using a limit switch in my circuit became very important.
1. 30kg 5.5Rpm Gearmotor
2. 14.8v 6000mAh rechargeable battery with in-built charger
3. L298 2A Dual Motor Driver Module
4. Esp32
5. Limit switch
Code to control esp32 to give commands to the motor. When to stop, when to rotate clockwise, when to rotate anti-clockwise and how to Operate with the limit switch. This code also includes the website design with Automatic Door closer as heading, then By ARTHAM then the 3 buttons. Button 1 OPEN button for unwrapping then string. Button 2 CLOSE button for wrapping the string and closing the door. Button 3 STOP button for safety purposes.
#include Wifi.h
#include WebServer.h
const char* ssid = "***";
const char* password = "***";
IPAddress local_ip(192,168,1,50);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
WebServer server(80);
uint8_t ENABLEpin = 4;
uint8_t IN1pin = 2;
uint8_t IN2pin = 15;
//Limit Switch defination
uint8_t CloseLimitSw = 12;
const uint8_t OPEN = 1;
const uint8_t CLOSE = 0;
uint8_t doorStatus;
const uint8_t STOPPED = 0;
const uint8_t OPENING = 1;
const uint8_t CLOSING = 2;
int doorspeed = 255;
void setup() {
Serial.begin(115200);
pinMode(CloseLimitSw, INPUT_PULLUP);
pinMode(ENABLEpin, OUTPUT);
pinMode(IN1pin, OUTPUT);
pinMode(IN2pin, OUTPUT);
digitalWrite(ENABLEpin, HIGH);
doorStatus = STOPPED;
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);
server.on("/", handle_OnConnect);
server.on("/opendoor", handle_opendoor);
server.on("/closedoor", handle_closedoor);
server.on("/stopdoor", handle_stopdoor);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started tiger");
}
void loop() {
server.handleClient();
if((digitalRead(CloseLimitSw)== CLOSE) && (doorStatus == CLOSING))
{stopDoor();}
}
void handle_OnConnect() {
server.send(200, "text/html", SendHTML());
}
void handle_opendoor() {
openDoor();
server.send(200, "text/html", SendHTML());
}
void handle_closedoor() {
closeDoor();
server.send(200, "text/html", SendHTML());
}
void handle_stopdoor() {
stopDoor();
server.send(200, "text/html", SendHTML());
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
void closeDoor()
{
if(digitalRead(CloseLimitSw)==OPEN)
{
digitalWrite(IN1pin, LOW);
digitalWrite(IN2pin, HIGH);
doorStatus = CLOSING;
}
else
{stopDoor();}
}
void openDoor()
{
digitalWrite(IN1pin, HIGH);
digitalWrite(IN2pin, LOW);
doorStatus = OPENING;
}
void stopDoor()
{
digitalWrite(IN1pin, LOW);
digitalWrite(IN2pin, LOW);
doorStatus = STOPPED;
}
String SendHTML(){
String ptr = "\n";
ptr +="\n";
ptr +="Door Control\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="\n";
ptr +="Automatic Door Closer\n";
ptr +="By ARTHAM\n";
ptr +="Tap to OPEN the door
OPEN\n";
ptr +="Tap to CLOSE the door
CLOSE\n";
ptr +="Tap to STOP
STOP\n";
ptr +="\n";
ptr +="\n";
return ptr;
}
1. 1. 30kg 5.5Rpm Gearmotor
2. 14.8v 6000mAh rechargeable battery with in-built charger -
3. L298 2A Dual Motor Driver Module
4. Esp32
5. Limit switch