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.
- 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.
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.
Carefully remove the circuit board, flip it over and locate the pins of the switch.
Grab two male to male jumper wires and solder them to the clicker circuit board, one to each main pin of the 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.
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.
Install the top and screw it down. The finished product will look like the image below.
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.
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.
You now have something that looks like this.
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.
string command = string.Empty;
Console.WriteLine("May I press the button for you? Enter y or n");
if (command.ToUpper() == "Y")
Console.WriteLine("May I do it again? Enter y or n");
else if(command.ToUpper() == "N")
command = Console.ReadLine();
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).
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.
Type Y and enter. The program will press the button for you and ask for permission to do it again.
Type Y and enter, the program will press the button and ask for permission to do it again.
Type N and enter. The program will end.
You can now control your garage door from Raspberry Pi using .NET. Happy dance is optional.
Go to Part Four