Wednesday, September 14, 2011

Monitor if Your Garage Door is Open with Netduino Plus

This blog post is going to document how to build an infrared sensor to monitor your garage door. It is part of a series to build an Android garage door app.

Supplies

  • Netduino plus (if you don't already have one). There are many places you can buy one and they seem to charge about the same $59.95.
  • Optical Detector / Phototransistor $1.13. (I bought mine from Sparkfun)
  • 200 ohm resistor (under a buck from any almost anywhere)
  • 5.6K ohm resistor (under a buck from any almost anywhere)
  • (Optional) (2) Screw Terminals 3.5mm Pitch $1.25 ea.
  • (Optional) PC Board $2.19 for two.
1. Build it

Follow this schematic to build your garage door sensor.

 This is what mine looks like (I used the PC board and terminals to make mine a little more tidy).


And here is the sensor installed in the garage. I placed it on the side facing the side plate. When the door is open the sensor detects an object close.


2. Code it

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).


Create a new project
Launch Visual Studio 2010 then create a new project (File > New Project > Netduino Plus Application). Let's name it NetduinoInfraredSensor.


Open Program.cs

  • Line 2 we define an AnalogInput and set it for PIN 0

  • Line 4 we set the range for reading the analog signal from 0 to 1024
  • Lines 6-10 are the main infinite loop. 
  • Line 8 we read the voltage through analog input 0 (which will return a value of 0 to 1024 which proportionally to the voltage coming from the infrared sensor we built and hooked up to analog input 0).
  • Line 9 we sleep the program for 1 second (so the program debug output is not flooding through the debug window). Be careful with loops that don't contain any Thread sleep commands. It is possible to for Visual Studio to have difficulty connecting and deploying if the loop is too tight. To be safe always throw in a sleep even if its just for a fraction of second.

//Set the analog pin to monitor Pin 0
AnalogInput garageSensor = new AnalogInput(Pins.GPIO_PIN_A0);
//Set sensor range
garageSensor.SetRange(0, 1024);
//Program loop
while (true)
{
    Debug.Print(garageSensor.Read().ToString());
    Thread.Sleep(1000);
}

3. Run it

First we need to change the project properties to deploy the program to the Netdiuno Plus and not an emulator (default). Right click on the project > properties > .Net Framework. Change the Transport to USB and make sure Netdiuno Plus is the device. (Your Netduino must attached to the computer via USB cable before making this change).
Now we can run the program in debug mode by pressing F5 or Debug > Start Debugging. Now hold an object about 3 inches from the infrared sensor and slowly move it towards the sensor. You will begin to see the reading drop from 1024.


Here is the complete code for the sensor.



To learn how to write the Android app that will control and monitor the garage door read the step by step blog post here. http://androidcodemonkey.blogspot.com/2011/10/android-garage-door-app.html

8 comments:

  1. Hi Greg, I enjoyed a lot your post. I was looking for a post like this for a long time, because of I have the necessity to be able to monitor my garage door. This project is perfect for me, I have an arduino (not netduino) idle and skills in programming but lack of skills in the electronic part. And this article seems so easy to follow and implement...but I have one doubt, I don't know where you placed the sensor.
    In the paragraph "And here is the sensor installed in the garage. I placed it on the side facing the side plate. When the door is open the sensor detects an object close." I don't understand the sentence "I placed it on the side facing the side plate." due to my english is not as good as I'd wish. Can you explain where you placed the sensor in a way I'm able to understand? for example adding a new photo to the existing one, but appearing the whole garage door and where you placed the netduino?

    Thanks in advance,

    Albert

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I'd like to modify your code to work for 2 garage doors, but I am an unfortunate newbie that has basically no experience with this. Is there a place you could recommend that I could get some base knowledge? Or better yet, write the code for me? Just kidding, but any help would be appreciated.

    It looks like I coud just repeat the code just changing the above code to PinX and garagesensor to garagesensor2

    ReplyDelete
  4. I liked very much, I'm just not getting the download Skydrive.

    ReplyDelete
  5. 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

    ReplyDelete
  6. 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
    consumers.
    http://wacsystem.com/

    ReplyDelete
  7. Your Oklahoma City Garage Door Repair Experts
    Seven days a week, our company offers garage door repair services in the areas of Oklahoma City and surrounding cities. Today, one of our specialists will come to you and get your home's garage door functioning like its brand new.

    Mitchell R. Clark
    1569 Harley Brook Lane
    Patton, PA 16668
    martinaaaamarketingg1984@gmail.com
    814-674-8592

    ReplyDelete
  8. I just want to mention I am very new to weblog and actually loved you're website. Almost certainly I’m likely to bookmark your blog . You amazingly come with beneficial posts. Thanks for sharing your web page.garage door repair winston salem

    ReplyDelete