One Touch Auto Roll Up Window Module DIY
Universal car auto roll-up window unit
Components and supplies
5 mm LED: Red
Optocoupler, Transistor Output
Through Hole Resistor, 120 ohm
1N4007 – High Voltage, High Current Rated Diode
1N5819 – 1A Schottky Barrier Rectifier
Capacitor 100 µF
General Purpose Transistor NPN
ATmega328
Capacitor 22 pF
Capacitor 10 µF
Arduino 101
Signal Relay, 5 VDC
Resistor 1k ohm
SparkFun Low Current Sensor Breakout - ACS712
General Purpose Transistor PNP
16 MHz Crystal
Ceramic Disc Capacitor, 0.1 µF
Linear Regulator (7805)
Tools and machines
10 Pc. Jumper Wire Kit, 5 cm Long
Solder Wire, Lead Free
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Project description
Code
Full code
arduino
Upload with Arduino software
1 2 /*PROGRAMME : CAR WINDOW AUTO RALL UP 3PROGRAMMED BY : 4 SetNfix 5WEBSITE : HTTP://WWW.SetNfix.COM 6Ownner : BMIAK Basnayaka 7****************************************************************** 8THIS 9 PROGRAMME IS FOR THE VEHICLES WITH FOLLOWING SETTINGS 101.CAR DOOR LIGHT ON/OFF 11 BY NEGATIVE 122.CAR HORN NEGATIVE 133.POWER WINDOW SYSTEM 14AUTO RALL UP WILL 15 WORK WHEN 161.THE CAR IS OFF, THE DOORS ARE CLOSED THEN SECURITY KEY PRESS LOCK, 17 THE FRONT 18TWO WINDOWS WILL BE SHUT AUTOMATICALLY. 192.THE CAR IS STARTED AND 20 IF THE AUTO SWITCH ON, IF YOU PRESS WINDOW UP 21ONCE THE DRIVER SIDE WINDOW WILL 22 GO UP AUTOMATICALLY*/ 23 24int UpSwitch = 0; 25int DwnSwitch = 0; 26int UpSwitch_Pin 27 = 11; 28int DwnSwitch_Pin = 12; 29 30int RMotorUp = 0; 31int RMotorDwn = 0; 32int 33 LMotorUp = 0; 34int RMotorUp_Pin = 10; 35int RMotorDwn_Pin = 9; 36int LMotorUp_Pin 37 = 8; 38 39 40int CarDoor =0; 41int Sensor = 0; 42int Acc = 0; 43int Btt = 44 0; 45int CarDoor_Pin =7; 46int Acc_Pin = 6; 47int Sensor_Pin = 5; 48 49int 50 Btt_Pin = 4; 51 52int CarHorn=0; 53int Reset = 0; 54int Reset_Pin = 3; 55int 56 CarHorn_Pin=A0; // To car horn 57 58 59int LED = 13; 60 61int DataUpR = 0; 62int 63 DataDwnR = 0; 64int DataUpL = 0; 65int DataUpR_Pin = A1; // To control the unit 66 using external commands 67//int DataDwnR_Pin = A1; 68//int DataUpL_Pin = A2; 69 70int 71 Active = 0; 72int Cancel = 0; 73int Window = 0; // 74int Interrupt = 0; 75float 76 OldMillis; 77float NewMillis; 78float Balancemillis; 79int Timmer = 6000; // 80 Average time to close/Open a window (6s) 81 82int x = 0; //if the door is locked 83 by key, value will be = 1. 84int y; 85 86long a = 0;// time push and hold the 87 button. 88int aUp = 0;// window up pressed 89int aDwn = 0;//window down pressed 90int 91 Clicked = 0;// button was pressed when =1 92 93//Current sensor Unit 94int CrntPin 95 = A2; 96float Anval = 0.0; 97float Vlt = 0.0; 98float Dflt = 66; // Default value 99 of 30A current sensor 100float Amps = 0.0; 101int Svolt = 2500; // Default voltage 102 of the sensor 2.5v 103int Limit = 6; // This is by amps (10 A) 104int limiton = 105 7 ; //limit for normal operation 106int Motor = 0; 107int ux = 0; 108int uy = 0; 109 110 111//Roll 112 uo timing 113 114int upx = 0; 115int upy = 0; 116 117 118 119void setup() { 120 121 Serial.begin(9600); 122 123pinMode(UpSwitch_Pin,INPUT); 124pinMode(DwnSwitch_Pin,INPUT); 125pinMode(RMotorUp_Pin,OUTPUT); 126pinMode(RMotorDwn_Pin,OUTPUT); 127pinMode(LMotorUp_Pin,OUTPUT); 128pinMode(CarDoor_Pin,INPUT); 129pinMode(Sensor_Pin,INPUT); 130pinMode(Acc_Pin,INPUT); 131pinMode(Btt_Pin,INPUT); 132pinMode(CarHorn_Pin,OUTPUT); 133pinMode(Reset_Pin,OUTPUT); 134pinMode(DataUpR_Pin,INPUT); 135pinMode(CrntPin,INPUT); 136pinMode(LED,OUTPUT); 137 138 //**************************************************************** 139CarDoor =digitalRead(CarDoor_Pin); 140Sensor=digitalRead(Sensor_Pin); 141Acc 142 =digitalRead(Acc_Pin); 143Btt =digitalRead(Btt_Pin); 144 145 146 147//------------------------------------------------------------------- 148//------------CHECK 149 THAT THE CAR LOCKED BY REMOTE KEY OR DOOR-------- 150//------------------------------------------------------------------- 151/* 152 IF THE CAR IS LOCKED BY REMOTE KEY, THEN SECURITY LED START TO BLINK 153 * BUT 154 IT IS LOCKED BY DOOR LOCK, NOTHING LIGHT 155 */ 156 157int cnt = 1; 158 159do{ 160 161 Sensor = digitalRead(Sensor_Pin); 162 digitalWrite(LED,HIGH); 163 delay(30); 164 165 cnt = cnt +1; 166 if (Sensor ==1){x = 1;cnt = 120;Serial.print("KEY LOCKED");} 167 168 digitalWrite(LED,LOW); 169}while (cnt < 100); 170 171//------------------------------------------------------------------ 172// 173 If the door is locked by door, reset the unit 174//------------------------------------------------------------------ 175if 176 (x == 0){//If the door is locked not by remote key 177digitalWrite(Reset_Pin,HIGH); 178 // Activate Reset relay 179delay(500); 180digitalWrite(Reset_Pin,LOW); 181}//----------------------------------------------------------------- 182 183 184 185//**************************************************************** 186//================CAR 187 LOCK Shutter 188//**************************************************************** 189if 190 ((Acc ==0)&&(CarDoor ==1)&&(Btt==1)&&(x==1)){ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 191 192 Serial.println("Key lock Shutter 01"); 193 digitalWrite(LED,HIGH); 194 delay(1000); 195 196carhorn(); 197delay(2000); 198 digitalWrite(LED,LOW); 199 200do { 201CurrentSensor(); 202 203digitalWrite(LED,HIGH); 204delay(100); 205digitalWrite(RMotorUp_Pin,HIGH); 206 // roll up window 207Serial.print("UPR : "); 208Serial.println(upx); 209Serial.print("MOTOR 210 : "); 211Serial.println(Motor); 212 213digitalWrite(LED,LOW); 214delay(100); 215upx++; 216if 217 ((Motor == 0)&&(upy < 35)){ux = 0;} else { ux = 1;} 218}while(ux ==0); 219digitalWrite(RMotorUp_Pin,LOW); 220 // roll up window STOP! 221Serial.println("STEP 1"); 222delay(500); 223CurrentSensor(); 224 225delay(50); 226 227do { 228CurrentSensor(); 229digitalWrite(LED,HIGH); 230delay(100); 231digitalWrite(LMotorUp_Pin,HIGH); 232Serial.print("UPY 233 : "); 234Serial.println(upy); 235Serial.print("MOTOR : "); 236Serial.println(Motor); 237digitalWrite(LED,LOW); 238delay(100); 239upy++; 240 241if 242 ((Motor == 0)&&(upy < 35)){uy = 0;} else { uy = 1;} 243 244}while(uy == 0); 245digitalWrite(LMotorUp_Pin,LOW); 246delay(500); 247CurrentSensor(); 248 249delay(50); 250//---------------------------------------------------------------- 251digitalWrite(Reset_Pin,HIGH); 252delay(500); 253digitalWrite(Reset_Pin,LOW); 254 255}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 256 257digitalWrite(LED,HIGH); 258delay(500); 259digitalWrite(LED,LOW); 260} 261 //************** END VOID SETUP************************ 262 263 264 265void loop() 266 { 267 268UpSwitch = digitalRead(UpSwitch_Pin); 269DwnSwitch = digitalRead(DwnSwitch_Pin); 270CarDoor 271 =digitalRead(CarDoor_Pin); 272Sensor=digitalRead(Sensor_Pin); 273Acc =digitalRead(Acc_Pin); 274Btt 275 =digitalRead(Btt_Pin); 276 277 278CurrentSensor(); // GEt current sensor value 279delay(50); 280 281//------------------------------------------------------- 282//Reset 283 if key lock inside the car when engine is started 284//------------------------------------------------------- 285if 286 ((Acc==1)&&(Btt==1)){ 287 Serial.println("key lock inside the car when engine 288 is started"); 289 digitalWrite(Reset_Pin,HIGH); 290 delay(500); 291 digitalWrite(Reset_Pin,LOW); 292} 293//------------------------------------------------------- 294 295 296 297 298//Inturrupted 299 to the current process 300if ((Active == 1)&&(Interrupt == 0)){ 301if (digitalRead(UpSwitch_Pin)==1){Window 302 = 1;Interrupt=1;Serial.print("UpSwitch : "); 303Serial.println(digitalRead(UpSwitch_Pin));} 304 305if 306 (digitalRead(DwnSwitch_Pin)==1){Window = 2;Interrupt=1;Serial.print("DwnSwitch 307 : "); 308Serial.println(digitalRead(DwnSwitch_Pin));} 309 310 311} 312//Stop When 313 Interrupt 314if (Interrupt == 1){digitalWrite(RMotorUp_Pin,LOW); digitalWrite(RMotorDwn_Pin,LOW);Serial.println("STEP 315 05");Window = 0;Active =0; Balancemillis=0; OldMillis = 0;LedBlink();Serial.println("Interrupted");delay(2000);Interrupt 316 =0;} 317 318/*/testing---------------------------- 319if ((UpSwitch ==1)||(DwnSwitch 320 ==1)){ 321 if (UpSwitch ==1){aUp = 1; aDwn =0;} 322 if (DwnSwitch ==1){aUp = 0; 323 aDwn =1;} 324 Clicked = 1; //BUTTON PRESSED 325 delay(10); 326 a = a + 1; 327} 328 329//FIND 330 THE DURATION TO RELEASE THE BUTTON 331if (Clicked ==1){ 332 delay(10); 333 a = 334 a + 1; 335 336}*/ 337 338 339 340 341 342 343//----------------------------------------- 344//Auto 345 Up the window 346if ((UpSwitch ==1)||(DwnSwitch ==1)){ 347 delay(200); 348 Serial.print("TOUCHED"); 349if 350 ((Active == 0)&&(Interrupt == 0)){ 351if ((UpSwitch ==1)&&(digitalRead(UpSwitch_Pin)==0)){Window 352 = 1;Active=1; OldMillis = millis();} 353if ((DwnSwitch ==1)&&(digitalRead(DwnSwitch_Pin)==0)){Window 354 = 2;Active=1;OldMillis = millis();} 355} 356Serial.println(Window); 357} 358 359//----------------------------------------- 360 361//*********************************************************** 362//WINDOW 363 RALL UP 364//*********************************************************** 365if ((Window 366 == 1)&&(Active==1)&&(Interrupt == 0)&&(BalancemillisTimmer)||(Amps >limiton)){ 367 368 digitalWrite(RMotorUp_Pin,LOW); 369 digitalWrite(RMotorDwn_Pin,LOW); 370 Serial.println("STEP 371 01"); 372 digitalWrite(LED,LOW); 373Active=0; Balancemillis=0; OldMillis = 374 0;Window = 0;Interrupt =0;Serial.println("WINDOW STOP");delay(500);} 375} 376//------------------------------------------------------------ 377 378 379//--------------------------------------------------------------- 380// 381 External Conrol wire 382//--------------------------------------------------------------- 383DataUpR 384 = analogRead(DataUpR_Pin); 385Serial.print("DataUpR : "); 386Serial.println(DataUpR); 387if 388 ((DataUpR>200)&&(DataUpR400)&&(DataUpR300)&&(DataUpR200)&&(DataUpR Limit){Motor 389 = 1;} else {Motor = 0;} // value "0" is motor is rotating and "1" is blocked. 390Serial.print("AMPS 391 : "); 392Serial.println(Amps); 393 394//************************************************************************************** 395} 396
Full code
arduino
Upload with Arduino software
1 2 /*PROGRAMME : CAR WINDOW AUTO RALL UP 3PROGRAMMED BY : SetNfix 4WEBSITE : HTTP://WWW.SetNfix.COM 5Ownner : BMIAK Basnayaka 6****************************************************************** 7THIS PROGRAMME IS FOR THE VEHICLES WITH FOLLOWING SETTINGS 81.CAR DOOR LIGHT ON/OFF BY NEGATIVE 92.CAR HORN NEGATIVE 103.POWER WINDOW SYSTEM 11AUTO RALL UP WILL WORK WHEN 121.THE CAR IS OFF, THE DOORS ARE CLOSED THEN SECURITY KEY PRESS LOCK, THE FRONT 13TWO WINDOWS WILL BE SHUT AUTOMATICALLY. 142.THE CAR IS STARTED AND IF THE AUTO SWITCH ON, IF YOU PRESS WINDOW UP 15ONCE THE DRIVER SIDE WINDOW WILL GO UP AUTOMATICALLY*/ 16 17int UpSwitch = 0; 18int DwnSwitch = 0; 19int UpSwitch_Pin = 11; 20int DwnSwitch_Pin = 12; 21 22int RMotorUp = 0; 23int RMotorDwn = 0; 24int LMotorUp = 0; 25int RMotorUp_Pin = 10; 26int RMotorDwn_Pin = 9; 27int LMotorUp_Pin = 8; 28 29 30int CarDoor =0; 31int Sensor = 0; 32int Acc = 0; 33int Btt = 0; 34int CarDoor_Pin =7; 35int Acc_Pin = 6; 36int Sensor_Pin = 5; 37 38int Btt_Pin = 4; 39 40int CarHorn=0; 41int Reset = 0; 42int Reset_Pin = 3; 43int CarHorn_Pin=A0; // To car horn 44 45 46int LED = 13; 47 48int DataUpR = 0; 49int DataDwnR = 0; 50int DataUpL = 0; 51int DataUpR_Pin = A1; // To control the unit using external commands 52//int DataDwnR_Pin = A1; 53//int DataUpL_Pin = A2; 54 55int Active = 0; 56int Cancel = 0; 57int Window = 0; // 58int Interrupt = 0; 59float OldMillis; 60float NewMillis; 61float Balancemillis; 62int Timmer = 6000; // Average time to close/Open a window (6s) 63 64int x = 0; //if the door is locked by key, value will be = 1. 65int y; 66 67long a = 0;// time push and hold the button. 68int aUp = 0;// window up pressed 69int aDwn = 0;//window down pressed 70int Clicked = 0;// button was pressed when =1 71 72//Current sensor Unit 73int CrntPin = A2; 74float Anval = 0.0; 75float Vlt = 0.0; 76float Dflt = 66; // Default value of 30A current sensor 77float Amps = 0.0; 78int Svolt = 2500; // Default voltage of the sensor 2.5v 79int Limit = 6; // This is by amps (10 A) 80int limiton = 7 ; //limit for normal operation 81int Motor = 0; 82int ux = 0; 83int uy = 0; 84 85 86//Roll uo timing 87 88int upx = 0; 89int upy = 0; 90 91 92 93void setup() { 94 Serial.begin(9600); 95 96pinMode(UpSwitch_Pin,INPUT); 97pinMode(DwnSwitch_Pin,INPUT); 98pinMode(RMotorUp_Pin,OUTPUT); 99pinMode(RMotorDwn_Pin,OUTPUT); 100pinMode(LMotorUp_Pin,OUTPUT); 101pinMode(CarDoor_Pin,INPUT); 102pinMode(Sensor_Pin,INPUT); 103pinMode(Acc_Pin,INPUT); 104pinMode(Btt_Pin,INPUT); 105pinMode(CarHorn_Pin,OUTPUT); 106pinMode(Reset_Pin,OUTPUT); 107pinMode(DataUpR_Pin,INPUT); 108pinMode(CrntPin,INPUT); 109pinMode(LED,OUTPUT); 110 //**************************************************************** 111CarDoor =digitalRead(CarDoor_Pin); 112Sensor=digitalRead(Sensor_Pin); 113Acc =digitalRead(Acc_Pin); 114Btt =digitalRead(Btt_Pin); 115 116 117 118//------------------------------------------------------------------- 119//------------CHECK THAT THE CAR LOCKED BY REMOTE KEY OR DOOR-------- 120//------------------------------------------------------------------- 121/* IF THE CAR IS LOCKED BY REMOTE KEY, THEN SECURITY LED START TO BLINK 122 * BUT IT IS LOCKED BY DOOR LOCK, NOTHING LIGHT 123 */ 124 125int cnt = 1; 126 127do{ 128 Sensor = digitalRead(Sensor_Pin); 129 digitalWrite(LED,HIGH); 130 delay(30); 131 cnt = cnt +1; 132 if (Sensor ==1){x = 1;cnt = 120;Serial.print("KEY LOCKED");} 133 digitalWrite(LED,LOW); 134}while (cnt < 100); 135 136//------------------------------------------------------------------ 137// If the door is locked by door, reset the unit 138//------------------------------------------------------------------ 139if (x == 0){//If the door is locked not by remote key 140digitalWrite(Reset_Pin,HIGH); // Activate Reset relay 141delay(500); 142digitalWrite(Reset_Pin,LOW); 143}//----------------------------------------------------------------- 144 145 146//**************************************************************** 147//================CAR LOCK Shutter 148//**************************************************************** 149if ((Acc ==0)&&(CarDoor ==1)&&(Btt==1)&&(x==1)){ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 150 Serial.println("Key lock Shutter 01"); 151 digitalWrite(LED,HIGH); 152 delay(1000); 153carhorn(); 154delay(2000); 155 digitalWrite(LED,LOW); 156 157do { 158CurrentSensor(); 159digitalWrite(LED,HIGH); 160delay(100); 161digitalWrite(RMotorUp_Pin,HIGH); // roll up window 162Serial.print("UPR : "); 163Serial.println(upx); 164Serial.print("MOTOR : "); 165Serial.println(Motor); 166 167digitalWrite(LED,LOW); 168delay(100); 169upx++; 170if ((Motor == 0)&&(upy < 35)){ux = 0;} else { ux = 1;} 171}while(ux ==0); 172digitalWrite(RMotorUp_Pin,LOW); // roll up window STOP! 173Serial.println("STEP 1"); 174delay(500); 175CurrentSensor(); 176delay(50); 177 178do { 179CurrentSensor(); 180digitalWrite(LED,HIGH); 181delay(100); 182digitalWrite(LMotorUp_Pin,HIGH); 183Serial.print("UPY : "); 184Serial.println(upy); 185Serial.print("MOTOR : "); 186Serial.println(Motor); 187digitalWrite(LED,LOW); 188delay(100); 189upy++; 190 191if ((Motor == 0)&&(upy < 35)){uy = 0;} else { uy = 1;} 192 193}while(uy == 0); 194digitalWrite(LMotorUp_Pin,LOW); 195delay(500); 196CurrentSensor(); 197delay(50); 198//---------------------------------------------------------------- 199digitalWrite(Reset_Pin,HIGH); 200delay(500); 201digitalWrite(Reset_Pin,LOW); 202 203}//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 204 205digitalWrite(LED,HIGH); 206delay(500); 207digitalWrite(LED,LOW); 208} //************** END VOID SETUP************************ 209 210 211 212void loop() { 213 214UpSwitch = digitalRead(UpSwitch_Pin); 215DwnSwitch = digitalRead(DwnSwitch_Pin); 216CarDoor =digitalRead(CarDoor_Pin); 217Sensor=digitalRead(Sensor_Pin); 218Acc =digitalRead(Acc_Pin); 219Btt =digitalRead(Btt_Pin); 220 221 222CurrentSensor(); // GEt current sensor value 223delay(50); 224 225//------------------------------------------------------- 226//Reset if key lock inside the car when engine is started 227//------------------------------------------------------- 228if ((Acc==1)&&(Btt==1)){ 229 Serial.println("key lock inside the car when engine is started"); 230 digitalWrite(Reset_Pin,HIGH); 231 delay(500); 232 digitalWrite(Reset_Pin,LOW); 233} 234//------------------------------------------------------- 235 236 237 238 239//Inturrupted to the current process 240if ((Active == 1)&&(Interrupt == 0)){ 241if (digitalRead(UpSwitch_Pin)==1){Window = 1;Interrupt=1;Serial.print("UpSwitch : "); 242Serial.println(digitalRead(UpSwitch_Pin));} 243 244if (digitalRead(DwnSwitch_Pin)==1){Window = 2;Interrupt=1;Serial.print("DwnSwitch : "); 245Serial.println(digitalRead(DwnSwitch_Pin));} 246 247 248} 249//Stop When Interrupt 250if (Interrupt == 1){digitalWrite(RMotorUp_Pin,LOW); digitalWrite(RMotorDwn_Pin,LOW);Serial.println("STEP 05");Window = 0;Active =0; Balancemillis=0; OldMillis = 0;LedBlink();Serial.println("Interrupted");delay(2000);Interrupt =0;} 251 252/*/testing---------------------------- 253if ((UpSwitch ==1)||(DwnSwitch ==1)){ 254 if (UpSwitch ==1){aUp = 1; aDwn =0;} 255 if (DwnSwitch ==1){aUp = 0; aDwn =1;} 256 Clicked = 1; //BUTTON PRESSED 257 delay(10); 258 a = a + 1; 259} 260 261//FIND THE DURATION TO RELEASE THE BUTTON 262if (Clicked ==1){ 263 delay(10); 264 a = a + 1; 265 266}*/ 267 268 269 270 271 272 273//----------------------------------------- 274//Auto Up the window 275if ((UpSwitch ==1)||(DwnSwitch ==1)){ 276 delay(200); 277 Serial.print("TOUCHED"); 278if ((Active == 0)&&(Interrupt == 0)){ 279if ((UpSwitch ==1)&&(digitalRead(UpSwitch_Pin)==0)){Window = 1;Active=1; OldMillis = millis();} 280if ((DwnSwitch ==1)&&(digitalRead(DwnSwitch_Pin)==0)){Window = 2;Active=1;OldMillis = millis();} 281} 282Serial.println(Window); 283} 284 285//----------------------------------------- 286 287//*********************************************************** 288//WINDOW RALL UP 289//*********************************************************** 290if ((Window == 1)&&(Active==1)&&(Interrupt == 0)&&(BalancemillisTimmer)||(Amps >limiton)){ 291 digitalWrite(RMotorUp_Pin,LOW); 292 digitalWrite(RMotorDwn_Pin,LOW); 293 Serial.println("STEP 01"); 294 digitalWrite(LED,LOW); 295Active=0; Balancemillis=0; OldMillis = 0;Window = 0;Interrupt =0;Serial.println("WINDOW STOP");delay(500);} 296} 297//------------------------------------------------------------ 298 299 300//--------------------------------------------------------------- 301// External Conrol wire 302//--------------------------------------------------------------- 303DataUpR = analogRead(DataUpR_Pin); 304Serial.print("DataUpR : "); 305Serial.println(DataUpR); 306if ((DataUpR>200)&&(DataUpR400)&&(DataUpR300)&&(DataUpR200)&&(DataUpR Limit){Motor = 1;} else {Motor = 0;} // value "0" is motor is rotating and "1" is blocked. 307Serial.print("AMPS : "); 308Serial.println(Amps); 309 310//************************************************************************************** 311} 312
Downloadable files
Plan
Plan

Comments
Only logged in users can leave comments