Arduino based garage door trigger

From EmbeddedSand

Jump to: navigation, search
No keys? Open your garage door using a website hosted on an Arduino microcontroller
Getting stuck out in the rain without house keys was the motivation for this project. An Arduino Etherten from Freetronics hosting a web-server is connected to the home wireless network. The web-server will trigger a relay to open the garage door when supplied with the password. The web-server isn't secure enough to attach to the public Internet, but a properly secured wireless network should offer sufficient protection. As an extra precaution, the Arduino will send the activation time out the serial port. Writing this data to a text file with MegunoLink provides a simple access log. Use at your own risk, of course!

Contents

Hardware

An EtherTen and a relay is all you need
The hardware is pretty simple:
Fully compatible with the the Arduino Uno, the Etherten includes an ethernet module based on the Wiznet chip used in the official Arduino shield. Of course you could use an Uno + Ethernet shield for this project but the Etherten costs less than buying the shield and Uno separately.
  • A relay
The relay works in parallel with the internal switch that activates the garage door opener. You'll need to follow the wiring for your own internal switch to see whether it is normally open or normally closed and configure the relay appropriately. Make sure the relay is rated appropriately.
Wire the relay to digital output number 7 on the Etherten. If you use a 5V relay that draws less than 40 mA, you can drive it directly from the Arduino output. Otherwise drive the relay with a transistor. Be sure to put a diode across the coil so the reverse EMF doesn't destroy the output driver on the Arduino board.
  • A custom 3D printed case designed in Blender and printed using a powder based 3D printing technology. If your interested the printer we used can be found here ZPrinter-150.

Arduino Code

The fantastic Webduino library is used to implement the garage door web-server on the Arduino. The current time for logging access is maintained by our Clock library. You can download the complete Garage door opener project. We'll look at the key sections below.

Entry Page

The first page users see when visiting the Arduino webserver is the index page where they are prompted for a password.

Enter a password to activate the garage door opener

This page is generated by the helloCmd function. It is registered with the webserver as part of the setup function:

  webserver.setDefaultCommand(&helloCmd); // when root page is accessed.
  webserver.addCommand("index.html", &helloCmd); // if index.html is accessed explicitly.

The helloCmd generates a simple web form that prompts the visitor for their password:

void helloCmd(WebServer &server, 
              WebServer::ConnectionType type, 
              char *url_tail, bool tail_complete)
{
  // Login screen cancels grace period
  s_bUnlocked = false;
 
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();
 
  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type == WebServer::HEAD)
    return;
 
  server.print("<html><head><title>Gateway</title></head><body>\n");
  switch (type)
    {
    case WebServer::GET:
        server.print("<form action='LetMeIn.html' method='POST'>");
        server.print("<p> Speak friend, and enter: </p>");
        server.print("<p> <input type='text' name='message' autocomplete='off' /> ");
        server.print("<input type='submit' name='send' value='Go'/> </p>");
 
        server.print("</form>");
        break;
    case WebServer::POST:
    default:
        server.print("<p>Unknown request</p>");
        break;
    }
 
    server.print("</body></html>");
}

Password Validation

The door can be activated again on the validation page
The form directs the user to a second page LetMeIn.html. This function is responsible for checking the user input and activating the door when an appropriate password is supplied. A grace period allows you to activate the door for a few minutes so it can be closed again without re-entering the password.


void validateCmd(WebServer &server, 
                 WebServer::ConnectionType type, 
                 char *url_tail, bool tail_complete)
{
  URLPARAM_RESULT rc;
  char name[NAMELEN];
  int  name_len;
  char value[VALUELEN];
  int value_len;
 
  /* this line sends the standard "we're all OK" headers back to the
     browser */
  server.httpSuccess();
 
  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type == WebServer::HEAD)
    return;
 
  if (type != WebServer::POST)
  { 
    server.print("<html><head><title>Gateway</title></head><body><p>Sorry, you are not welcome here.</p></body></html>");
    return;
  }
 
  // Validate the password, if one was supplied. An invalid 
  // password will cancel the lock period, but a missing 
  // password will not (otherwise we'd need a different page,
  // to handle that). 
  if (type == WebServer::POST)
  {
    while (server.readPOSTparam(name, NAMELEN, value, VALUELEN))
      if (strcmp(name, "message") == 0)
      { 
        // An invalid password will reset grace period
        s_bUnlocked = strcasecmp(value, "arduino") == 0 ||
          strcasecmp(value, "freetronics") == 0 || 
          strcasecmp(value, "megunolink") == 0;
        s_lLastUnlocked = millis();
      }
  }
 
  server.print("<html><head><title>Gateway</title></head><body>");
  if (s_bUnlocked)
  {
    server.print("<p>Welcome</p>");
 
    server.print("<form action='LetMeIn.html' method='POST'>");
    server.print("<input type='submit' name='send' value='Activate Door'/> </p>");
    server.print("</form>");
 
    server.print("<form action='index.html' method='GET'>");
    server.print("<input type='submit' name='Lock' value='Lock'/> </p>");
    server.print("</form>");
 
  } else
    server.print("<p>None shall pass!</p>");
 
  server.print("</body></html>");
 
  if (s_bUnlocked)
    ActivateDoor();
}

Activating the Door

The simplest part of all: activating the door. The relay is closed for a short time and the message written to the serial port. Capturing the serial message with MegunoLink provides a simple access log.

void ActivateDoor()
{
  Serial.write("Door activated ");
  g_Clock.WriteDateTime(&Serial);
  Serial.write('\n');
 
  digitalWrite(PIN_LED, HIGH);   // set the LED on
  digitalWrite(PIN_DOOR, HIGH);  // Open door.
  delay(600);              
  digitalWrite(PIN_LED, LOW);    // set the LED off
  digitalWrite(PIN_DOOR, LOW);  // Door will continue to open by itself.
}
An access log is recorded by MegunoLink.
Download MegunoLink

Version: 1.0.6
Updated: 3 October 2012
Size: 1.25 KB
Update History

If you find MegunoLink or this tutorial useful, please consider a donation to help support future development




Comments

Crs said ...

12:07, 4 August 2012 (MDT)

Nice work I wonder whhteer the Gameduino would work on the ChipKit boards (32-bit and faster than Arduino, but sorta compatible). I might have to check that out.

jordan retro 3 said ...

22:29, 1 November 2012 (MDT)

This web site is really a walk-through for all of the info you wanted about this and didn��t know who to ask. Glimpse here, and you��ll definitely discover it.

Personal tools