Sunday, September 18, 2011

Open & Close Garage Door with your Netduino plus

There are many ways to control your garage door with your Netduino. I decided to hack a spare garage door opener (since I wasn't using it) with an Optoisolator. My total cost $1.25. If I didn't have a spare garage door opener I would have run two wires off the Optoisolator pin 3 & 4 to the control panel in the garage. To send commands to the Netduino I am going to use HTTP commands.


  • Garage door opener
  • Optoisolator with Darlington Driver - 1 Channel. I purchased mine from Sparkfun.
  • 100 ohm resistor
  • 33 ohm resistor
  • Netduino plus
1. Build it

Here is the schematic for interfacing with the garage door opener. Excuse my unsophisticated schematic as I don't own any electrical CAD software.

  • Connect the Optoisolator pin 1 (Anode) to the Netduino plus digital pin 13
  • Connect the Optoisolator pin 2 (Cathode) to a ground pin on the Netduino plus with a 33 ohm resistor in-line.
  • Connect the Optoisolator pin 3 (Emitter) to one side of the garage door opener push-button with a 100 ohm resistor in-line.
  • Connect the Optoisolator pin 4 (Collector) to the other side of the garge door opener push-button.
Here is mine all built. You may notice mine has is wired for two garages although I only have one hooked up to the Netduino for this tutorial.

2. Code it

For the code, I am going to start with a stubbed out web server code from my previous blog post. To get more information on the basic code for a web server see my previous blog post.
If you have not installed all the necessary software see my previous blog post on how to setup your Netduino Plus development environment here (How to Setup Netduino Plus Development Environment).

After you download the code, open the project. Let's modify the code so we can send an HTTP request to the Netduino to activate the garage door opener. We are going to send a command to push the button on the garage door opener. We don't know if we are opening it or closing it since we are not yet monitoring the garage door status. We will combine this project to activate the garage door with the monitor code in a later post. Then we will be able to send the specific command "Open" or "Close".

Make the following changes to code
  • Line 6: Initialize digital port 13 to talk to the garage door opener
  • Lines 38-48: Parse the http request and confirm the user requested to door be activated with the command "HTTP:/192.XXX.X.XXX/activatedoor"
  • Line 49: Call our method to activate the garage door opener.
  • Lines 51-55: Send HTTP response.
  • Lines 56-62: send a HTTP response - command not recognized.
  • Lines 68-75: activate garage door method
    • Line 70: light the on-board LED for visual confirmation command is being sent to garage door opener
    • Line 71: Send voltage to the digital pin 13 to close the push-button on the garage door opener
    • Line 72: Wait for 1 second
    • Line 73: Turn off on-board LED
    • Line 74: Stop voltage to pin 13

public class WebServer : IDisposable
        private Socket socket = null;
        //open connection to onbaord led so we can blink it with every request
        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
        private OutputPort Garage2CarOpener = new OutputPort(Pins.GPIO_PIN_D13, false);

        public WebServer()
            //Initialize Socket class
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //Request and bind to an IP from DHCP server
            socket.Bind(new IPEndPoint(IPAddress.Any, 80));
            //Debug print our IP address
            //Start listen for web requests

        public void ListenForRequest()
            while (true)
                using (Socket clientSocket = socket.Accept())
                    //Get clients IP
                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;
                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;
                    //int byteCount = cSocket.Available;
                    int bytesReceived = clientSocket.Available;
                    if (bytesReceived > 0)
                        //Get request
                        byte[] buffer = new byte[bytesReceived];
                        int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);
                        string request = new string(Encoding.UTF8.GetChars(buffer));
                        string firstLine = request.Substring(0, request.IndexOf('\n')); //Example "GET /activatedoor HTTP/1.1"
                        string[] words = firstLine.Split(' ');  //Split line into words
                        string command = string.Empty;
                        if( words.Length > 2)
                            string method = words[0]; //First word should be GET
                            command = words[1].TrimStart('/'); //Second word is our command - remove the forward slash
                        switch (command.ToLower())
                            case "activatedoor":
                                //Compose a response
                                string response = "I just opened or closed the garage!";
                                string header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n";
                                clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);
                                clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);
                                //Did not recognize command
                                response = "Bad command";
                                header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n";
                                clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);
                                clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);
        private void ActivateGarageDoor()
            led.Write(true);                //Light on-board LED for visual cue
            Garage2CarOpener.Write(true);   //"Push" garage door button
            Thread.Sleep(1000);             //For 1 second
            led.Write(false);               //Turn off on-board LED
            Garage2CarOpener.Write(false);  //Turn off garage door button
        #region IDisposable Members
        public void Dispose()
            if (socket != null)
Remember to make sure you are deploying to your Netduino board and not the emulator. You do that by right-clicking on the Netduino project in Visual Studio > properties > .Net Framework. Set "Transport" to USB and confirm "Device" is set to "Netduino Plus".

3. Run it

  • Now run the code in debug mode. 
  • Open another a web browser and enter the IP address that the Netdiuno board displayed in the output window. For me its ""
  • You should see the LED on the Netduino plus light and the door should open or close.
Here is the complete code.

To learn how to write the Android app that will control and monitor the garage door read the step by step blog post here.


  1. I am a newbie in this, but why did you choose pin13 and not pin0? Also for mine I used wires coming from the the garage door button itself connected them to the 2222A transistor with a 5.6kohm resistor between the base and pin0 on the netduino, it seem to be working fine, but I am not sure if it'll damage netduino. Thanks

  2. You can use any pin. There is no reason for pin 13 so any pin including pin 0 is fine. Wiring the garage door button works as well. I used a controller because I had an extra one and I didn't have to run extra wire to the garage.

  3. Thanks a lot. Could you also tell me how to make the simplest switch to tell if the door is open without sensors? I was thinking about just using 3.3v with resistor and connect it to one of the inputs, if the pin sees voltage the door is closed. What would be the safest pin to use as well as resistor?

  4. @Vlad, I am not sure I fully understand how you want to detect the garage door is open. I created a sensor using a phototransistor. You could also use a physical switch that was closed with pressure when the door is open.

  5. That is what I was talking about - a physical switch. How should I connect it to netduino? What pins, resistors, etc. to use? Thanks

  6. Hi Greg. Excelent post :D Congratulations!!! I'm new to netduino microcontrollers and android programming but i already started to program my netduino plus and created a simple app using some of your code to simply control the blue led using my android cell phone. I'm using two commands "ledon" and "ledoff". Currently i'm dealing with some kind of delay that is retarding the reception of commands by netduino, i.e., only after some button pushes (3 or 4) the led wakes up / goes to sleep. Could you give me some hint about the possible cause of this problem? Adriano (

  7. Greg, Really great work.

    I have the new Netduino Plus 2 and it is running 4.2. Have setup the development platforms (micro framework and android) per the instructions. Used the code as is, except for two things. Changed the IP address and change the android platform to 3.2 (to support my Samsung Tab7.7). Loaded the code on the Netduino and Tab. The app appears on the Tab. When I tap the black box on the app, the progression circle spins. Using Ethereal I see the TCP traffic transmit from the Tab to the Netduino. Then I see Netduino response transmitted to the tab.

    The issue that I am having is that the "OPEN" graphic does not appear. I have built a few sensors and even tested them with a multimeter to see the sensor's output voltage in both hi and low states.

    So, I am assuming that the new MF4.2 on the Netduino is my problem and right now the porting kit isn't an option. Below is the code that I modified from your version to the 4.2. Please let me know if you think it is whacked and if so how would you write it? Thanks!

    //Set the analog pin to monitor Pin 0

    // OLD lanuage -> InputPort garageSensor = new InputPort.AnalogPort(Pins.GPIO_PIN_A0);

    AnalogInput garageSensor = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0);

    //Set sensor range

    // old 4.1 code -> garageSensor.SetRange(0, 1024);

    //Program loop
    while (false)

    1. The release of the 4.2.2 for the N+2 resolved the incompatibility issues that I was having with your original code.

      Pulling the "SecretLabs.NETMF.Hardware.AnalogInput" reference into the project is also key.

      I am far from complete on this project and a complete noob, so I still grin each time the garage door opens from a browser command.

  8. Using your code, how can i access my netduino from an outside network? I love what you did here and it works great on my project, but I don't want to have to be in my local network to use my netduino, i would like to use it while at work. I can't seem to find anything about it online though and i would like to just use your code with it.

  9. now i bought new netduino plus 2 board can any one plsssssssss tel me in which part the codings should be edited in netduino plus 2 and my android app with 2.3 version

  10. Noob question: how do you know what types resistors to use? Maybe dumb question: how do you know you even needed to use them?

  11. This is exactly what I was looking for as a base point for networking my whole house.

    Could you rehost the code on a different service than Skydrive? I'm attempting to download it but it will not let me because Skydrive is blocking it because it is unable to scan for viruses. Thank you.

  12. Greg,
    Is the netduino plus required for this? Or could one use the regular neduino or netduino mini?

  13. This comment has been removed by the author.

  14. I’m sure you will provide the more awesome blogs like these blogs that I’ve enjoyed a lot.

  15. I like your blog post. Keep on writing this type of great stuff. I'll make sure to follow up on your blog in the future. garage supplies.

  16. Hello

    One question.
    Some times when sending a parameter, i get a No data received page.
    I dont know why this happens so i dont have an ideia on how to fix it.

    Can you please help?

  17. Garage Door Repair Fontana 212-0325 Garage Door Installation, Broken Spring Replacement, Liftmaster and Genie Garage Door Openers & Remote, 24 Hours Garage Door company in Fontana

  18. How did you calculate these values for the resistors (the 100 ohm and 33 ohm ) ?

  19. I really like your blog it excellent. this blog is very helpful and informative. Thanks for sharing with us. supplies

  20. Introduction include modern day gadgets made us all engineering generally based entirely.
    There is not a single second once we will not be put into use any kind of type of engineering.
    Since the people include hardly time, therefore it is being a crying have to obtain every
    little thing done more rapidly than just before. At present, many individuals will not be
    holding funds; instead they are holding ATM minute card to get anything, which is why,
    they have come to be essential for every single company centre, no matter whether retail
    center or maybe take a trip firm, to be furnished with the device where funds can be taken
    from the actual minute card in combination with supplying expenses right away for the

  21. I think this is one of the most vital info of Garage Door Services for me. And I’m glad reading your article.

  22. This comment has been removed by the author.

  23. Hell yes thanks! garage door repair oxnard that's right, its great stuff for me

  24. There are many automatic mechanisms available that you can install in your garage door so that it closes and opens all by itself. You can consult any door specialist before installing any such system for your security doors or garage doors

  25. Thanks for great information, it's much helpful for the new professional.
    Garage Door Opener

  26. Garage Door and Garage Door Opener are a vital part of a modern home, A Garage Door is the single largest point of access to your home and can either enhance or diminish the value of your house.

    We are selling Garage Door Opener San Diego

  27. I will to work on this project.I actually want to see how my garage door will work with this programming.I was looking for such information from last few days. Thanks for the help.

  28. Are you find any garage door company in New York that provide these services and fix any issues in your garage door? garage door new york

  29. Thanks for sharing information.Your blog has always been a source of great tips.
    garage door company
    garage door service

  30. Good to see these helpful information here,Thanks lots for sharing them with us.
    garage doors ny
    garage door repair new york

  31. I read your post a d i really like your post. Thank you for sharing this post.
    Garage Door Repair NY
    garage door queens

  32. You can visit our showrooms at Fort Myers and Naples for all your carport entryway supplies.Clarks Garage Door & Gate Repair Riverside

  33. I would simply say to you all “awesome information” thanks for shearing with us

  34. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..

    Home Automation in Chennai
    smart home in Chennai
    Home security in Chennai
    Burglar alarm in Chennai
    Wifi Camera Chennai


  35. Wow, I really like your post because the information which you given in this blog is really extra ordinary.

    Austin Garage door repair

  36. To get more information on the basic code for a web server see my previous blog post.repairman

  37. Great and insightful article as always! Love your dedication to keeping up your house!

    If you are a housekeeper or housekeeper seeker, click here to view Housekeeping profiles.


  38. Wow, I really like your post because the information which you given in this blog is really extra ordinary.

    Austin Garage door repair

  39. I read your post and i really like it,Thanks for sharing useful information.
    garage door repair ny
    garage door installation long island

  40. Thank you for sharing your info. I really appreciate your efforts and I am waiting for your next post thank you once again.
    garage door opener westchester
    garage door service westchester

  41. Thanks for sharing this information. Your blog has always been a source of great tips and knowledge..

    garage door company new york
    garage door repair queens

  42. Thanks for Sharing it what I nice blog. Thank you for this sharing cheers up!

  43. We provide garage door services all through the south of Florida. Our service includes new garage doors installation and full repair.To check the details visit here Slide Easily

  44. Wow! I am fully impressed with this blog. The content of this post is very good. Thanks for sharing this post.

    Garage Door Services San Diego CA