Geo-fence Garage Door Using Raspberry Pi, Azure, C#, and Windows Phone
Part Three

Part one we setup our Raspberry Pi, installed Mono, and ran our first C# program. Part two we connected a Relay to the Pi and used C# to turn the Relay On/Off.
In part three, we will connect the Relay to the garage door opener and control the door from our Raspberry Pi, using C#.
Here is what you will need for part three, in addition to the hardware/software you used in parts one and two.

Hardware :
  • Garage door remote control/clicker, preferably an old clicker with pin-through components instead of surface-mount.
  • Solder and soldering iron.
  • Small cross tip/phillips and flat tip screwdrivers.
  • Male to male jumper wires.

I am assuming the garage door opener you are using is a spare one, and you don’t care if it gets broken, burnt, abused and/or rendered useless.
Grab the garage door opener and locate the screws that are holding it together. Here is what my garage door opener looks like.
Clicker Before

Remove all the screws and pull the two sides apart. Locate the button you press when you want to open/close the garage door, here is what my clicker and the button location looks like.
Switch Top View

Carefully remove the circuit board, flip it over and locate the pins of the switch.
Switch Bottom View

Grab two male to male jumper wires and solder them to the clicker circuit board, one to each main pin of the switch.
Soldered Switch

Go to your garage door and touch the two wires together. The garage door should open or close, depending on the previous state of your garage door.
Test Switch

After confirming the garage door can be control by touching the wires together, put the circuit board back in the case and guide the wires out.
PCB Inside  the Case

Install the top and screw it down. The finished product will look like the image below.
Clicker Reassembled

Ok, the garage door is prepped and ready to receive the Pi. Make sure the Pi is turned off and the power cord is disconnected. You can shut down the Pi by running the command below.
sudo shutdown now

Wait for the green LED of the Pi to stop blinking (the red LED will stay on) and then unplug the power.
Go to relay you connected to the Pi in part one and identify the pins again. We will use the normally open pin and the center pin.
Relay Pins

Loosen up the center and normally open screws of the relay, insert one wire in the center location and screw it tight, insert the second wire in the normally open location and screw it tight.
Relay Out Pins

You now have something that looks like this.
Assembled View

Enough with the wires. Let’s go to Visual Studio and open the GaragePi.Net project you created in part two.
Replace the code inside the main method with the code below and build the project. The program will ask for permission to press the garage door opener button, if you answer with “y” it will energize it for half a second and ask for permission again. If your answer is “n”, the program will end.
 LibGpio.Gpio.SetupChannel(BroadcomPinNumber.TwentyThree, Direction.Output);
string command = string.Empty;
Console.WriteLine("May I press the button for you? Enter y or n");
while (true)
{
if (!string.IsNullOrEmpty(command))
{
if (command.ToUpper() == "Y")
{
LibGpio.Gpio.OutputValue(BroadcomPinNumber.TwentyThree, true);
System.Threading.Thread.Sleep(500);
LibGpio.Gpio.OutputValue(BroadcomPinNumber.TwentyThree, false);
Console.WriteLine("May I do it again? Enter y or n");

}
else if(command.ToUpper() == "N")
{
Console.WriteLine("Bye Bye");
break;
}


}

command = Console.ReadLine();
}

Code View

Power up your Raspberry Pi and wait for the Pi to get started. Start PuTTY and login to your Pi, start WinSCP and login to your Pi. Locate the Debug folder of the program you created and drag it to the pi folder of your Raspberry Pi (replacing the old one).
Copy Program

Go to PuTTY and run your program.
 sudo mono Debug/GaragePi.NET.exe

You program will run and ask for permission to press the button for you.
Running Program View One

Type Y and enter. The program will press the button for you and ask for permission to do it again.
Running Program View Two

Type Y and enter, the program will press the button and ask for permission to do it again.
Running Program View Three

Type N and enter. The program will end.
Program Ending

You can now control your garage door from Raspberry Pi using .NET. Happy dance is optional.
Go to Part Four
;