6

CHAPTER

Image

Internet-Enabled, Arduino Powered Garage Door Opener

This chapter’s project will use the classic Arduino Uno development board with an Internet connection to provide a means to open an electrically powered garage door using a web browser, smartphone, or tablet. This project complements the use of a conventional radio control transmitter that is ordinarily used by most homeowners to remotely operate their garage doors. The Arduino door opener project will also make use of passwords to provide a strong security to the project.

 


Arduino Hardware

There are two hardware boards used in this project that I will separately discuss. The first is the Arduino Uno development board, which contains the microcontroller, and the second is the Ethernet Shield board, which connects the Uno board to an Ethernet network.

Arduino Uno Development Board

I will start with a brief overview of the Arduino Uno development board as I suspect most readers will already be familiar with it. If not, I would highly recommend reading Simon Monk’s excellent book on programming the Arduino boards, Programming Arduino: Getting Started with Sketches (McGraw-Hill Education, 2011). The word “Sketches” in the book title refers to the name the Arduino Project gives to programs written for Arduino development boards. I will discuss Sketches and many other related programming elements in the software section, but first I want to provide a brief tour of the Arduino hardware I will be using in this project.

The Arduino Uno board I used is shown in Figure 6-1. It is a rev 3 board, which is important to note as the pin sockets changed slightly between the board revisions.

Image


FIGURE 6-1 Arduino Uno rev 3 board

You can quickly identify rev 3 boards as the reset button was relocated from the center right-hand side on earlier versions to the upper left-hand side on rev 3 boards. The key specifications of the Uno board are specified in Table 6-1.

Image


TABLE 6-1 Arduino Uno Key Specifications

Don’t be concerned if you do not understand some of the specification abbreviations in the preceding table as I will explain them if they are needed for the project. I recommend looking at Atmel’s ATMEGA328P datasheet if you want to learn more about the detailed microprocessor specifications.

The single most important item to be mindful of regarding the Uno is that it is a microcontroller board and not a fully operational computer such as a Raspberry Pi. The significant difference is the Uno has no capability of hosting an operating system and cannot support any programming development using only the board. It must be connected to an external computer in order to be programmed. This does not make the Uno inferior to the Pi; it just is designed for a different approach for controlling embedded projects as compared to the Pi or the Beaglebone Black, which I discuss in upcoming chapters.

The open-source Arduino Project may be accessed at http://arduino.cc, the home page that contains many links to other pages that I know you will find very informative. In fact, I highly recommend that you stop reading this book for a while and go to this site and become acquainted with the Arduino concept as it will help you comprehend the software underlying the Arduino boards.

Ethernet Shield Board

Figure 6-2 shows the Ethernet Shield board that I used to establish a wired network connection between the Uno board and my local area network (LAN).

Image


FIGURE 6-2 Ethernet Shield board

The word “shield” in the board title simply refers to any one of a number of boards that are designed to plug directly on top of an Arduino microcontroller board such as the Uno. This one contains all the hardware required to establish a wired connection between the Uno and the LAN. This board is an older version of the Arduino Ethernet Shield and is based on the Wiznet W5100 chip. Figure 6-3 is the W5100 block diagram where you can see all the component parts that make up the built-in networking functions.

Image


FIGURE 6-3 W5100 block diagram

It is important to point out that while the W5100 chip does contain 16KB for memory buffers, it does not have any provision to store a program and is totally dependent upon the Uno for its programmed instructions in order to function. This means a separate Ethernet library must be loaded into the Uno’s flash memory in order for this shield to work properly. This approach generally holds true for most of the shield boards that are designed for use with the Arduino series of microcontrollers.

 


Arduino Uno Software

Truth be told, the section title is a bit misleading as the software I will be discussing covers a broad spectrum of the Arduino processors, not just the Uno. The key software that you need to program the Uno is an integrated development environment (IDE). This term should be familiar to you if you have read the early book chapters, as I used the Eclipse IDE to test Java programs that eventually ran on the Pi. The Uno IDE is not Eclipse, but it is a fully capable suite designed specifically to support the Arduino series of microcontroller boards. The IDE is available as a free download from the Arduino website that was provided earlier. The current IDE I will be using is 1.05, which will likely change in the future as improvements and upgrades are constantly being added by the very smart folks that run and maintain the Arduino Project. One nice feature is that the existing Arduino hardware will always run on the latest version of the IDE. No planned or unplanned obsolescence in this arena.

I would recommend that you power on your Uno and connect it to the computer running the IDE using a standard USB cable. Almost any “wall wart” power supply that uses a 2.1 mm outer barrel with a positive center connector will work. Remember that supply must be between 7 and 12VDC. I used a surplus power supply that provides 7.5V at 1.5A, which is more than ample for this project. Your computer should show a dialog that a driver is being installed after the Uno is plugged into the computer. Wait until the driver has been installed before starting the IDE.

Figure 6-4 is a screenshot of the Arduino v1.05 Start screen on a Windows laptop.

Image


FIGURE 6-4 Arduino IDE startup screen

The IDE automatically created a default sketch entitled sketch_may04a, which obviously contains the date that I ran the IDE program. You would normally use this blank sketch to create a program and then rename it to whatever suits your application. I will not be creating a sketch for this demonstration but will instead load a pre-stored example to demonstrate the classic LED blink program. There are many example programs automatically loaded into the computer during the IDE download. The program I opened was aptly named “blink” and was loaded by following this sequence: Select progressively File | Open | Examples | 01.Basics | Blink | Blink.

Figure 6-5 shows the loaded Blink program, which appears in its own window. Note that the original window for the sketch_may04a is still open in the background. This makes working on multiple programs very easy and convenient as all you need to do is select the desired window to resume development in that program.

Image


FIGURE 6-5 Blink code

I’m including the following Blink code in order to point out some key program parts for this introductory example. I will not normally list example program code, as it is easy to load and examine by yourself.

Image

This sketch has two methods: setup and loop. The setup method is always run first, followed by the loop method. The setup method provides the logical name “led” to the LED attached to the Uno’s pin 13. It also makes GPIO pin 13 an output.

The loop method is a forever loop that alternately turns on the LED for one second and then turns it off for one second. The digitalWrite method is the means by which the Uno controls pin 13 and, ultimately, the LED.

You should note that I didn’t mention any physical wiring was required for this demonstration as the Uno board already has a yellow LED permanently connected to pin 13. You can easily see this LED in Figure 6-1 as it is labeled with an “L” and is located just to the left and above the ARDUINO silkscreen name.

Selecting the right-facing arrow in the toolbar shown in Figure 6-5 will cause the program to be compiled and uploaded to the Uno. The Blink program will start immediately and continue indefinitely. You also might be a bit confused as the LED probably was already blinking before you uploaded the Blink program. That blinking was due to the default “heartbeat” that runs when no program was previously loaded. You can prove to yourself that the Blink program functions as expected by changing the delay time and observing the new blink rate matches whatever you entered. Simply enter new values for the delay time, say 2000ms, which will make the LED blink at a two-second rate. Compile and upload the changed program by pressing the right-facing arrow and watch the LED slowly blink every two seconds.

 


Testing the Ethernet Connection

In this section, I will demonstrate how to use the Ethernet Shield board with the Uno. The first step is to unplug the Uno’s power and USB cables. You never should attempt to attach or remove a shield board while the Uno is powered on as you might damage it. There is only one way that the shield pins will align with the Uno sockets. Carefully align the boards and firmly press them together. Figure 6-6 shows the Ethernet Shield attached to the Uno. Notice that the shield’s Ethernet connector is on the same side as the Uno’s power and USB sockets. The shield board is identical in size to the Uno board and should precisely cover it.

Image


FIGURE 6-6 Ethernet Shield attached to the Uno

Next, connect the Uno’s power and USB cables and also connect an Ethernet patch cable from the shield to your network’s router, hub, or switch, depending upon how you have configured your LAN. In my case, I connected to a 10/100 switch that is on my development workbench. You should immediately see four or five green LEDs light up on the shield indicating both power is being applied to the board and network activity is being detected via the patch cable. Figure 6-7 shows these active LEDs.

Image


FIGURE 6-7 Ethernet Shield active LEDs

If you do not see these LEDs light, immediately remove the power from the Uno and recheck how the shield and Uno are connected together. The most likely cause is that you have shifted the pins over one or even two spaces. Reposition the shield and reattach it to the Uno and you should be fine.

The Ethernet library, which you will need to access, is available from the IDE’s menu selections: Open | Examples | Ethernet menu.

All the current Ethernet library menu selections are detailed in Table 6-2.

Image


TABLE 6-2 The Ethernet Library

Open the DhcpAddressPrinter program and upload it into the Uno. After it uploads, select the spyglass icon near the upper-right corner of the IDE to open a serial terminal. You should see the Uno’s IP address displayed, as shown in Figure 6-8.

Image


FIGURE 6-8 IP address displayed

My network router assigned a 192.18.1.29 IP address to the Uno/Ethernet Shield. Your address would most certainly be different, however; please make note of it, as you will need it for the next program.

Next, load the program named WebServer, located in the Ethernet library, into the Uno. This program creates an active server that responds to HTTP requests at the IP address you determined with the previous program, and it returns the raw data from the Uno’s six analog input channels. WebServer uses the default HTTP port 80 so all you will have to do is enter the IP address on a remote, networked computer to see the results. However, you must make the following change in WebServer in order for it to work with the Uno’s preassigned IP address. Just type in your IP address where it is shown in the following code snippet from the WebServer sketch:

Image

Note that the IP numbers are separated (delimited) by commas and not periods as they normally would be. Incidentally, for those readers who have some background in network protocols, I would point out that a dummy mac address is being used for this and all the other Arduino Ethernet programs for this project. There are two reasons; first it doesn’t make any real-world difference what the actual mac address is as long as it is unique within the network. The second reason is that this older Ethernet Shield did not come with any sticker showing the actual firmware mac address assigned to the chip. I think this situation holds true for most of the old revision Ethernet Shields. I also understand newer versions do have a sticker on the board showing the actual address. If that’s the case, all you need to do is change the preset mac address to match the sticker address. Strangely, it should also work if you do not make the change but I believe it is good practice to always match the mac addresses if possible.

You should now open a browser on a networked computer and enter the Uno’s IP address, which in my case was 192.168.1.29. It is purely optional to enter the “http://” prefix as all modern browsers assume that is the default protocol to use. Figure 6-9 shows the output on MacBook Pro when I entered that address.

Image


FIGURE 6-9 The WebServer program on a remote browser

In the figure, you can see numbers ranging from a low of 282 to a high of 321. These represent the voltage “floating” on the six unconnected Uno analog input channels. Each channel is 10 bits in resolution and has a full-scale voltage input of 5.0V, which is the same as the Uno’s operating voltage. This means that a count of 1023 would represent a 5.0V input to a particular analog channel. Consequently, numbers averaging around a 300 count represent an approximate 1.47V level, which is determined by a simple proportional calculation:

Floating input voltage = 5.0 * (300 / 1023) = 1.47V

I soldered a jumper wire between ground and the analog input A0, as you can see in Figure 6-10.

Image


FIGURE 6-10 Jumper wire soldered between ground and analog input A0

My purpose in this effort was to further confirm the analog inputs were properly operating as I expected to see a 0V level when I next opened a browser to the WebServer page. My expectations were met as evidenced by Figure 6-11, which is the WebServer operating with the A0 input grounded.

Image


FIGURE 6-11 WebServer page with A0 grounded

Interestingly, you can see that not only does the A0 input have a 0 value but all the others are much lower than they were before when nothing was connected to the inputs. I can only infer that the inputs must have been at very high impedances, which are easily influenced by stray and nearby electrical fields. This also explains why, when I attempted to measure the open voltages on the analog inputs with a standard multimeter, I recorded much lower voltages than I had earlier calculated. My moderate impedance multimeter simply loaded down the high impedance inputs and showed voltages that were a result of the multimeter shunting the high impedance input. This is a good example of recognizing when your test equipment can have an unexplained effect upon the device under test (DUT). By the way, DUT is a standard electronics industry description for any electrical/electronic equipment being tested. This possible effect should always be kept in mind when testing any device.

At this point, I believe I have fairly well demonstrated how to connect an Uno to a network and have it perform useful tasks. It is now time to demonstrate a program that will accept a user input from a browser and cause the Uno to perform a desired operation. This program will show you the fundamental concepts involved in controlling a microprocessor over a networked connection. This program will also be the basis for the simplified garage door opener project. For this initial demonstration, I will only be lighting a LED when a checkbox is selected.

A simple hardware setup should be done before discussing the code. This simply entails connecting a LED’s anode to the Uno’s pin 2 and 220Ω resistor in series from the LED’s cathode to ground. Figure 6-12 shows the physical setup. Note that I soldered wires directly to the Ethernet Shields pins that directly connect with pin 2 and one of the ground pins. I also connected to the 5V supply, which I use in a later example.

Image


FIGURE 6-12 Physical LED test setup

Image

Image

Image

The code starts with two include statements that refer to all the dependencies necessary for this program to function. These are the SPI and basic Ethernet libraries.

A “dummy” mac address assignment follows, which you can use as is or else enter your own if known. The allocated Uno IP address is next. This must be entered to match the real IP address or the Ethernet connection cannot be established, as I discussed in an earlier example.

Next are the two standard Arduino methods named setup and loop that I have already mentioned. This particular setup method performs these initializations:

         •   Instantiates an Ethernet connection object

         •   Starts listening for client requests

         •   Starts the serial terminal at 9600 baud

         •   Sets the Uno GPIO pin 2 as an output

The loop method follows the setup and is much more extensive than the previous example’s loop method. The main reason for this is that the Uno does not use an operating system and consequently cannot set up and maintain a file system. This means that code that interacts with the remote browser (client) must be dynamically created each time the web server program is run. That’s the purpose of all the client.println statements contained within the loop method. This necessity should be compared with the way the Raspberry Pi web service functions. The Pi has a full Linux file system, which means the client code can be stored in a predefined directory from which clients can access it. Normally, it is in /etc/www directory and the client file is typically named index.htm or index.html for the HTTP protocol using port 80.

The first statement in the loop method is

EthernetClient client = server.available();

which will assign a non-null value to the client reference if an HTTP request is detected. Next, all the println statements will be executed, resulting in a web page being displayed on the client. The page displayed in Figure 6-13 appears when the client, again being a browser on a remote network computer, connects with the Uno’s web server program.

Image


FIGURE 6-13 The client after it has connected to the Uno’s web server program

The loop method will now loop, essentially waiting until the checkbox is selected, thus indicating that the user wants to turn on the connected LED. Checking the status of the checkbox is the function of the third method contained in the ProcessCheckbox method. This method takes a client argument and will either cause the LED to turn on if it was previously off or it will turn it off if it was previously on. The LED status, whether on or off, is stored in a program variable aptly named LED_status. If you carefully examined the ProcessCheckbox code, you should notice that the HTML call to the browser is exactly the same whether turning the LED on or off. This call simply toggles the checkmark in the checkbox and has nothing to do with actually turning the LED on or off. That’s all handled by the Uno in the web server program.

I ran the program and observed the LED turning on and off as expected when the checkbox was selected. I urge you to duplicate this demonstration as it should reaffirm what you know about how the Uno interacts with a web page to control a GPIO pin. The next step is to modify the LED program to control a relay that in turn controls a garage door.

 


Simplified Garage Door Opener

This portion of the project uses a modification of the previous LED demonstration where a relay is being controlled in lieu of a LED. The relay in turn switches the control power to a garage door opener. I will need to discuss my specific garage door opener system before proceeding with the actual project.

Actual Garage Door Opener

In this section I will show you how to build a basic, no-frills, remotely activated garage door controller. It is designed to operate with an existing residential style opener, which is shown in Figure 6-14.

Image


FIGURE 6-14 Garage door opener

I believe this opener is fairly typical of the garage door openers that are used for residential service. Either the press of a wall-mounted push button or the press of a button on a radio control transmitter that I have attached to the driver side visor activates it. The plan is simply to connect two wires in parallel to those wires, which are currently connected to the wall-mounted push button. These two new wires will be connected to a set of normally open relay contacts such that when the relay is energized by the Uno, which will then close the contacts and act the same as if the wall-mounted push button was pressed. The relay is needed because there is a 16VDC potential on the wires going to the push button, which far exceeds the Uno GPIO voltage specifications.

Figure 6-15 is a closeup of the connection terminals where I made the push button wires parallel. They are the two left-most wires shown in the figure. You may have to check your own opener’s connection diagram to determine which set of wires goes to the wall-mounted push button.

Image


FIGURE 6-15 Garage door opener connection terminals

If you refer to Figure 6-14, you can see these two new wires protruding from the left side of the opener. I used #20 gauge, solid-core, twisted bell wire for the new wires as that was exactly the same type that was installed going to the wall-mounted push button. I also briefly touched the newly installed wires together at the remote end where I was installing the Uno to confirm the door did operate as expected.

Modified LED Program to Open Garage Door

I modified the existing LED control program so that it will operate a transistor that will, in turn, control a relay, which has the garage door contact wires connected to a set of normally open contacts. Figure 6-16 is a schematic for this straightforward control circuit. Almost any common NPN switching transistor can be used to switch the relay. I used a 2N3904 in the circuit shown in the schematic.

Image


FIGURE 6-16 Relay switching circuit schematic

The relay switching circuit was wired on a solderless breadboard for convenience and easy modification if necessary. Both the breadboard and the Uno board were mounted in a plastic case near the garage door that was being controlled. Figure 6-17 shows the Uno and relay circuit mounted in the case.

Image


FIGURE 6-17 Uno and relay switcher mounted in plastic case

I ran both power and an Ethernet cable to the case along with the control wire pair connected to the garage door opener mechanism. You can easily see all the connections within the case, which was mounted on the garage wall.

The following is the modified LED control program. I didn’t change much except to operate the relay for one second every time the checkbox is selected. It doesn’t matter if there is a checkmark in the box; all you need do is select it to operate the door. This modified code is named Garage_Door_Open.ino and is available on this book’s companion website.

Image

Image

Image

Figure 6-18 shows the browser connected to the Uno web server for this door opener program.

Image


FIGURE 6-18 The browser display for the garage door opener

Selecting the checkbox either opened or closed the garage door depending upon its previous position.


NOTE This program in no way compromises the inherent safety features of the garage door opener. It will still stop and reverse its path if it encounters an obstacle when closing. In addition, the safety infrared beams at the door bottom still operate normally.

I also wanted to confirm that I could control the garage door using a smartphone. To do this, I simply entered the Uno’s IP address into the phone’s browser and subsequently connected to the web server. Figure 6-19 shows my smartphone’s browser display.

Image


FIGURE 6-19 Smartphone browser display connected to the garage door web server

The door operated precisely in the same manner as when I used the laptop’s browser. Of course, there is no extra security when operating in this manner other than the WPA passkey used in my network’s secure Wi-Fi connection. I would not be overly concerned as WPA should be sufficient to prevent unauthorized garage door operation. Definitely do not use this garage door software with an open Wi-Fi connection. You might as well hang your house keys next to your door if you choose to operate in this manner.

It is now time to take a slight deviation and introduce another IDE that will be used along with the Arduino IDE to create an enhanced garage door opener project.

 


Visual Studio 2012 IDE

It is both possible and useful to the Microsoft Visual Studio IDE to develop software for use with the Arduino board series. Using this IDE creates an opportunity to have access to a wide array of programming tools and libraries not found in the more limited Arduino libraries. You will need three software packages to develop with this software:

         •   Visual Studio 2012

         •   Arduino version 1.05

         •   MegunoLink Pro

The Microsoft Visual Studio 2012 Express edition will be used to develop the garage door software. This IDE, which will be referred to as simply VS2012, is available free of charge for non-commercial purposes at Microsoft’s download website: www.microsoft.com/en-us/download/details.aspx?id=34673.

This is a Windows program and it’s fairly large so it will take a while to download. Once it is installed, you will have to register online in order to obtain a free product key. Otherwise, the software “expires” after 30 days. Again, it is free as long as you certify that you are using it for personal, non-commercial use. The latest commercial version is expensive if bought directly from Microsoft. Figure 6-20 shows the VS2012 application without any projects loaded.

Image


FIGURE 6-20 Visual Studio 2012 IDE

The second software item is the Arduino IDE, which you have likely already downloaded. Just confirm that it is version 1.05 or later as earlier versions may have compatibility issues with the VS2012.

The last piece of software is named MegunoLink Pro and serves as a bridge between VS2012 and Arduino boards. It is impossible to upload any compiled VS2012 into an Arduino board without the use of the MegunoLink Pro software. There is a free seven-day trial period; you must purchase a license if you want to use it once the trial period has ended. The license fee for personal use is very reasonable and in my opinion well worth it for the significant functionality it provides in allowing the use of VS2012 with the Arduino boards as well as providing some very professional appearing graphical user interfaces (GUIs). MegunoLink Pro is available at www.megunolink.com.

Follow the website installation instructions to initially set up the MegunoLink Pro software. You should see the build-tool installation screen, as shown in Figure 6-21, when you select the gear icon on the MegunoLink Pro toolbar. Select Setup Arduino Build Tool for Visual Studio 2012 to install the software module within VS2012, which permits compiled programs to be uploaded into Arduino boards.

Image


FIGURE 6-21 MegunoLink Pro build-tool installation

You will need to enter the directory location for the arduino.exe binary executable. This may vary somewhat depending on the options you selected during the Arduino software installation. In my case, the location was simply C:\Program Files\Arduino, as you can see in the figure.

The current serial port connecting the Uno to the laptop must also be selected in the MegunoLink Pro Connection Manager Visualizer module. The Uno must be powered on and connected to the laptop via a USB cable in order to have the serial port recognized by the Connection Manager. Figure 6-22 shows my Connection Manager establishing a connection via COM46 at 9600 baud.

Image


FIGURE 6-22 Connection Manager Visualizer

Completing all of the preceding steps should now allow programs created in VS2012 to be compiled and uploaded to the Uno. I will next demonstrate how to create, compile, and upload an LED blink program to an Uno using VS2012 and MegunoLink Pro.

 


VS2012 LED Blink Program

Any program created with VS2012 must be part of a project. Create a project by following these three steps:

         1. Select File | New | Project | Templates | Visual C++ | Arduino Program.

         2. Provide a name for the new project. For this example, I chose “HelloArduino.” Use the default Location to create the project directory. The solution name will automatically be the same as the project name except for the file extension.

         3. Select OK.

Figure 6-23 shows the HelloArduino project screen with the source code for Program
.cpp shown in the main editor window. Program.cpp is the default name automatically provided by VS2012 as part of the VC++/Arduino template. It also contains the working code for a LED blink application that uses a LED connected to pin 13, as was the case for the first blinking program shown earlier in this chapter. I found that having sample code immediately in the editor does make initial program development easier as it is always better to start with modifications to a working program.

Image


FIGURE 6-23 Program Device Visualizer screen

Select Build | Build Solution to compile the source code. You can also simply press the F7 function key to do an immediate build. The compiled code that is first created uses the project name with a .elf file extension. This file type is a CodeWarrior ELF Debug Executable type and for my setup was automatically stored at C:\Users\Don\My Documents\Visual Studio 2012\Projects\HelloArduino\HelloArduino\bin\debug.

The MegunoLink Pro software automatically creates a companion hex file, which is the only type that can be uploaded into the Uno. The new hex file is also stored in the same directory as the original ELF file.

The actual hex file program upload is accomplished using the MegunoLink Pro Program Device Visualizer. You need to select the Program Device Visualizer from the Visualizer list and add in the location of the hex file and the serial port that was previously set up. Also ensure that the Arduino Uno is selected from the device drop-down menu. Then simply select the Program button. It should only take a few seconds to upload the newly created hex file into the Uno. A graphical progress bar shows what is currently happening in the process. Figure 6-23 shows this Program Device Visualizer screen.

Please note that after every program modification, you must recompile with VS2012 and upload using the MegunoLink Pro software. I can assure you that the process becomes almost second nature as you repeatedly use the software.

I did observe a blinking LED after I compiled and uploaded the binary to the Uno. Now, let’s move on to the enhanced garage door project.

 


Enhanced Garage Door Project

This section is called “Enhanced Garage Door Project” simply because I will be demonstrating some features beyond the basic functionality that was shown in the first version of this project. Password set and retrieve features will be shown that will allow the garage door to be operated from an open Wi-Fi connection without the risk of allowing unauthorized door activations. This revised project will make use of the VS2012 IDE as well as the MegunoLink Pro software. This project is the creation of Paul Martinsen and may be downloaded in zip form from GitHub at https://github.com/Megunolink/GarageDoorOpener.

Go to that website and select the Download zip button located in the lower-right corner of the opening page. The archive file is medium sized at about 5.6MB and must be extracted and stored somewhere on the laptop’s hard drive. I put all the extracted files into a sub-directory named GarageDoor located in the Downloads directory. There is a VS2012 solutions file in the archive, which you will use to re-create the original project on your laptop. This file is named Garage Door Opener.sln and is located in the GarageDoorOpener-master directory that was automatically created during the archive extraction. Incidentally, there is another file in that same directory named Garage door opener config interface.mix that you will also need later when setting up the password(s).

The Garage Door Opener project is easily created in VS2012 by following these steps:

         1. Select File | Open Project.

         2. Browse to the solution file wherever you extracted it using the Open Project dialog box.

         3. Select the solution file (Garage Door Opener.sln).

         4. Select OK.

Figure 6-24 shows this newly created project with the main application file program.cpp displayed in the source code editor window.

Image


FIGURE 6-24 VS2012 Garage Door Opener project

You should notice that Program.cpp contains only the same two methods, setup and loop, that you have seen in all of the other Arduino sketches. There are, however, a substantial number of additional files that provide additional functionality required to support web access as well as password protection. A list of these additional files is shown in the Solution Explorer in the VS2012 right-hand pane. I will not offer a detailed explanation of all these files as that would be well beyond the scope of this chapter and book. However, I do need to discuss one particular file, as some configuration changes must be made within this file in order to have a functional project. This file is Configuration.h and is classified as an include file. Files of this type contain supplemental information that is crucial to support application files, i.e., the ones ending with the .cpp filename extension. Simply double-click on the filename, which is shown in the include file list shown in Figure 6-25.

Image


FIGURE 6-25 Include file list

The source code will be displayed in the VS2012 main editor window. The altered Configuration.h source code is shown here for your information:

Image

I only changed the constant LOCAL_IP_ADDRESS to match the Uno’s assigned IP address as I have previously discussed. There is also an opportunity to assign the unique mac address if you know it; otherwise use the default address. You can also reset the maximum number of passwords possible, which is set at 10, and the maximum password length, which is set at 10 characters. I do not recommend changing either one of these parameters. The passwords are set using a special configuration application that I discuss shortly. They are permanently stored in the Uno’s eeprom memory to allow instantaneous access when the main garage door application is run. Save the altered Configuration.h file before proceeding with the compilation.

Next, select Build | Build Solution to create the hex file that will be uploaded into the Uno. The MegunoLink Pro Program Device Visualizer must next be used to upload the hex file into the Uno using the procedures that I discussed earlier.

The next step is to set at least one password in order to test this project. The passwords are set using the MegunoLink Pro configuration file I mentioned previously. All you need to do is double-click on the file Garage door opener config interface.mix, which is located in the same directory as the project solution file. Figure 6-26 shows the MegunoLink Pro screen that results when this file is run.

Image


FIGURE 6-26 MegunoLink Pro password configuration

You need first to select the initialize button, which prepares the Uno’s eeprom to accept new passwords. Next, select one of ten slots in which you will store the password being set. The first slot should be preselected. In addition, there is a default password “test” appearing in the Enter new password textbox. I used that as it was sufficient to proceed with the initial test. Select the Add/Update button to store the password into the selected slot. You can repeat this process until you have reached the ten-password limit. Note that you can always overwrite any password by simply assigning a new password to a given slot and selecting the Add/Update button. Do not select the Initialize button as it will likely erase any stored passwords that are in the eeprom.

 


Testing the Enhanced Garage Door Opener

The newly programmed Uno with the relay switching circuit was reinstalled in the same box that held the original project circuits. A browser on my MacBook Pro was set to the Uno’s IP address and I was greeted with the web page shown in Figure 6-27. Enter any of the stored passwords and you should see Figure 6-28, which is the next web page to activate the garage door.

Image


FIGURE 6-27 Initial web page for the enhanced garage door opener project

Image


FIGURE 6-28 Garage door activation web page

Selecting the Activate Door button either opened or closed the garage door as expected. I also accessed the door opener using my iPad, as you can see in Figure 6-29. It worked perfectly without any issues.

Image


FIGURE 6-29 iPad access to garage door opener

This concludes the garage door opener project, which hopefully showed you how you can effectively use the Arduino as a web-based appliance, in this case, a remotely activated garage door opener/closer.

 


Summary

I started this chapter with an overview of the Arduino Uno development board and explained key features that you should know when using it. I also discussed the Ethernet Shield board as that is the means by which the Uno connects to a network using the Ethernet.

The Arduino integrated development environment (IDE) was discussed next as that is required to create the software that controls the Uno functions. I used the customary and traditional LED “blinking” program to show you how to create and upload a program into the Uno. Incidentally, no additional parts were required for this demonstration as the program makes use of the Uno’s built-in LED connected to GPIO pin 13.

Next, I demonstrated a network-enabled program that allows a browser running on a remote, networked computer to control and receive data from the Uno. This program displayed the data from the Uno’s six analog-to-digital (ADC) converter channels in real time to the browser client.

I included a discussion on how the Uno, lacking an operating system, can run a web server application. I went into some detail about how this was accomplished and compared it to how similar boards, such as the Raspberry Pi, approach implementing web server applications.

I then demonstrated a simplified garage door opener project that used a modified version of an LED web control program that I showed earlier in the chapter. This project lacks security, save the inherent security present using a WPA Wi-Fi network with the opener hardware. I used both a remote client web browser and a smartphone to successfully control a garage door.

I next discussed how the Arduino software may be developed using Microsoft’s Visual Studio 2012 (VS2012) IDE in conjunction with the MegunoLink Pro software package. This combination is very powerful as it allows you to have full access to a comprehensive C/C++ development environment if you so choose. I used a completed project solution to demonstrate an enhanced garage door opener that employed passwords for better security.

I first showed you how to create and run a LED blink program using the VS2012 and MegunoLink Pro software. The enhanced garage door project was next, and it was very quickly implemented as it was already a successful project solution that needed only to be loaded into VS2012. I demonstrated how to set a password and then control a garage door using the password for access. This was shown using remote web browsers running a laptop as well as a tablet.

You should feel comfortable after completing this chapter in using the Arduino Uno for web-enabled projects. The next chapter builds on this chapter’s content to create a slightly more complex project: a web-enabled home irrigation system.