Step 1: Preparations
To kick things off, we will start by building up the TinyDuino Web server. The first step is to download Adafruit's CC3000 library which can be accessed here. Download the file to your Arduino library and proceed to assemble your processor, USB board, and the Wi-Fi board. For this tutorial, we will be looking at and modifying the HTTPServer example in the Adafruit_CC3000 library.
Step 2: Pin assignments & Security Details
The first change that must be made from the example is the assignment of IRQ, VBAT, and CS pin. The Pin assignment is as follows: ADAFRUIT_CC3000_IRQ 2, ADAFRUIT_CC3000_VBAT A3, and ADAFRUIT_CC3000_CS 8. Since we are using the #define feature for these pins, be sure not to include a semicolon after the pin.
Be sure to enter your own SSID and Password under WLAN_SSID and WLAN_PASS. Make sure you check the security setting of your wireless router and change the WLAN_SECURITY accordingly. The Adafruit library lists all of the available connection types the CC3000 chip is compatible with.
Step 3: Testing the CC3000
After changing those few settings, upload the program and view the COM port. When everything has been setup and initialized, we will be able to read the IP address, net mask, gate way, DHCP server, and DNS server.
The board will also be “Listening for connections…” with the IP address given to you, go to your web browser of choice and enter that number in the address bar. After going to the address, two things should happen. The Web browser will display a webpage, and the COM window will show you that a client has been connected and what requests the client is making.
Step 4: The buildup
Now that we know the CC3000 is working properly, let’s make a door sensor. Grab your protoboard, soldering iron, and reed switch. While using the Wi-Fi board, the pins 3-7 are going to be available for use. To make sure that your board will get power, take your 5V wall adapter and solder the red wire to the 5V terminal on the proto board and the black wire to the ground terminal. We will use pin 3 for the reed switch, so solder one end of it to terminal 3 and the other end to the ground terminal. With the reed switch, if a magnet is near the switch the circuit will be shorted to ground. Now, we will make our server tell us whether the door is open or closed.
Step 5: Reed switch/html setup
In the setup part of the code assign pin 3 as an INPUT and digital write it HIGH. That way, when the door is closed and the reed switch completes the circuit, pin 3 will be shorted to ground making it easier to read. In the main loop find the line of code inside the “ if (parsed) “ section that reads “client.fastrprintln (F("Content-Type: text/plain"));” change plain to html so that the content read from the client will be displayed in html format as a webpage.
Using client.fastprint(F()), we can create a nice, basic webpage. For more information on html, check the link here. We will now create the part of the code that will tell us whether the door is open or closed.
Step 6: Reading the switch
In the body of the code, we will perform a digital read on pin 3. If the pin reads zero, the reed switch has been completed and the door is closed. If anything else, the door will be shown as open. We also want to display a button in order to refresh the page to check the state of the door. With this last bit of code, upload it and mount your switch. We now have a fully functional door sensor that can be viewed on your own local network!
The code provided below is what your program should look like after making all the proper changes. Thanks to the codebender plugiin, it can be downloaded to your computer or directly uploaded to your TinyDuino processor board.