Results 1 to 16 of 16

Thread: Garage Door Opener

Threaded View

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Garage Door Opener

    I have been working on several different types of Home Automation controllers using Arduino. One of them is a Garage Door controller. From my mobile phone I can open, close, or see the status of the garage door (see if its open or closed). In my garage I have an Arduino Uno with an Ethernet Shield attached to it. The garage door opener is connected to the Arduino via a SainSmart relay board.

    I discovered that the button that normally opens and closes the garage door was just a simple push button that briefly closes the circuit between the two wires running from the garage door opener. Using a Relay, I am able to simulate a button press electronically. I ran a wire pair from the connectors on the back of the garage door opener to a cabinet where the Arduino is located. I connected one wire to the common connector on the relay and the other to the normally open connector. Meaning the connection is always open until the Arduino tells the relay to close the circuit.

    Here is the Arduino (Mega Shown) with Ethernet Shield and Relay board

    Here is the Web Interface from my iPhone. Garage -> Door is the button to open the garage door.


    The Relay Board has 4 relays (In picture, closest relay was broken and removed). I used digital outputs 2, 3, 5, 6 on the Arduino to control the relays. Output 0 + 1 is used for serial communication and output 4 is used for the SD card on the EthernetShield. Additionally, the relay board requires Ground and +5V.

    When I press the Garage Door button on the web interface, it sends a HTTP request to the arduino with a URL similar to http://myip:port/command. For example: http://192.168.1.204:84/flashoutput5 will quickly close and open relay 5, just enough time for the garage door to recognize it as a button press. The garage door then opens.

    Here is the code for the garage door opener with comments.
    C Code:
    1. /*
    2. ARDUINOMATION RELAY CONTROL DEVICE
    3. LAST UPDATED: 06/08/2014
    4. */
    5.  
    6. #include <SPI.h>
    7. #include <Ethernet.h>
    8.  
    9. // VERSION NUMBER
    10. float VersionNumber = 2.0;
    11.  
    12. // DEVICE ID - MUST BE UNIQUE
    13. char deviceID[] = "100001";
    14.  
    15. // NETWORK SETTINGS
    16. int port = 84;
    17. char ipAddress[] = "192.168.1.241";
    18. char macaddress[] = "0xDE:0xAD:0xBE:0xEF:0xFE:0xEE";
    19. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; //physical mac address
    20. byte ip[] = { 192, 168, 1, 241 }; // DEVICE IP ADDRESS
    21. IPAddress controllerserver(192,168,1,204); // CONTROL SERVER IP ADDRESS
    22. EthernetServer server(port); //CONTROL SERVER PORT
    23. EthernetClient client;
    24.  
    25. // CONTROL SERVER PARAMETERS
    26. char updateurl1[] = "/projects/arduino/master_controller.php?command=checkin&deviceid=";
    27. char updateurl2[] = "&ip=";
    28. char updateurl3[] = "&mac=";
    29.  
    30. // DIGITAL OUTPUTS
    31. String readString;
    32. int output1 = 2;
    33. int output2 = 3;
    34. int output3 = 5;
    35. int output4 = 6;
    36. int output5 = 7;
    37. int output6 = 8;
    38. int output7 = 9;
    39.  
    40. // **************************** START CODE ****************************
    41.  
    42. void setup(){
    43.  
    44.   pinMode(output1, OUTPUT);
    45.   pinMode(output2, OUTPUT);
    46.   pinMode(output3, OUTPUT);
    47.   pinMode(output4, OUTPUT);
    48.   pinMode(output5, OUTPUT);
    49.   pinMode(output6, OUTPUT);
    50.   pinMode(output7, OUTPUT);
    51.  
    52.   // ETHERNET CONNECTION
    53.   Ethernet.begin(mac, ip); // , ip, gateway, subnet
    54.   server.begin();
    55.  
    56.   //PRINT TO SERIAL
    57.   Serial.begin(9600);
    58.   Serial.println(" Device Controller Loading..."); // so I can keep track of what is loaded
    59.   Serial.print("IP Address: ");
    60.   Serial.print(Ethernet.localIP());
    61.   Serial.print(":");
    62.   Serial.println(port);
    63.  
    64.   // CONNECT TO CONTROL SERVER
    65.   // Control server keeps track of all devices on the network
    66.   if (client.connect(controllerserver, 8888)) {
    67.     Serial.println("Connected to device server");
    68.    
    69.     Serial.println("Updating System");
    70.     client.print("GET ");
    71.     client.print(updateurl1);
    72.     client.print(deviceID);
    73.     client.print(updateurl2);
    74.     client.print(ipAddress);
    75.     client.print(updateurl3);
    76.     client.print(macaddress);
    77.     client.println(" HTTP/1.0");
    78.     client.println();
    79.     client.stop();
    80.     Serial.println("Server updated");
    81.   } else {
    82.     Serial.println("Connection to server failed.");
    83.    
    84.    
    85.     client.stop();
    86.     delay(1000);
    87.   }
    88.  
    89.   // EVERYTHING IS LOADED - WAIT FOR REQUESTS
    90.   Serial.println("Ready for requests...");
    91.   Serial.println();
    92. }
    93.  
    94. void loop(){
    95.   // Create a client connection
    96.   EthernetClient client = server.available();
    97.   if (client) {
    98.     while (client.connected()) {
    99.       if (client.available()) {
    100.         char c = client.read();
    101.  
    102.         //read char by char HTTP request
    103.         if (readString.length() < 100) {
    104.  
    105.           //store characters to string
    106.           readString += c;
    107.         }
    108.  
    109.         //if HTTP request has ended
    110.         if (c == '\n') {
    111.  
    112.           ///////////////
    113.           Serial.println("String:");
    114.           Serial.println(readString); //print to serial monitor for debuging
    115.  
    116.           client.println("HTTP/1.1 200 OK"); //send new page
    117.           client.println("Content-Type: text/html");
    118.           client.println();
    119.  
    120.           client.println("<HTML>");
    121.           client.println("<HEAD>");
    122.           client.println("<TITLE>Garage Control</TITLE>");
    123.           //client.println("<meta http-equiv="refresh" content="5">");
    124.           client.println("</HEAD>");
    125.           client.println("<BODY>");
    126.  
    127.           client.println("<H1>Garage Controller</H1>");
    128.          
    129.          
    130.           // READ SENSOR
    131.           int sensor = digitalRead(8);
    132.          
    133.           //  PRINT STATUS OF SENSOR
    134.           if (sensor == HIGH) {
    135.             client.println("Garage Open");
    136.           } else {
    137.             client.println("Garage Closed");
    138.           }
    139.          
    140.           client.println("<br><br><a href='/?flashoutput5'>Open/Close Garage</a>");
    141.          
    142.           client.println("<br><br><a href='/'>Refresh</a>");
    143.          
    144.           //client.println(sensor);
    145.           client.println("</BODY>");
    146.           client.println("</HTML>");
    147.  
    148.           delay(1);
    149.           //stopping client
    150.           client.stop();
    151.          
    152.           ///////////////////// control arduino pin
    153.          
    154.          
    155.           //******* OUTPUT 5 GARAGE *************
    156.           //This one is Special for Garage.
    157.  
    158.           if(readString.indexOf("flashoutput5") >0)
    159.           {
    160.              digitalWrite(output5, HIGH);
    161.              delay(500);
    162.              digitalWrite(output5, LOW);
    163.              Serial.println("Output 5 Flashed");
    164.           }          
    165.          
    166.           //******* OUTPUT 1 *************
    167.           if(readString.indexOf("highoutput1") >0)//checks for on
    168.           {
    169.            
    170.             digitalWrite(output1, HIGH);    
    171.             Serial.println("Output1 On");
    172.            
    173.           }
    174.           if(readString.indexOf("lowoutput1") >0)
    175.           {
    176.            
    177.             digitalWrite(output1, LOW);
    178.             Serial.println("Output1 Off");
    179.           }
    180.          
    181.           //******* OUTPUT 2 *************
    182.           if(readString.indexOf("highoutput2") >0)//checks for on
    183.           {
    184.            
    185.             digitalWrite(output2, HIGH);    
    186.             Serial.println("Output2 On");
    187.            
    188.           }
    189.           if(readString.indexOf("lowoutput2") >0)
    190.           {
    191.            
    192.             digitalWrite(output2, LOW);
    193.             Serial.println("Output2 Off");
    194.           }
    195.          
    196.           //******* OUTPUT 3 *************
    197.           if(readString.indexOf("highoutput3") >0)//checks for on
    198.           {
    199.            
    200.             digitalWrite(output3, HIGH);    
    201.             Serial.println("Output3 On");
    202.            
    203.           }
    204.           if(readString.indexOf("lowoutput3") >0)
    205.           {
    206.            
    207.             digitalWrite(output3, LOW);
    208.             Serial.println("Output3 Off");
    209.           }
    210.          
    211.           //******* OUTPUT 4 *************
    212.           if(readString.indexOf("highoutput4") >0)//checks for on
    213.           {
    214.            
    215.             digitalWrite(output4, HIGH);    
    216.             Serial.println("Output4 On");
    217.            
    218.           }
    219.           if(readString.indexOf("lowoutput4") >0)
    220.           {
    221.            
    222.             digitalWrite(output4, LOW);
    223.             Serial.println("Output4 Off");
    224.           }
    225.          
    226.           //******* OUTPUT 5 *************
    227.           if(readString.indexOf("highoutput5") >0)//checks for on
    228.           {
    229.            
    230.             digitalWrite(output5, HIGH);    
    231.             Serial.println("Output5 On");
    232.            
    233.           }
    234.           if(readString.indexOf("lowoutput5") >0)
    235.           {
    236.            
    237.             digitalWrite(output5, LOW);
    238.             Serial.println("Output5 Off");
    239.           }
    240.          
    241.           //******* OUTPUT 6 *************
    242.           if(readString.indexOf("highoutput6") >0)//checks for on
    243.           {
    244.            
    245.             digitalWrite(output6, HIGH);    
    246.             Serial.println("Output6 On");
    247.            
    248.           }
    249.           if(readString.indexOf("lowoutput6") >0)
    250.           {
    251.            
    252.             digitalWrite(output6, LOW);
    253.             Serial.println("Output6 Off");
    254.           }
    255.          
    256.           //******* OUTPUT 7 *************
    257.           if(readString.indexOf("highoutput7") >0)//checks for on
    258.           {
    259.            
    260.             digitalWrite(output7, HIGH);    
    261.             Serial.println("Output7 On");
    262.            
    263.           }
    264.           if(readString.indexOf("lowoutput7") >0)
    265.           {
    266.            
    267.             digitalWrite(output7, LOW);
    268.             Serial.println("Output7 Off");
    269.           }
    270.          
    271.           Serial.println("--------------------------------------------------");
    272.           //clearing string for next read
    273.           readString="";
    274.  
    275.         }
    276.       }
    277.     }
    278.   }
    279. }


    Here is what the serial console looks like when it is loaded. Notice that is says "Connection to server failed", thats because I do not have it connected to the network and it was not able to tell the Logic Server that its now online.

    Attachment 115163



    Edit:
    Here is part 2 of the project where I put the project in an enclosure.
    Last edited by dclamp; Aug 25th, 2018 at 12:27 AM.
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width