typalowski
Published © GPL3+

WiFi Window Blinds Control!

Control the angle of your window blinds' shades via WiFi by using an ESP32, DC Motor and driver board.

IntermediateShowcase (no instructions)6,452
WiFi Window Blinds Control!

Things used in this project

Hardware components

Adafruit HUZZAH32 – ESP32 Feather Board
Adafruit HUZZAH32 – ESP32 Feather Board
×1
Geared DC Motor, 12 V
Geared DC Motor, 12 V
×1
Darlington High Power Transistor
Darlington High Power Transistor
TiP120 Transistor
×1
Motor Driver/Controller, H-Bridge
Motor Driver/Controller, H-Bridge
I used an MD10CR3, use whatever can drive the motor.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

DC Motor Clamp

To clamp around the DC Motor.

Motor Coupler

This is for connecting the DC motor Shaft to the 1/4" hexagonal shaft that runs through my blinds.

Schematics

Circuit Diagram

Pin D5: Motor Driver On/Off
Pin D12: Direction For Motor Driver
Pin D14: On/Off Motor Control

Code

WebServer DC Motor Control Code

Arduino
Enter the name of your wifi and open serial monitor to find the ip address of your esp32. I left in PWM components of the code commented out, this can be uncommented and adjusted for speed control.
For some reason the code cannot be saved with the full code, paste the ADDITONAL_HTML_CODE in where stated.
/*
Controlling Motors for my window blinds 
Ty Palowski YouTube channel: https://youtube.com/c/typalowski
PWM components of the code are commented out,
this can be uncommented and adjusted for motor speed control.
*/ 
//define pin name
#define dir 14  // Direction Pin
#define pwrA 12 // Power Pin for Motor A
#define signalPin 5 // Turns On/Off Driver Board
int pwrAState = LOW;
int  dirStatus = 3;// stores direction status 3= stop (do not change)

String buttonTitle1[] ={"CCW", "CW"};
String buttonTitle2[] ={"CCW", "CW"};
String argId[] ={"ccw", "cw"};

#include <ESPmDNS.h>
#include <WebServer.h>
#include <WiFi.h>
#include <WiFiClient.h>

// Setting PWM properties, control the speed of the motor
//  const int freq = 30000;
//  const int pwmChannel = 0;
//  const int resolution = 8;
//  int dutyCycle = 255;
//  int operatingDC = 255;
//  int startupDC = 255;

const char *ssid = "Wifi Name Here";
const char *password = "Wifi Password Here";

WebServer server(80);

void handleRoot() {
 String HTML =
 
 ***************ENTER THE "ADDITONAL_HTML_CODE" HERE******************
   
  HTML +="</style>\n\n</head>\n\n<body>\n<h1>Blinds Control </h1>\n";

   if(dirStatus ==2){
    HTML +="\n\t<h2><span style=\"background-color: #FFFF00\">Motor Running in CW</span></h2>\n";    
   }else if(dirStatus ==1){
    HTML +="\n\t<h2><span style=\"background-color: #FFFF00\">Motor Running in CCW</span></h2>\n";      
   }else{
    HTML +="\n\t<h2><span style=\"background-color: #FFFF00\">Motor OFF</span></h2>\n";    
   }
      if(dirStatus ==1){
        HTML +="\t<div class=\"btn\">\n\t\t<a class=\"angleButton\" style=\"background-color:#f56464\"  href=\"/motor?";
        HTML += argId[0];
        HTML += "=off\">";
        HTML +=buttonTitle1[0]; //motor ON title
      }else{
        HTML +="\t<div class=\"btn\">\n\t\t<a class=\"angleButton \" style=\"background-color:#90ee90\"  href=\"/motor?";  
         HTML += argId[0];
        HTML += "=on\">";       
        HTML +=buttonTitle2[0];//motor OFF title   
      }   
     HTML +="</a>\t\n\t</div>\n\n";  
           
      if(dirStatus ==2){
        HTML +="\t<div class=\"btn\">\n\t\t<a class=\"angleButton\" style=\"background-color:#f56464\"  href=\"/motor?";
        HTML += argId[1];
        HTML += "=off\">";
        HTML +=buttonTitle1[1]; //motor ON title
      }else{
        HTML +="\t<div class=\"btn\">\n\t\t<a class=\"angleButton \" style=\"background-color:#90ee90\"  href=\"/motor?";  
         HTML += argId[1];
        HTML += "=on\">";       
        HTML +=buttonTitle2[1];//motor OFF title   
      }   
     HTML +="</a>\t\n\t</div>\n\n";     

  HTML +="\t\n</body>\n</html>\n";
  server.send(200, "text/html", HTML);  

  }//handleRoot()

void handleNotFound() {
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";

  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }

  server.send(404, "text/plain", message);
}//end of handleNotFound()

void setup(void) {  
// initialize the pwr and dir pins as outputs:
  pinMode(pwrA,OUTPUT);
  pinMode(dir,OUTPUT);
  pinMode(signalPin,OUTPUT);

// configure LED PWM functionalitites
//  ledcSetup(pwmChannel, freq, resolution);

// attach the channel to the GPIO to be controlled
//  ledcAttachPin(pwrA, pwmChannel);

//initialize the serial monitor
  Serial.begin(115200);
  Serial.println("Window Blinds Control");
    
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  
// Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: http://");
  Serial.println(WiFi.localIP());

//multicast DNS
  if (MDNS.begin("WindowBlinds")) {
    Serial.println("MDNS responder started");
    Serial.println("access via http://WindowBlinds");
  }

  server.on("/", handleRoot);
  server.on("/motor", HTTP_GET, motorControl);           
  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("HTTP server started");

}//end of setup

void loop(void) {
  server.handleClient();
if(dirStatus ==1){ 
   digitalWrite(signalPin, HIGH);
   delay(15);
   digitalWrite(dir,LOW);  // set DIR pin HIGH or LOW   
   digitalWrite(pwrA,HIGH);
   //Serial.println("Motor Turning CCW");
//   ledcWrite(pwmChannel, dutyCycle);
//   dutyCycle = startupDC;
//   delay(5);
//   dutyCycle = operatingDC;
      
 }else if(dirStatus ==2){ 
   digitalWrite(signalPin, HIGH);
   delay(15);
   digitalWrite(dir,HIGH); 
   digitalWrite(pwrA,HIGH);
   //Serial.println("Motor Turning CW");
   
//   dutyCycle = startupDC;
//   delay(5);
//   dutyCycle = operatingDC;
//   ledcWrite(pwmChannel, dutyCycle);
        
 }else{
  digitalWrite(pwrA,LOW);
  digitalWrite(signalPin, LOW); 
  //Serial.println("Motor Off");
//  ledcWrite(pwmChannel, dutyCycle);
//  dutyCycle = 0;
 }

   delay(1);
}//end of loop

void motorControl() {


    if(server.arg(argId[0]) == "on")
    {
      dirStatus = 1;// CCW 
               
    }else if(server.arg(argId[0]) == "off"){
      dirStatus = 3;  // motor OFF 
          
    }else if(server.arg(argId[1]) == "on"){
      dirStatus = 2;  // CW  
          
    }else if(server.arg(argId[1]) == "off"){
      dirStatus = 3;  // motor OFF
          
    }  

  handleRoot();
}

Credits

typalowski

typalowski

1 project β€’ 23 followers

Comments