Sep 24

Arduino Controlled Garage Door – Part 3

In my last 2 articles I put together a prototype for a garage door control that I could power on and off through a website I developed. I plugged everything in and let it sit on my desk connected to the network for about a week. Every once in a while I’d load up the webpage and click the buttons to make sure I heard the relays switch on then off.  I wanted to give it a chance to “burn in” and ensure it would work over a long period of time. Once I felt comfortable it was working as expected it was time to do the physical installation.

My hope is that this will be the first project in a series that will automate several functions in my house. Because of this concept I decided to place the Arduino in a centralized location in my house and run a cable to the garage that I could use for 5v power and I2C communication.

Materials

  • Power Supply
  • 1 Low voltage wall box
  • 1 Blank Wall Plate
  • 2 Buttons
  • Any cable with 4 or more wires (I used Cat5)
  • Pull up resistors
  • Heat shrink tubing

Buttons

I wanted to keep the look of this project neat so instead of reusing the old buttons that controlled my garage doors I decided to build my own. I cut a hole in the wall and installed a low voltage wall box mounted sideways. I used 2 concave arcade style buttons from Sparkfun for the physical buttons. To tie it all together I got a blank plastic wall plate and drilled a hole for each button.

Garage Door Button Plate

I secured the module to the top of the buttons and secured it with zip ties. I wanted to make sure that even if the relay module or the Arduino were unusable that I would still be able to open the garage doors so I wired the buttons in as manual overrides. In this configuration either the buttons or the relay can complete the circuit. I used heat shrink tubing to cover all the exposed copper.

Garage Door Button Wiring

Once everything was wired up I put the whole module into the wall and screwed the cover on. You can’t see it in the picture but when the module is powered up you can see the green light from the LED shining through the white plate.

Finished Garage Button Plate

Last Minute Tweak

Once it was all finished I plugged the other end of the cable into my Arduino and loaded up the website and… nothing. I pressed both buttons, neither worked. I figured I must have mixed up the I2C wires for SDA and SCL so I swapped them and still nothing. I have worked pretty extensively with I2C and I remembered that many people recommend pull up resistors on the SDA and SCL lines but in my experience it was never needed because the Arduino has integrated pull up resistors for these pins. I decided to try it anyway and added a pair of 4.6k resistors to the Arduino side of the I2C circuit and tested the web buttons again. This time it worked. It seems that the pull up resistors in the Arduino are better suited for short runs.

Next Steps

The next step in this process is for the Arduino to detect or show the status of the garage doors. This also allows for future expansion of the system by adding other I2C devices. A temperature sensor would be an easy addition and may be a future project.

Aug 28

Arduino Controlled Garage Door – Part 2

In part 1 of this series I showed how I created an I2C relay module to open and close my garage doors. Now that I have the ability to do this, the next step is to make the user interface for this accessible from a laptop, smart phone, etc. To do this we will create a simple Arduino Ethernet based web page with a button for each door.

The libraries to run an Arduino Ethernet or Ethernet shield are included in the Arduino IDE. The sample sketches include the ability to tweet, telnet, and create a webpage. The example for a web server is fairly simple, however for projects that require more sophistication there is the Webduino library that adds the ability to use AJAX buttons, sliders, and login authentication on websites directly on an Arduino. Because this will eventually be a more complex system this is the method we’ll use in this project.

Materials

  • Arduino Ethernet or Ethernet shield (must be Wiznet-based)
  • relay control module
  • Webduino library

Installing Webduino

Before we can get started we need to install the Webduino library into the Arduino IDE.

  • Download the latest version from https://github.com/sirleech/Webduino/zipball/master
  • Create a “libraries” folder inside your Arduino Sketch folder
  • Extract the zip file to the libraries folder you just created.
  • Open Arduino program and paste the code below
  • Upload the below code to Arduino

The below code is a modified version of the buzzer sketch. It creates 2 buttons, one for each garage door. In this example the web interface can be reached at http://192.168.1.20/garage (this may need to be modified for your network).

// Garage Control Code
// Fork Robotics 2012
// Based on Webduino buzzer sketch

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include

//randomly generated MAC http://sqa.fyicenter.com/Online_Test_Tools/Test_MAC_Address_Generator.php
static uint8_t mac[] = { 0x7C, 0xD5, 0x93, 0xAE, 0xB2, 0x76 };
static uint8_t ip[] = { 192, 168, 1, 20 };

#define PREFIX "/garage"
WebServer webserver(PREFIX, 80);

int garageToggle=0;
int ATtinyAddress=0x26;

void garageCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);
      if (strcmp(name, "garage") == 0)
      {
        garageToggle = strtoul(value, NULL, 10);
      }
    } while (repeat);
    server.httpSeeOther(PREFIX);
    return;
  }

  server.httpSuccess();
  if (type == WebServer::GET)
  {
    /* store the HTML in program memory using the P macro */
    P(message) =
      "Webduino Garage Example"
""
 "</pre>
<h1>Pick a Door</h1>
<pre>
"
 "</pre>
<form action="/garage" method="POST">"
 "
<button name="garage" value="1">Left Door</button>

"
 "
<button name="garage" value="2">Right Door</button>

"
 "</form>
<pre>
";
    server.printP(message);
  }
}

void setup()
{
  Wire.begin();
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&garageCmd);
  webserver.begin();
}

void loop()
{
  webserver.processConnection();
  if (garageToggle > 0){
    RelaySwitch(ATtinyAddress,garageToggle);
    garageToggle=0;
  }
}

void RelaySwitch(byte device,byte data) {
  Wire.beginTransmission(device);
  Wire.write(data);
  Wire.endTransmission();
}

The Result

The result of this code is a simple webpage with 2 buttons. When a button is clicked it will send the appropriate I2C command to the module created in part 1.

Next steps

While the Webduino library makes great strides towards making the Arduino Webserver more useable it is still limited in what it can do. I just recently got my hands on a Raspberry Pi; it has I2C, integrated Ethernet, a real time OS and Apache. Eventually the main control mechanism could be a switched over to this platform but for the moment the next step is to install this into my house.

Aug 13

One Week on Mars with Curiosity

NASA’s Curiosity Rover has spent a week on Mars and while it has yet to even start its actual mission there this project has produced some of the most exciting and visceral moments out of the space program in recent memory.

For those of you who stayed up late to watch the Entry, Decent and Landing (EDL) you know it was an exciting night. Watching live as the JPL and the audience lived through the 7 Minutes of Terror we were all biting our nails waiting and waiting to hear back that Curiosity landed safe and sound. Thankfully the Mars Odyssey was able to get into position in time to relay the first picture of Mars from the newly landed rover.

The next day we were gifted with a picture of the MSL mid decent with its parachute deployed.

MSL Landing

And even a picture of the aftermath of the EDL phase. Showing all the individual components of the entry vehicle spread across the surface of Mars.

MSL Landing Components

After the landing happened NASA passed over the area to see how close they were to the projected landing zone. It cannot be overstated the precision with which the NASA team was able to land this rover.

After a quick OTA update (if you think updating your smartphone is nerve wracking imagine patching a $2.5 billion device with no way of un-bricking it). We were greeted with some color HD pictures of the surface of mars that makes is seem like it could be right from our backyard.

Closeup of Wheel

The latest is a stitched together Panorama

All of this has been so much fun to watch. NASA has done a great job of showcasing the amazing work being done. In the coming years robotic exploration is going to be the standard. While we wait for the resurgence of a manned space program the work done by NASA and the JPL during this project is truly inspirational.

Aug 02

Arduino Controlled Garage Door – Part 1

Robotics and automation is a lot of fun as a hobby, however it can also be a great tool to solve common problems. Being fairly new to Aurdino and robotics, one area that seems within reach as a beginner’s project is home automation. I recognize that I’m not going to wake up one morning and be ready to deploy a system like SARAH from Eureka, but taking baby steps towards that goal seems like the best way to gain valuable experience and learn the challenges associated with such a system. The ice breaker project I’ve decided to use as a kickoff is a control mechanism for my 2 garage doors.

Current setup

The current setup I have in my garage is 2 Craftsman garage door openers. They are controlled through a set of wireless remote controls as well as a button wired directly to the units that allows the doors to be opened and closed from inside the garage.

garage door openergarage door buttongarage door remote

I want to leave the wireless modules alone, so I’ll be connecting to the wired connection for this project. On some initial testing I discovered that the 2 wire cable connected to the button on the wall is a 25v/2mA powered connection. When the button is pressed it connects the 2 contacts and the door opens, closes or stops. The relays I have are capable of handling 30v at 3A so this was a great fit.

Adding functionality

The main purpose of this project is to develop a system to detect if the garage doors are opened or closed (a problem my wife and I often encounter after leaving the house – did we remember to close the door?) and to be able to open or close the doors from anywhere, perhaps through an app on our smart phones.

This is really a 3 part problem

  1. Create a module that can open and close the doors
  2. Setup Arduino Ethernet to control the module remotely
  3. Develop a way to detect if a garage door is open or closed

Garage Door Control Module

With that in mind my first step is to build a permanent version of the I2C relay circuit from the Relay over I2C article. This modified version will need connect the door opener button circuit. The existing button will stay in place as a manual override (just in case the Arduino based system is not working).

The materials I used are:

Here is what the module looks like:

Relay Control Module - TopRelay Control Module - Botton

As a side note this is the last time I’ll try to solder a board like this, I’m going to have to test out the laser printer method to create a PCB next time.

This is a modified version of the code used in the relay article. When the module received a “1” or “2” over I2C it will switch on the appropriate relay then turn it off.  This essentially simulates a button press.

// Garage Door Control Module
// Fork Robotics 2012
//

#include "TinyWireS.h"                  // wrapper class for I2C slave routines

#define I2C_SLAVE_ADDR  0x26            // i2c slave address
#define RELAY1_PIN         3
#define RELAY2_PIN         4

void setup(){
  pinMode(RELAY1_PIN,OUTPUT);
  pinMode(RELAY2_PIN,OUTPUT);
  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
}

void loop(){
  byte byteRcvd = 0;
  if (TinyWireS.available()){           // got I2C input!
    byteRcvd = TinyWireS.receive();     // get the byte from master
      switch (byteRcvd) {
        case 0x01:
          Press(RELAY1_PIN,500);
        break;
        case 0x02:
          Press(RELAY2_PIN,500);
        break;
      }
  }
}

void Press(int RELAY,int ontime){ // poor man's display
    digitalWrite(RELAY,HIGH);
    delay (ontime);
    digitalWrite(RELAY,LOW);
    delay (ontime);
}

The code for the Arduino is the same as the one used in the Relay Control over I2C article.

Here is a video of the initial testing:

Next steps

At this point this module is still a very manual proposition. The module needs to be attached to an Arduino that in turn needs to be connected to a computer. The next step will be to create a web based interface to control this (and others in the future) module.