WiFi Window Blinds Control!
Control the angle of your window blinds' shades via WiFi by using an ESP32, DC Motor and driver board.
Components and supplies
Adafruit HUZZAH32 – ESP32 Feather Board
Motor Driver/Controller, H-Bridge
Geared DC Motor, 12 V
Darlington High Power Transistor
Tools and machines
3D Printer (generic)
Hot glue gun (generic)
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
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.
1/* 2Controlling Motors for my window blinds 3Ty Palowski YouTube channel: https://youtube.com/c/typalowski 4PWM components of the code are commented out, 5this can be uncommented and adjusted for motor speed control. 6*/ 7//define pin name 8#define dir 14 // Direction Pin 9#define pwrA 12 // Power Pin for Motor A 10#define signalPin 5 // Turns On/Off Driver Board 11int pwrAState = LOW; 12int dirStatus = 3;// stores direction status 3= stop (do not change) 13 14String buttonTitle1[] ={"CCW", "CW"}; 15String buttonTitle2[] ={"CCW", "CW"}; 16String argId[] ={"ccw", "cw"}; 17 18#include <ESPmDNS.h> 19#include <WebServer.h> 20#include <WiFi.h> 21#include <WiFiClient.h> 22 23// Setting PWM properties, control the speed of the motor 24// const int freq = 30000; 25// const int pwmChannel = 0; 26// const int resolution = 8; 27// int dutyCycle = 255; 28// int operatingDC = 255; 29// int startupDC = 255; 30 31const char *ssid = "Wifi Name Here"; 32const char *password = "Wifi Password Here"; 33 34WebServer server(80); 35 36void handleRoot() { 37 String HTML = 38 39 ***************ENTER THE "ADDITONAL_HTML_CODE" HERE****************** 40 41 HTML +="</style>\ 42\ 43</head>\ 44\ 45<body>\ 46<h1>Blinds Control </h1>\ 47"; 48 49 if(dirStatus ==2){ 50 HTML +="\ 51\ <h2><span style=\\"background-color: #FFFF00\\">Motor Running in CW</span></h2>\ 52"; 53 }else if(dirStatus ==1){ 54 HTML +="\ 55\ <h2><span style=\\"background-color: #FFFF00\\">Motor Running in CCW</span></h2>\ 56"; 57 }else{ 58 HTML +="\ 59\ <h2><span style=\\"background-color: #FFFF00\\">Motor OFF</span></h2>\ 60"; 61 } 62 if(dirStatus ==1){ 63 HTML +="\ <div class=\\"btn\\">\ 64\ \ <a class=\\"angleButton\\" style=\\"background-color:#f56464\\" href=\\"/motor?"; 65 HTML += argId[0]; 66 HTML += "=off\\">"; 67 HTML +=buttonTitle1[0]; //motor ON title 68 }else{ 69 HTML +="\ <div class=\\"btn\\">\ 70\ \ <a class=\\"angleButton \\" style=\\"background-color:#90ee90\\" href=\\"/motor?"; 71 HTML += argId[0]; 72 HTML += "=on\\">"; 73 HTML +=buttonTitle2[0];//motor OFF title 74 } 75 HTML +="</a>\ \ 76\ </div>\ 77\ 78"; 79 80 if(dirStatus ==2){ 81 HTML +="\ <div class=\\"btn\\">\ 82\ \ <a class=\\"angleButton\\" style=\\"background-color:#f56464\\" href=\\"/motor?"; 83 HTML += argId[1]; 84 HTML += "=off\\">"; 85 HTML +=buttonTitle1[1]; //motor ON title 86 }else{ 87 HTML +="\ <div class=\\"btn\\">\ 88\ \ <a class=\\"angleButton \\" style=\\"background-color:#90ee90\\" href=\\"/motor?"; 89 HTML += argId[1]; 90 HTML += "=on\\">"; 91 HTML +=buttonTitle2[1];//motor OFF title 92 } 93 HTML +="</a>\ \ 94\ </div>\ 95\ 96"; 97 98 HTML +="\ \ 99</body>\ 100</html>\ 101"; 102 server.send(200, "text/html", HTML); 103 104 }//handleRoot() 105 106void handleNotFound() { 107 String message = "File Not Found\ 108\ 109"; 110 message += "URI: "; 111 message += server.uri(); 112 message += "\ 113Method: "; 114 message += (server.method() == HTTP_GET) ? "GET" : "POST"; 115 message += "\ 116Arguments: "; 117 message += server.args(); 118 message += "\ 119"; 120 121 for (uint8_t i = 0; i < server.args(); i++) { 122 message += " " + server.argName(i) + ": " + server.arg(i) + "\ 123"; 124 } 125 126 server.send(404, "text/plain", message); 127}//end of handleNotFound() 128 129void setup(void) { 130// initialize the pwr and dir pins as outputs: 131 pinMode(pwrA,OUTPUT); 132 pinMode(dir,OUTPUT); 133 pinMode(signalPin,OUTPUT); 134 135// configure LED PWM functionalitites 136// ledcSetup(pwmChannel, freq, resolution); 137 138// attach the channel to the GPIO to be controlled 139// ledcAttachPin(pwrA, pwmChannel); 140 141//initialize the serial monitor 142 Serial.begin(115200); 143 Serial.println("Window Blinds Control"); 144 145 WiFi.mode(WIFI_STA); 146 WiFi.begin(ssid, password); 147 Serial.println(""); 148 149// Wait for connection 150 while (WiFi.status() != WL_CONNECTED) { 151 delay(500); 152 Serial.print("."); 153 } 154 155 Serial.println(""); 156 Serial.print("Connected to "); 157 Serial.println(ssid); 158 Serial.print("IP address: http://"); 159 Serial.println(WiFi.localIP()); 160 161//multicast DNS 162 if (MDNS.begin("WindowBlinds")) { 163 Serial.println("MDNS responder started"); 164 Serial.println("access via http://WindowBlinds"); 165 } 166 167 server.on("/", handleRoot); 168 server.on("/motor", HTTP_GET, motorControl); 169 server.onNotFound(handleNotFound); 170 server.begin(); 171 Serial.println("HTTP server started"); 172 173}//end of setup 174 175void loop(void) { 176 server.handleClient(); 177if(dirStatus ==1){ 178 digitalWrite(signalPin, HIGH); 179 delay(15); 180 digitalWrite(dir,LOW); // set DIR pin HIGH or LOW 181 digitalWrite(pwrA,HIGH); 182 //Serial.println("Motor Turning CCW"); 183// ledcWrite(pwmChannel, dutyCycle); 184// dutyCycle = startupDC; 185// delay(5); 186// dutyCycle = operatingDC; 187 188 }else if(dirStatus ==2){ 189 digitalWrite(signalPin, HIGH); 190 delay(15); 191 digitalWrite(dir,HIGH); 192 digitalWrite(pwrA,HIGH); 193 //Serial.println("Motor Turning CW"); 194 195// dutyCycle = startupDC; 196// delay(5); 197// dutyCycle = operatingDC; 198// ledcWrite(pwmChannel, dutyCycle); 199 200 }else{ 201 digitalWrite(pwrA,LOW); 202 digitalWrite(signalPin, LOW); 203 //Serial.println("Motor Off"); 204// ledcWrite(pwmChannel, dutyCycle); 205// dutyCycle = 0; 206 } 207 208 delay(1); 209}//end of loop 210 211void motorControl() { 212 213 214 if(server.arg(argId[0]) == "on") 215 { 216 dirStatus = 1;// CCW 217 218 }else if(server.arg(argId[0]) == "off"){ 219 dirStatus = 3; // motor OFF 220 221 }else if(server.arg(argId[1]) == "on"){ 222 dirStatus = 2; // CW 223 224 }else if(server.arg(argId[1]) == "off"){ 225 dirStatus = 3; // motor OFF 226 227 } 228 229 handleRoot(); 230}
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.
1/* 2Controlling Motors for my window blinds 3Ty Palowski YouTube channel: https://youtube.com/c/typalowski 4PWM components of the code are commented out, 5this can be uncommented and adjusted for motor speed control. 6*/ 7//define pin name 8#define dir 14 // Direction Pin 9#define pwrA 12 // Power Pin for Motor A 10#define signalPin 5 // Turns On/Off Driver Board 11int pwrAState = LOW; 12int dirStatus = 3;// stores direction status 3= stop (do not change) 13 14String buttonTitle1[] ={"CCW", "CW"}; 15String buttonTitle2[] ={"CCW", "CW"}; 16String argId[] ={"ccw", "cw"}; 17 18#include <ESPmDNS.h> 19#include <WebServer.h> 20#include <WiFi.h> 21#include <WiFiClient.h> 22 23// Setting PWM properties, control the speed of the motor 24// const int freq = 30000; 25// const int pwmChannel = 0; 26// const int resolution = 8; 27// int dutyCycle = 255; 28// int operatingDC = 255; 29// int startupDC = 255; 30 31const char *ssid = "Wifi Name Here"; 32const char *password = "Wifi Password Here"; 33 34WebServer server(80); 35 36void handleRoot() { 37 String HTML = 38 39 ***************ENTER THE "ADDITONAL_HTML_CODE" HERE****************** 40 41 HTML +="</style>\ 42\ 43</head>\ 44\ 45<body>\ 46<h1>Blinds Control </h1>\ 47"; 48 49 if(dirStatus ==2){ 50 HTML +="\ 51\ <h2><span style=\\"background-color: #FFFF00\\">Motor Running in CW</span></h2>\ 52"; 53 }else if(dirStatus ==1){ 54 HTML +="\ 55\ <h2><span style=\\"background-color: #FFFF00\\">Motor Running in CCW</span></h2>\ 56"; 57 }else{ 58 HTML +="\ 59\ <h2><span style=\\"background-color: #FFFF00\\">Motor OFF</span></h2>\ 60"; 61 } 62 if(dirStatus ==1){ 63 HTML +="\ <div class=\\"btn\\">\ 64\ \ <a class=\\"angleButton\\" style=\\"background-color:#f56464\\" href=\\"/motor?"; 65 HTML += argId[0]; 66 HTML += "=off\\">"; 67 HTML +=buttonTitle1[0]; //motor ON title 68 }else{ 69 HTML +="\ <div class=\\"btn\\">\ 70\ \ <a class=\\"angleButton \\" style=\\"background-color:#90ee90\\" href=\\"/motor?"; 71 HTML += argId[0]; 72 HTML += "=on\\">"; 73 HTML +=buttonTitle2[0];//motor OFF title 74 } 75 HTML +="</a>\ \ 76\ </div>\ 77\ 78"; 79 80 if(dirStatus ==2){ 81 HTML +="\ <div class=\\"btn\\">\ 82\ \ <a class=\\"angleButton\\" style=\\"background-color:#f56464\\" href=\\"/motor?"; 83 HTML += argId[1]; 84 HTML += "=off\\">"; 85 HTML +=buttonTitle1[1]; //motor ON title 86 }else{ 87 HTML +="\ <div class=\\"btn\\">\ 88\ \ <a class=\\"angleButton \\" style=\\"background-color:#90ee90\\" href=\\"/motor?"; 89 HTML += argId[1]; 90 HTML += "=on\\">"; 91 HTML +=buttonTitle2[1];//motor OFF title 92 } 93 HTML +="</a>\ \ 94\ </div>\ 95\ 96"; 97 98 HTML +="\ \ 99</body>\ 100</html>\ 101"; 102 server.send(200, "text/html", HTML); 103 104 }//handleRoot() 105 106void handleNotFound() { 107 String message = "File Not Found\ 108\ 109"; 110 message += "URI: "; 111 message += server.uri(); 112 message += "\ 113Method: "; 114 message += (server.method() == HTTP_GET) ? "GET" : "POST"; 115 message += "\ 116Arguments: "; 117 message += server.args(); 118 message += "\ 119"; 120 121 for (uint8_t i = 0; i < server.args(); i++) { 122 message += " " + server.argName(i) + ": " + server.arg(i) + "\ 123"; 124 } 125 126 server.send(404, "text/plain", message); 127}//end of handleNotFound() 128 129void setup(void) { 130// initialize the pwr and dir pins as outputs: 131 pinMode(pwrA,OUTPUT); 132 pinMode(dir,OUTPUT); 133 pinMode(signalPin,OUTPUT); 134 135// configure LED PWM functionalitites 136// ledcSetup(pwmChannel, freq, resolution); 137 138// attach the channel to the GPIO to be controlled 139// ledcAttachPin(pwrA, pwmChannel); 140 141//initialize the serial monitor 142 Serial.begin(115200); 143 Serial.println("Window Blinds Control"); 144 145 WiFi.mode(WIFI_STA); 146 WiFi.begin(ssid, password); 147 Serial.println(""); 148 149// Wait for connection 150 while (WiFi.status() != WL_CONNECTED) { 151 delay(500); 152 Serial.print("."); 153 } 154 155 Serial.println(""); 156 Serial.print("Connected to "); 157 Serial.println(ssid); 158 Serial.print("IP address: http://"); 159 Serial.println(WiFi.localIP()); 160 161//multicast DNS 162 if (MDNS.begin("WindowBlinds")) { 163 Serial.println("MDNS responder started"); 164 Serial.println("access via http://WindowBlinds"); 165 } 166 167 server.on("/", handleRoot); 168 server.on("/motor", HTTP_GET, motorControl); 169 server.onNotFound(handleNotFound); 170 server.begin(); 171 Serial.println("HTTP server started"); 172 173}//end of setup 174 175void loop(void) { 176 server.handleClient(); 177if(dirStatus ==1){ 178 digitalWrite(signalPin, HIGH); 179 delay(15); 180 digitalWrite(dir,LOW); // set DIR pin HIGH or LOW 181 digitalWrite(pwrA,HIGH); 182 //Serial.println("Motor Turning CCW"); 183// ledcWrite(pwmChannel, dutyCycle); 184// dutyCycle = startupDC; 185// delay(5); 186// dutyCycle = operatingDC; 187 188 }else if(dirStatus ==2){ 189 digitalWrite(signalPin, HIGH); 190 delay(15); 191 digitalWrite(dir,HIGH); 192 digitalWrite(pwrA,HIGH); 193 //Serial.println("Motor Turning CW"); 194 195// dutyCycle = startupDC; 196// delay(5); 197// dutyCycle = operatingDC; 198// ledcWrite(pwmChannel, dutyCycle); 199 200 }else{ 201 digitalWrite(pwrA,LOW); 202 digitalWrite(signalPin, LOW); 203 //Serial.println("Motor Off"); 204// ledcWrite(pwmChannel, dutyCycle); 205// dutyCycle = 0; 206 } 207 208 delay(1); 209}//end of loop 210 211void motorControl() { 212 213 214 if(server.arg(argId[0]) == "on") 215 { 216 dirStatus = 1;// CCW 217 218 }else if(server.arg(argId[0]) == "off"){ 219 dirStatus = 3; // motor OFF 220 221 }else if(server.arg(argId[1]) == "on"){ 222 dirStatus = 2; // CW 223 224 }else if(server.arg(argId[1]) == "off"){ 225 dirStatus = 3; // motor OFF 226 227 } 228 229 handleRoot(); 230}
Downloadable files
Circuit Diagram
Pin D5: Motor Driver On/Off Pin D12: Direction For Motor Driver Pin D14: On/Off Motor Control
Circuit Diagram
Circuit Diagram
Pin D5: Motor Driver On/Off Pin D12: Direction For Motor Driver Pin D14: On/Off Motor Control
Circuit Diagram
Documentation
DC Motor Clamp
To clamp around the DC Motor.
DC Motor Clamp
Motor Coupler
This is for connecting the DC motor Shaft to the 1/4" hexagonal shaft that runs through my blinds.
Motor Coupler
DC Motor Clamp
To clamp around the DC Motor.
DC Motor Clamp
Comments
Only logged in users can leave comments