Remote Home Automation

by dathomar in Circuits > Remote Control

70155 Views, 211 Favorites, 0 Comments

Remote Home Automation

DTMFinternal.JPG
RHA_Main.JPG
I've wanted to post this project for about 3 years now but never could find the time. Oh well needs must as the devil drives as they say and it's here for you now. I hope it comes across clear, if not let me know and I'll fix it. With that said:

Home Automation systems are cool. You can use them to control your music, home temperature, lights, theater systems, sprinklers, HVAC, alarm system etc. Think of the Jetsons without the flying cars or stupid clothes. That's what the 21st century is supposed to be like folks, and it's not going to come on it's own we have to build it.

Back in 2007 and 2008 I made a Home Automation System as a part of my senior design project, and to automate some of the tasks that I come across in my daily life. While this project is still far from complete, and what I present here is just the tip of the iceberg, it is a great starting point to get your feet wet, and to build upon. I'll try and cover all the basics of what and why I chose to implement what I did back then. I'll also post a bunch of upgrade plans that can be easily implemented.

If you have any questions, comments, criticisms feel free to let me know this is my first instructable. If I did the system over today it would be a little different cuz I've learned more since then, tech has changed, and I no longer have a home phone line which the heart of the system relies on. Just don't measure my choices then based upon todays yardsticks. Some parts will get pretty wordy, but I'll try and load in Pics to help with that along the way. Hope you have as much fun with it as I have!

I mean this instructable to illustrate many BUILDING BLOCKS that can be used in your home automation system. Please treat each subsytem as a lego block, if you want to use it go for it, if you think it dumb ignore it.
(As a fair warning I can get wordy skip it if your not interested! Feel free to tell me where I messed up I wont take offense.)

This will also be my entry into the 3rd Epilog challenge, as well as the Makerbot Challenge I wish I had another month to update the info because there is a lot more, but I hope you like it as is.





What Is Remote Home Automation (RHA)?

robotHouse.JPG
BlockDiagram.JPG
Home Automation is a little different from Building Automation although they are pretty similar. Automated houses or smarthomes are usually distinguished by their ergonomics (or how they interface with people) and are made to have a little flare to them. Whereas most other building automation is strictly functional.

Examples of home automation include the clapper, the X10 series, and the HAL 2000 software .

Basically think of it as making your home into a giant robot. With different sensors, and systems to make your life easier.

Given above is the block diagram for the system we'll be focusing on. The Phone will be our initial interface for triggering subsystems, later I'll show how you can interface this with the computer and then automate more stuff from there.

There are an endless number of things that you can do to automate your home. Here I'll present a few of the building blocks for one such system. I intend for these systems to be used more like lego pieces so use them as you will. :)






Why Build RHA?

Injured.JPG
Elderly.JPG
There are lots of reasons to build an automated home. Primarily people build advanced houses because it's cool. Other more practical reasons are because a person is either injured, elderly, or infirm in such a way that they can't do everything they used to be able to do.

MY reason at the time was my wife was diagnosed with degenerative disc disease and scoliosis. Basically she had a REALLY bad back and couldn't always do everything she liked to do. Occasionally it got bad enough she couldn't get out of bed. So I would try and do extra stuff for her like feed her plants and keep the house clean-ish. That was a little tough with how much I was gone for school and work at the time so I made this system so I could do a few things to help out when the day was particularly not cool for her. (I also needed a senior project which this fit the bill nicely)

The final reason to build a home automation system is so that you can prove just how much work will will do to avoid having to stand up walk across the room and open the blinds. Because darn it all, they are ALL THE WAY OVER THERE!

Materials & Skills List

CostTable.JPG
For this instructable I assume you have basic electronics skills, namely soldering & following a schematic, also that your comfortable reading/writing code for a microcontroller. Where applicable I have included links to help put you on the right path if you don't have these skills at your disposal.

Here's a small list of materials used. Albeit not complete for everything I will be attempting to describe.

Materials:
 
     DTMF Decoder Sub-system:  
     1N4001 Diode
     10uF Capacitor
     100uF Capacitor
      0.1uF Capacitor x3
      10 nF Capacitor x3
      18pF Capacitor x 2 
      47 kOhm Resistor x2
      220 kOhm Resistor x2
      270 kOhm Resistor
      10 kOhm Resistor x3
      1 MOhm Resistor
      3.579545 MHz Crystal
      7805 Voltage Regulator
      Atmel ATtiny2313 (Today I'd use a ATtinyt 4313 or ATMega128/1280)
      7-12V Wall Warts
      Answering Machine or Phone that can auto-answer
      RJ 11 Phone Socket
      1:1 Audio Isolation transformer (still available at radioshack believe it or not!)
      20 MHz Crystal 
      Momentary Push Button Switch
      1N914 Diode
      Project Box
      Power connector socket to match wall wart plug.
      Piece of perfboard (mine was ~17 x 28 holes)
Optional:
     74LS48 7 Segment Decoder (optional)
     7 Segment Display (optional)
     Small Ferrite beads (possible)
     Screw terminal

     Plant Watering Sub-system:
     555 Timer
     90 kOhm Resistor ( 100k Potentiometer is better)
     0.1 uF Capacitor
     10 kOhm resistor
     100 uF Capacitor
     220 uF Capacitor
     1800 uF Capacitor
     0.01 uF Capacitor
     1N4001 diode x 2
     7805 Voltage Regulator
     12 Vdc Wall Wart
     5V Solid State Relay or TIP110 NPN Transistor
     12 V Solenoid Valve
      Perf Board
      Project Box
      Power Connector that matches wall wart
      Screw terminals x 3
      Rubber Hose that matches Solenoid Valve
      Tank to hold water or adaptors to hook hose up to house water line

    "Curtains":
     1N914 Diode
     10 kOhm Resistor
     Pushbutton Switch 
     110 Ohm Resistor
     10 uF Capacitor
     100 uf Capacitor
     18 pF Capacitor
     20 MHz Crystal
     ATtiny2313
     ULN2003A
     Zener Diode
     Stepper Motor
     1 Toggle Switch
     1 Pushbutton Switch
     2 Roller Switches
     Shaft Coupler (I JB welded together some 1/4" shaft collars)
     1/4 20 Threaded Rod
     Coupling Nut
     2 small L brackets
     Metal shaft
     Slider for metal shaft
     Project Box
     Framing Material (I used a piece of oak that I had laying arround)
    12 Vdc Wall Wart
     Connecter socket that matches wall wart
    7805 Voltage Regulator

    RFID Door Unlock:
    RFID Tag Reader    
    RFID Tags
    Electronic Door Strike
    555 TImer
    Project box
    220 uF Capacitor
    1800 uF Capacitor
    90k Resistor or 100k potentiometer
    10k Resistor
    5Vdc Solid State Relay
    12 Vdc Wall Wart
     7805 Voltage Regulator
       
    General Use:
    Wire
     Solder
     Heat Shrink tubing
     Zip ties
     Various Screws & Nuts
     JB Weld
     Time
     Patience

Okay.... that's not such a small list and I'm not sure I even got it all, I will repost this for each subsystem section so you don't have to keep referring to this page.

Budget:
     I made mine for about $400 back then, but that was with trial and error and buying stuff I didn't end up using, the heart of the system (DTMF decoder) can be made for ~$20 and subsystems can be cheap or real pricey depending on what you want.





Where to Get Components

Components.JPG
Components2.JPG
F31_RFIDReader.JPG
F30_DoorStrike.JPG
Buying electronic components for cheap is an art in and of it self. There is no 1 place to go for parts. That being said most cheap parts I order from Futurlec , Digikey , and Mouser . Futurlec is the easiest & cheapest to find general components on but comes from China so its got a long shipping lead time. Digikey second with a much larger range of options and if I can find it at mouser I will usually get it there because they have this nifty project manager feature that allows you to order stuff as clumped projects and look it up years later, this is especially nice when I look at a part from one project I want to put in another but don't want to look up all the other parts along with it. The project manager will store them all right next to each other for me, and suggest replacements if one is no longer made.

For the RFID doorlock I got both the electronic door strike and RFID reader from ebay . Just look up "Door Strike" and "RFID reader" and sort by price and you'll find the two I use in this instructable, and I bought this stuff about 4 years ago. Same with the stepper motors, but you will just have to look around for a good deal.

For the microcontrollers and any little modules that will shorten development time on this and other projects I used sparkfun.com . I don't think they carry the smaller attiny2313 any more which I used for this project, but you can upgrade it to a ATMega328, or ATMega128 (suggested), and pick up a nice breakout board there as well.

Finally I'd also look and see what they have over at the aptly named electronic goldmine you can pick up all sorts of sensors and things that are useful for home automation systems.





Tools & Where to Get 'em

Dremel.JPG
SolderingIron.JPG
Drill.JPG
Saw.JPG
USBTiny.JPG
You'll need a variety of tools for this project. I can't stress enough having the right tool for the right job. When I did this I owned 1 saw... a small hacksaw because it could cut metal. Oh yes it works fine on wood too, but it takes longer, is a pain, and isn't meant for that job. Do yourself a favor and never stop collecting tools, having the right tool saves time, energy and money. That being said here are some of the more important tools I used:

Tools:
Dremel or other rotary tool
Computer/Laptop
Soldering Iron
Atmel AVR programmer (I use the USBtiny from ladyada )
Drill/Screwdrivers
Hot air gun (read the manual)
Hot glue gun
Chisel
Saw
Safety Glasses
Work Gloves
Hammer
Pliers
Multimeter (I would suggest one with a continuity setting... will save your sanity!)
Oscilloscope
Bus Pirate would be handy too

Most of these are available at you local hardware store, or harbor freight if your low on the cash. You can make substitutions where needed, but no matter what you end up using: USE THE RIGHT TOOL FOR THE RIGHT JOB!






How to Solder

SolderingIron.JPG
Solder.JPG
The best breif guide I've seen on hand soldering can be found here from NASA. If you've not seen them even if you know how to solder go watch them. More in depth soldering guides are available from the guys at Curious Inventor

To sum it up:

1. Make sure your iron tip is clean & well tinned
2. Wet your sponge
3. Pre-tin the things you are going to solder, or use flux
     (don't always have to do this one, I usually only do this for wires)
4. Hold the two items being soldered together
5. In just a second or so of time:
    a. apply heat to the surface being soldered
    b. apply solder
    c. remove soldering iron and solder
6. Clean the tip of your iron on the sponge
7. Re-tin the tip of your iron





Microcontrollers:

AtmelLogo.JPG
USBTiny.JPG
ProgrammingHeader.JPG
I won't try and do a comprehensive list of how to program micros, but I will cover enough steps to get you started. There are better lists out there, lots on instructables (in fact I learned this here about 5 years ago). That being said I'll try and give lots of external links to help out.

Favorite Links for Microcontrollers:
avrbeginners
hackaday tutorial
AVRFreaks
Sparkfuns Beginning Embedded Tutorials

My choice of Microcontrollers is the Atmel line of 8 bit AVRs. The main reason for this is they were the cheapest & easiest to learn when I got into the hobby and now I'm hooked. There is a huge community of users and the open source tools are both powerful and customizable.

If you have another micro you are fond of feel free to substitute it any time. The TI MSP430s are great for low power which many home automation systems need to be, and the STM8s and STM32s look pretty nice too. Don't feel limited to only one micro, there are lots of great options out there.





Sub-System Choices

7805.JPG
Subsystems:

There are many potential subsystems that can be implemented in home automation. Anything from turning on and off house lights to feeding a pet can be accomplished. The following table summarizes several of the initial ideas for subsystems.

Some Potential Subsystems:
Open/Close Curtains
Water House Plants
Feed Pets
Toggle House Lights
Lock/Unlock Doors
Play Music
HVAC Control

Opening and closing the curtains, watering house plants, and latching/unlatching the front door are currently the most useful subsystems to me. They also demonstrate things that are useful to activate while being incapable of doing them by oneself, either from being ill, or absent.

There are many alternative design choices that could be made in this system. Each subsystem offers alternate approaches of their own, so alternative designs will mainly focus on the different choices available through user interfacing every subsystem will have a direct trigger option such as a switch or button. The next version of each subsystem will incorporate wireless communication and addressing to trigger the subsystems. For now the main subsystem will just toggle a transistor to activate the subsystems.

The main system types can be divided into two groups: direct actuation triggers and triggers that are created while traveling. The systems that offer control from a distance can also be used while at home, which makes them far more useful in the long run. A potential third group would be automatic triggers that occur naturally without the need of a user to be present. Automatic triggers offer the highest convenience but are more of a solution to trigger subsystems on the subsystem level instead of offering user control.

Based on the topics and ideas discussed above, a distance actuation system employing DTMF decoding will be used for the first user interface. The first three subsystems will be an indoor plant sprinkling system, a window curtain driver, and an electronic door opener. Then a simple security system, and adding IR as a user interface to connect to a computer. The final design details and implementation steps of each of these systems will constitute the remaining bulk of this instructable.

The circuitry for each of the designed subsystems can operate off of a 9-12 Volt input. The input voltage is then reduced to 5 Volts using a common LM7805 Voltage regulator. This is a simple circuit to build and can cost less than $1, including external components. Depending on the input power, the circuit may require an external heat sink, but generally will not for our power consumption needs. The 7805 usually supplies up to an amp of current which is well beyond what any of the driving circuitry will draw. All of the following subsystems use this chip with a 9 Volt 200mA power supply to power their on board microchips unless otherwise stated. A typical 7805 setup can be seen in the above schematic.





DTMF: What Is It?

Telephone.JPG
DTMFKey2.JPG
DTMFtable.JPG
The main system is the user interface and control system. The phone line was chosen as the method of interfacing because it has distinct advantages over other systems in communicating information from a distance. The method of sending simple commands across the phone line is also already provided by the keys of a touch-tone telephone. When a key is pressed, a unique tone is played. The tone is actually a combination of two separate frequencies and the signaling touch-tone system is more appropriately called Dual-Tone Multi-Frequency (DTMF) signaling.

You can see what this signal looks like in the image above. I've also included a table that shows which key presses correspond with what frequencies. There are other standards defined for DTMF including key presses A-D as well as the signal used to cause your phone to ring and everyone favorite dial tone.






Why Choose DTMF?

TappedPhone.JPG
So now that you've seen the anatomy of a DTMF signal why did we choose it vs. say other methods?

Well DTMF was designed for the purpose of actuating systems remotely from a distance (hmmm...sound familiar?) and the chief concern was to ensure a reliable recovery of the transmitted signal. As a result, DTMF was designed with various characteristics to isolate it from potential noise. These characteristics include:

o Each DTMF signal is just under a whole tone.
o None of the tone frequencies are the sum/difference of any other two tones.
o No tone’s frequency is a multiple of any another.
o Valid DTMF signals must vary by less than 1.5% of the designed frequencies.
o The higher four frequencies can be a maximum of 3 dB louder than the lower frequencies.

Basically it's a well established, easy to use, and reliable system. Perfect for our first user interface.






Isolating From the Phone Line

AudioIsolation.JPG
The DTMF Decoder must be isolated from the regular phone line to prevent it from getting fried from voltage spikes or other transient signals or noise that could come in from the outside world.

There is often protection circuitry installed in commercial hardware such as an answering machine. Also answering machines are both cheap and readily available in thrift stores. Interfacing the system with an answering machine also handles hanging up the phone when the call is completed.

You can also use a cell phone that auto answers after a few rings. I'll describe later in the instructable how this can also be used as a GPS car tracker on the cheap :)

Aside from relying on some other manufacturer to protect our circuit from the phone line we have a schematic shown which is the circuit that takes care of isolating our chips for us so we know we are protected.

The Audio Isolation transformer can be picked up at radioshack , and I used a standard wall phone jack that I dremeled down to size for the phone line input. The rest of the components are probably easiest to pick up at an online retailer.

The phone plug is a regular RJ11 plug .







Decoding DTMF

Decode DTMF.JPG
DecoderRing.JPG
CM8870.JPG
Early Soldering.jpg
DTMF tones can be decoded and converted to digital signals. These signals can then be used by a microprocessor to determine if an appropriate series of digits was entered by the user. If the correct code is entered, the microprocessor will activate one of the subsystems. Multiple codes or one code with an options menu can be used to activate the appropriate subsystem.

There are many ways you can decode DTMF including:

The Goertzel Algorithm
Band split filters & pulse counters
Premade chips for decoding:

     - CM8870
     - SSI-202, 203, 204
     - MSM6843
     - MC145436
     - MC68HC05F5-µP

I've looked at several of these, the easiest to use and understand is the CM8870 chip. It acts kind of like a decoder ring that spits out the binary value of a DTMF signal. The CM8870 actually implements the bandsplit filter and pulse counter method which is illustrated from a MATLAB screenshot taken of the DTMF decoder file written by Randolf Sequera. If you'd like to play with it you can get it over at the MATLAB file exchange .






DTMF Decoder: Hardware

DTMFinternal.JPG
AudioIsolation.JPG
CM8870sch.JPG
DTMFdecoderSch.JPG
DTMFinternalBack.JPG
DTMFcomplete.JPG
Xbee.JPG
DecoderSchematic.jpg
Materials:
1N4001 Diode
10uF Capacitor
100uF Capacitor
0.1uF Capacitor x3
10 nF Capacitor x3
18pF Capacitor x 2
47 kOhm Resistor x2
220 kOhm Resistor x2
270 kOhm Resistor
10 kOhm Resistor x3
1 MOhm Resistor
3.579545 MHz Crystal
7805 Voltage Regulator
Atmel ATtiny2313 (Today I'd use a ATtiny 4313 or ATMega128/1280)
7-12V Wall Warts
Answering Machine or Phone that can auto-answer
RJ 11 Phone Socket
1:1 Audio Isolation transformer (still available at radioshack believe it or not!)
20 MHz Crystal
Momentary Push Button Switch
1N914 Diode
Project Box
Power connector socket to match wall wart plug.
Piece of perfboard (mine was ~17 x 28 holes)
Optional:
74LS48 7 Segment Decoder (optional)
7 Segment Display (optional)
Small Ferrite beads (possible)
Screw terminals

This schematic shows how the last few circuits connect together and feed into the ATtiny2313.

The output from the 2313 to toggle the subsystems is shown at the top left of the 5th picture. These were just wirewrap sockets I could jumper to the other projects. I would update them to be wireless addressable units now using something like a zigbee , and I'd update the schematic to not use the ATtiny2313's serial pins for the DTMF input, but the circuit shown will work just fine.

One of the funny things I came across was that my CM8870 was not putting out 5V as I'd expected. It was actually floating in the range between a logic high and a logic low on the ATtiny2313, faced with it not working for my upcoming project demonstration and hacking it I chose to use hack it. I didn't have a logic level shifter or much else so I decided to drop the ATtiny2313's operating voltage which would in turn lower the threshold voltage for a logic level high.

All I ended up doing was making a voltage divider with a few spare resistors feeding the ATtiny2313's power.... horrible design I know... but it worked and got me through my review. You can probably leave this out and just connect the 2313 to 5V but be prepared to do something funny if the CM8870 output is finicky.

The last schematic should be the same as the first but without the voltage divider.






DTMF Decoder Code (Assembly & C): Programming an Atmel AVR

Coding.JPG

Here I'll explain the code a little bit, the next few steps will be a tutorial on how to load it into the ATtiny2313 using an example program, but the same steps will apply for all the code we have for the micro-controllers.

I've included both the assembly and C code for this circuit. They should be pretty similar in function. The C code just forwards what is read by the ATtiny2313 onto Port B from Port D, this is so that you can verify that the signal is coming in correctly with nothing more then a few blinkinlights on the lower 4 pins of Port B.

The default code is 0000 and can be changed on line 99. Once you've entered the correct code hit the # button on your phone to have the micro validate the code. If you mis-press a key don't worry, just keep entering numbers the micro will only remember the last 4 digits entered.

Once your that far and you can see the DTMF codes being read correctly by the 2313, un-comment the large block of code on lines 118-121, and 123-261, and comment out line 122 to enable regular functionality.

Lines 233-238 will contain the code you want executed once a valid code is entered. Port B is totally free so for a low # of sub-systems you can just have the next phone key presses activate subsystems directly on the port. Another option would be to have this section send a serial command out to either a computer or other subsystem.

There is a lockdown mode for too many invalid characters being entered, I defaulted it to 2 seconds for your troubleshooting but once working I would encourage upping this to a few minutes or more for security. Lines 320-332 have the lockdown code.

Ask any questions if you have them and I'll try and explain the mad state I was in while coding this. It is fairly well commented though and shouldn't be too hard to decipher.





 

Download Development Enviornment

WinAVR.JPG
Now that it's time to dig into

WinAVR is a suite of tools to program Atmel's micro-controllers within Microsoft windows OSs. This is what I'll use for this instructable to code in C.

AVR Studio 4 : If you are the type of person that enjoys the speed and efficiency provided by banging your head on a rock.... erm... I mean .... programming in assembly. Well then you could do a lot worse the by going with Atmel's own tools. Actually AVR Studio 4 is pretty powerful and the environment I first started this project with. I'll give the code that remains from then as well.

Linux: For the power hungry nerd in all of us.

CrossPack : "Hi I'm a Mac"

Also if you'd like you can hop on the beta for testing out AVR Studio 5 AVR Studio in C using BOTH the GCC and IAR compilers if I'm not mistaken. Not used it yet but this is looking pretty promising as well. Way to go Atmel!








Create a Makefile

makefile.JPG
Lets see how can I explain these... Lets say your a person that doesn't know anything about cars and your development environment is a car. Then a makefile is like your cars engine. Its powered by all sorts of tomfoolery and witchcraft that you don't need to worry about right now.

Just include the one I've left here, in your codes main directory. If you are using a different microcontroller then the attiny2313 or would like to use a bit of code with a different name then TEST_2313.c you will need to edit the makefile just a little.

To do so open the WINAVR program named MFile and with it open the make file I've included. If you are using a different microcontroller then me change the first highlighted name from attiny2313 to the name of your micro. If you want to use a C file with a different name change the second highlighted value to the name of your file (it IS case sensitive and you need to leave off the extension).

Notice you can't edit the make file..... to enable edititing of the make file goto: "Makefile >> Enable Editing of Makefile" and type away to your hearts content.







Downloads

Load Code Into Programmers Notepad

matrix.JPG
Once your makefile is squared away open the WINAVR program called Programmers Notepad.

From the main menu select File >> New >> C/C++
Paste the below code into the editor and save the file as TEST_2313.c  making sure it is saved to the same directory as your makefile.


#include <avr/interrupt.h>        // Defines pins, ports, etc to make programs easier to read
#define F_CPU 8000000UL   // Sets up the default speed for delay.h
#include <util/delay.h>             // Allows for delay to be used
#include <avr/io.h>                   // Enables IO

//**********************************************************
// Main Program

int main()
{

DDRB = 0xff;            // Set Port B data direction register to be outputs
PORTB = 0x03;       // Turn on Port B Pins 1 & 2 (0b00000011)

while(1)                    // Repeat this code forever
{

      for(int i = 0; i < 250;i++)
      {
           PORTB = 0x02;                  // Turn on and off, Port B Pin 2, 251 times with a 1/4 second delay
           _delay_ms(250);
           PORTB = 0x03;
      }

/*                                                                This is how you comment out a large block
       for(int i = 0; i < 250;i++)
       {
           PORTB = 0x00;
           _delay_us(250);
           PORTB = 0x01;
       }
*/

} // end while

return(0);

}     // COPY CODE ALL THE WAY DOWN TO HERE !!!!






Compile Code

compiling.JPG
To compile your code inside of programmers notepad click on Tools >> [WinAVR] Make All.

If you've followed up until now what this will do is take the example code from the last page and create a hex file. This is a file that can be read by the microcontroller.

This hex file should be saved in the same directory as your C code and makefile, along with a whole bunch of other stuff you don't need to care about right now. Take the hex file and copy it into the same directory as the program avrdude and get your programmer ready to burn your first microcontroller.






Connect the Programmer to the ATtiny2313

DevBoard.JPG
USBTiny.JPG
ProgrammingHeader.JPG
ATtiny2313pinout.JPG
Open avrdude:

     Open a command prompt by going to Start >> Run >> cmd >> Enter.
     Then inside of the command prompt go to the directory where WinAVR's avrdude program is hiding.

Connect Your Programmer:

     Each AVR requires 6 pins to be programmed. These are:

     MOSI - (Master Out Slave In, pin 17)
     MISO - (Master In Slave Out, pin 18)
     SCK/SCL - (Clock, pin 19)
     Voltage (pin 20)
     Ground (pin 10)
     Reset (pin 1)

     Connect these 6 pins from the programmer to the chips identically named pins. The programmers usually will follow Atmel's defined pinout for the ISP (In System Programmer) which I've included in the pictures. You can just jumper them over, or build a breakout board like I did to make programming lots of the same chips easier. The guys at Evil Mad Science have made a ATtiny2313 breakout board that easily replaces the board I have shown. Just solder in a 6 pin header and a Zif socket and you are good to go.

Also ensure that your chosen programmer is providing power to the micro. If it doesn't do this you will need to supply the chip with 5V externally, don't forget to connect your ground to this external ground!






Loading Code Into the ATtiny2313

avrdude.JPG
With AVRdude open, your microcontroller receiving power, and your programmer connected it's time to learn how to use AVRdude.

Check that AVRdude sees the ATtiny2313 by typing the following command:

     avrdude -c usbtiny -p t2313

This line says we'd like to program an ATtiny2313 using the usbtiny programmer. If you are using a different device or a different chip you can type

     avrdude -c 6

to get a list of valid programmers

     avrdude -c usbtiny -p 6

to get a list of valid microcontrollers. If AVRdude could not find the device it will say: "Could not find...." If AVRdude could find the usbtiny programmer it will say "avrdude: Initialization failed...." I know it sounds weird, but trust me it found it.

To program your hex file onto the chip type:

     avrdude -c usbtiny -p t2313 -U flash:w:XXXXXXXX.hex

substituting the name of your file for the XXXXXXXX's given above.

If you ever get stuck just type 'avrdude' then press 'enter' and a list of commands will pop up.
A great tutorial on using AVRdude is available at ladyada's website

Once you're comfortable with AVRdudes functioning go to this Sparkfun tutorial and setup programmers notepad to do the programming for you with hotkeys. You'll still need to know how to run AVRdude, particularly when you need to burn the fuse bits... speaking of which:







Burn the Fuse Bits

Tiny2313XTAL.JPG
T2313FuseTable1.JPG
ChooseXTAL.JPG
NewFuseByte2313.JPG
The AVR fuse bits are special bits that change certain things about your micro such as if you want to allow someone to read the hex file saved on your AVR or not. We'll be using them to tell the micro-controller to not use the internal RC oscillator anymore, but for it to start running from off of an external crystal. This gives us more speed and a more precise clock.

Ensure that your crystal and bootstrap capacitors are connected before you try and burn the fuse bits. If your micro now wants to run using it's external 20MHz clock and it doesn't have one well, it will look like you killed it (you didn't you just need to clock it properly but still it can be aggravating finding this out later on).

Also you can let the magic smoke out if you decide to go mucking around with the the fuse bits and don't' know what you're doing so be careful.

To reprogram the fuse bits :

1. Hook up to program the AVR as normal
2. Open AVRdude and type:

     avrdude -c usbtiny -p t2313 -U lfuse:r:-:h

     This will READ the low fuse byte (the one we care about) from the ATtiny2313.

Referring to the Table in the images: the results of the above will give the default settings of the internal RC oscillator running at 8 MHz, but CKDIV8 results in an actual clock speed of 1 MHz.. THE DEFAULT LOW FUSE BYTE VALUE IS: 0x64

From the ATtiny2313 datasheet we can see that we need to set CKSEL3 through CKSEL0  to be between 1000-1111 (binary). And the exact value depends on the speed we want to run at.

3. Refer to the second table and choose a clock speed.
    For an 8+MHz clock speed we want CKSEL3...1 to be 111 and CKSEL0 = 1 for a Crystal oscillator with a fast rising power. Look at the 3rd table to see the changes to the fuse byte. THE NEW FUSE BYTE VALUE IS 0xEF

4. Hook up the Crystal & bootstrap capacitors as shown in the schematic.
5, Program in the new LOW fuse byte by typing into AVRdude the following command:

     avrdude -c usbtiny -p t2313 -U lfuse:w:0xEF:m

The ATtiny2313 should now run on an external crystal. Woo-HOO!!!







Water the Plants: Design

PlantWateringBD.JPG
The first subsystem designed for this project was an indoor plant watering system.
The implementation for this system is straight forward and relatively simple as can be seen in the block diagram given in the pictures.

The activation signal comes from either the DTMF decoder circuit or from a push button switch. This activates a timer which will drive a relay controlling a solenoid valve. The valve will remain open for the duration of the timers’ impulse. With the valve open water can be either drained from a gravity fed tank or connected to the house water line. The timer is also used to make sure that the plants do not get over-watered. This is done by keeping the valve open for a known quantity of time which will control the water flow to the plant.

Materials to Build:
555 Timer
90 kOhm Resistor ( 100k Potentiometer is better)
0.1 uF Capacitor
10 kOhm resistor
100 uF Capacitor
220 uF Capacitor
1800 uF Capacitor
0.01 uF Capacitor
1N4001 diode x 2
7805 Voltage Regulator
12 Vdc Wall Wart
5V Solid State Relay or TIP110 NPN Transistor
12 V Solenoid Valve
Perf Board
Project Box
Power Connector that matches wall wart
Screw terminals x 3
Rubber Hose that matches Solenoid Valve
Tank to hold water or adaptors to hook hose up to house water line






555 Timer

Astable.JPG
Monostable.jpg
555timer.JPG
A popular timer chip is the 555 timer made by a variety of companies. 555 timers are used in many different systems because they can be easily configured for either astable or for monostable operation. They also require a low component count and are very straight forward to work with.

While in astable mode, the timer acts like a common clock circuit providing a constantly changing pulse level that can be controlled with a great degree of precision. The duty cycle of the timer can be easily changed making this circuit popular for use with servo motors. A servo motor would fulfill the requirement for precision angular control as well as keeping with the modular theme of each subsystem. So a 555 timer is a good choice to keep in mind for use in future subsystems as well.

The monostable operation of a 555 timer is the mode of operation that is of interest for this particular application. While in monostable or ‘one shot’ mode the 555 timer will drive its output signal high for a predetermined period of time. The time that the pulse remains high is determined by the value of an RC network attached to the timer. A capacitor is charged and upon activation, is allowed to drain through a resistor to ground. The RC time constant of this setup determines the length of time for this drain to occur and in turn sets up the time frame for the duration of the output pulse.
The equation that determines the timer pulse duration is as follows:

t = 1.1*R*C

Where t is time in seconds, R is resistance in Ohms, and C is capacitance in Farads. The resistor and Capacitor to worry about changing the values on are the ones that attach to pins 6 and 7 of the 555 timer.

 To vary the time within known limits, the resistor can be replaced with a potentiometer acting as a rheostat. This allows for simple changes to the pulse length to be made without having to take the system apart.

The 555 timer circuit requires a low activation signal to turn on. The software for the remote access system was coded to output a high pulse as an activation signal. To reverse the logic fed from the microprocessor to work with the 555 timer, a 3904 NPN transistor was used to short the 555 timer trigger line to ground.

I highly recommend taking the time to read the doctronics writeup on 555s they have just about everything you would like to know about them.






Driving a Solenoid:

zener.JPG
F16_PlantWateringSch.JPG
The thing you should know about driving a solenoid or a relay or an inductor of any kind is that they have the potential to damage your system if driven incorrectly.

The reason behind this is the solenoid is made from a coil of wire which will form a magnetic field when current is flowed through it. When you try and turn off this current the solenoid will throw a fit. Inductors don't like changes in current, so the inductor will try and keep the current flowing by releasing all the energy stored in it's built up magnetic field to do so.

However, inductors do not care about Voltage and will do whatever they can to the Voltage across their coils to keep the current flowing while the magnetic field is collapsing. This leads to the voltage spiking to extremely high values, a few hundred volts is not out of the question and is in fact quite common. As you would guess this is not a happy thing to see a few hundred volts on the pin of an integrated circuit and will probably kill it.

Fortunately you can protect your circuit by putting in a reverse biased Zener diode. There is a good Sparkfun tutorial on driving relays and there they use a 1N4148 across the relays terminals. This will also work nicely for our solenoid valve.

Several relays were tested in the system and none had any specific advantage over another. Eventually, I tried and settled on a Motorola TIP 110 NPN Darlington Pair to drive the solenoid valve instead of the relay. The TIP 110 works exactly like a typical NPN transistor with a higher operational voltage and current range. The TIP 110 can drive a load at 60 Volts and several amps. This was the same for the relays, but they cost several dollars whereas the TIP 110 cost fifty cents. The TIP 110 also only required 3 connections to be made instead of the four from the solid state relays.







Choosing a Solenoid Valve

SolenoidValve.JPG
This system was meant to be connected to either a water tank or to a house’s main water line. Depending on where the user lives the water pressure they receive can vary greatly from place to place. A typical house has about 60 psi on a water line, but this value can vary as high as 120 psi. The solenoid valve that was chosen would need to be able to withstand each of these pressures without leaking and would need to be able to be activated with one of the systems operational voltages. Many valves that match this description can be purchased online from mcmaster.com.

Most commercial solenoid valves operate from either 12 or 24 Volts alternating current or direct current. With a 12 Volt power supply running a 7805 voltage regulator for the 555 timer circuit it was an easy choice to go for the 12 Volt valves. A valve from ECI valves was chosen for its high pressure rating (300 psi) and high Cv factor. A high Cv favor determines the flow rates capable for a valve, the higher the rate the higher the flow.

A secondary valve made by EHCOTECH was also chosen for similar operational qualities and it was a little more cost effective. The EHCOTECH valve is also actuated by 12 VDC and is a normally closed valve to prevent water from flowing when not desired. This secondary valve can only withstand 150 psi so although it can be hooked up to a house line it isn’t quite as secure as the ECI valve. This valve will also work for a gravity fed system the one you choose may need pressure in order to work right.

A third option is to use the same diaphram valves that are commonly used on regular outdoor sprinkler systems. These are both cheap, and easy to repair/replace.They are also always available at the local hardware store.






Water the Plants: Implementation

F17_WatererCircuitry.JPG
F18_WateringSubsystem.JPG
The plant watering subsystem was also assembled with point-to-point soldering on a 2.75 mm proto-board. The LM7805 voltage regulator and 555 timer circuits were first tested using a LED and piezo buzzer for output. The TIP 110 Darlington transistor was then added and tested for adequate power delivery to drive the solenoid valve. Screw terminals were added to connect the driving circuitry to the outside world, and to accept a trigger signal.

Like the remote access system, this subsystem was encased within a RadioShack project box measuring 50 x 75 x 30 mm. Wires to the outside world were fed through holes drilled in the side of the project box. The wires were secured in place internally and tested externally for strain relief. A size K coaxial DC power jack was added to the side of the box and connected to the internal circuitry. This configuration is shown above.

The test solenoid described above was attached to the system’s driving line and the circuit is actuated by applying an external voltage to the input lines. The system was tested with various driving times by changing the value of an internal potentiometer. The 555 system is set for approximately a 5 second run time.

The solenoid valve was tested by connecting it to a submersible water pump. The valve would successfully only water the plants for the predefined period of time, and would remain off even in the absence of power to the system. The second image shows the completed system.

The test results met the required design parameters, and with a slight change in the external mechanical hardware connected to the solenoid valve, the system can be driven from a home water line with no trouble.

Potential improvements include the design and use of a water level meter or soil moisture transducer to provide feedback that would prevent the plant from being over watered. This could also keep the water from overflowing the reservoir tank at the base of the planter box.






Open the Curtains: (Prototype CNC Axis)

curtains.JPG
F19_HalfStepSeq.JPG
F20_ULN2803.JPG
F21_CurtainBD.JPG
F22_MotorRod.JPG
F23_CouplingNut.JPG
F24_CurtainSWFlow.JPG
F25_CurtainActuationSch.JPG
I will start out by saying this is not the ideal design for this sub-system, I've included links to a better design at the end of this subsystems section, which I also later implemented.

It worked because my curtains were on a pulley system and just needed to move the rope up and down to open and close them. At this point I also really wanted to build a CNC machine but the budget & school time frame only allowed for one to be built.... so I compromised by making a single prototype CNC axis that I could use to open and close the blinds.

There is no point in watering plants if they are going to die from a lack of sunlight. So that is why this was made: opening and closing window shades and curtains.

Materials:
1N914 Diode
10 kOhm Resistor
Pushbutton Switch
110 Ohm Resistor
10 uF Capacitor
100 uf Capacitor
18 pF Capacitor
20 MHz Crystal
ATtiny2313
ULN2003A
Zener Diode
Stepper Motor
1 Toggle Switch
1 Pushbutton Switch
2 Roller Switches
Shaft Coupler (I JB welded together some 1/4" shaft collars)
1/4 20 Threaded Rod
Coupling Nut
2 small L brackets
Metal shaft
Slider for metal shaft
Project Box
Framing Material (I used a piece of oak that I had laying around)
12 Vdc Wall Wart
Connector socket that matches wall wart
7805 Voltage Regulator






Stepper Motors

Stepper.JPG
Stepper motors have a natural 360 degrees rotation angle whereas an RC servo has only a limited range without modification. Servo motors also come in a wider variety of sizes and strengths.

Unlike a regular motor a stepper motor does not spin freely when a voltage is applied to its terminals. Instead a stepper motor has many inputs (4-8) and a voltage applied across the right pair will cause the stepper to rotate a small amount (typically 1.8 degrees). This is called taking a step.

When a voltage is applied to the stepper motor terminals in the proper sequence the stepper motor will step in the same direction as the applied terminal voltage. To reverse the stepper motor the input sequence is reversed. To change the stepper motors speed the sequence is changed faster or slower. And to stop and hold a stepper motors position the sequence is halted on the appropriate step.

Stepper motor speeds can be limited by the inductive/resistive components associated with the leads and internal windings of the motor. This LR time constant can lead to stalling and dead zones of operation. The time constant that determines where the motor stalls can be easily changed on unipolar motors. This allows them to be run at speeds they were not initially designed for, and as long as the input power stays within the motors operational range no damage should come to the motor through such control. To change the LR time associated with a unipolar motor a series resistance is added to each line. Then by running the motor in its higher voltage range the same torque levels can be achieved. The drawback to running a system in this method is the power that gets wasted as heat in the series resistances that were added to the driving terminals.







More on Stepper Motors

F19_HalfStepSeq.JPG
StepperTypes.JPG
Stepper motors come in two varieties bipolar motors, and unipolar motors. Bipolar motors have four input wires and require an H-Bridge circuit to drive the inputs. Unipolar motors have from five to eight inputs, but most are run using the five terminal configurations regardless of the number of terminals available. Unipolar and Bipolar motors have the same stepping sequences, but unipolar motors are easier to work with and do not require an H-bride driver circuit. A typical stepping sequence can be seen in above.

The above figure shows the sequence of terminal activation required for driving the motor in half step mode. Half stepping provides a motor with greater resolution but requires more power to drive the motor. To do regular stepping the odd numbered steps can be removed from the chart, and to drive the motor with more torque two adjacent terminals can be triggered at the same time. Any stepper motor requires two additional pieces of circuitry; a stepper driver and a transistor array capable of sourcing or sinking the motors operational voltage and current.

A Unipolar motor can be driven as a Bipolar motor by leaving the two center taps unconnected. Because of this it may be in your best interest to buy a 6 or 8 wire unipolar motor and then have the option of driving it as either a unipolar or bipolar motor.






Stepper Motor Electronics

F20_ULN2803.JPG
F24_CurtainSWFlow.JPG
F25_CurtainActuationSch.JPG
A stepper motor driver can be purchased for around $15 , or one can be programmed on a microcontroller. The microcontroller option is cheaper, and allows us to add features that may not be available on a driver circuit. An ATtiny2313 is again chosen to drive the stepping sequence of the motor. Programming a step limit allows us to tell the motor how far it is required to turn before stopping. A general stepper motor driver was written in C for the ATtiny2313 and several input pins were used to determine various factors about how quickly, and how far the motor would turn. Limit switch inputs were also included in the code as a means of redundantly stopping the motor from turning past its desired bounds.

To provide the motor with enough power to turn a ULN2803 eight Darlington array with a common emitter was used to sink power through the motor terminals. Although only four of the eight Darlington pairs are required to drive the stepper motor a person can use the extra four, and the unused four digital I/O lines on the ATtiny2313, to drive a second motor at the same time for use on a future subsystem. The pinout of the ULN2803 Darlington transistor array can be seen above

The block diagram for this subsystem is shown above as well.







Lead Screw, Thrust Nut, and Linear Rail

F22_MotorRod.JPG
F23_CouplingNut.JPG
PB030034.JPG
PB030037.JPG
PB030038.JPG
Now being able to control the rotation of a motor precisely, the system can be mechanically converted from this motion into a linear path. To do this conversion, simply connect the stepper motor to a long threaded rod via a shaft coupling. On the threaded rod is placed an inch long coupling nut. When the orientation of the nut is held constant and the stepper motor is turning the nut will move up or down the threaded rod depending on which direction the motor turns. The first image shows the stepper motor attached to the threaded rod. The coupling nut can also be seen at the far right of the same image.

To hold the coupling nut in a constant orientation a non-threaded rod is run parallel to the threaded rod and a slider is placed on it. The coupling nut is then attached to the slider with some JB Weld. The motor and two rods are mounted in a frame to hold it all together. As the threaded rod turns the orientation of the coupling nut is held constant due to its connection to the slider. This causes the coupling nut to screw itself up and down the threaded rod which allows control of the backwards and forwards movement of the coupling nut.

The angle of threads on the threaded rod and the speed and resolution of the turning motor will translate to the speed and resolution at which the nut moves up and down the threaded rod. With a smaller threaded angle and a slow strong turning motor the linear motion can be made fairly strong as was done in this system. Industrial applications for this setup are commonly found in desktop printers, as well as CNC routing machines.

My window curtains opened with a pull string on a pair of pulleys, while the angle of blinds is determined by rotating a plastic rod. This system can be used to open either, with little modification. To open curtains that have a pull string, attach the string securely to the coupling nut on the threaded rod. Activate the system and the nut will move up or down pulling the curtains pull string with it. If the pull string is secured on the bottom with a pulley the curtains will open and close with no trouble.

To change the angle of blinds on a window directly drive the blind rod with the stepper motor and a shaft collar. Varying the level of light allowed to enter the blinds can be done by changing the number of steps the motor takes before stopping.







Curtains Code:

F24_CurtainSWFlow.JPG
F25_CurtainActuationSch.JPG
The software flow diagram is the first image. The second is the complete schematic.\

A copy of the stepper motor program is included as well and it's in C ‘CurtainStepper.c’ sorry assembly coders, no love this time ;).

Also as can be seen in the schematic a ULN2003 Darlington array can be used in place of a ULN2803 array. These chips are identical in function but the ULN2803 has one extra Darlington pair included in its array.

There are also several connections to the ATtiny2313 that are not shown in the schematic. Each of these connections is a control signal for the program that runs the stepper motor and is described in the comments at the beginning of the program “CurtainStepper.c”. Pretty much just a couple push buttons and limit switches.

I've also included the hex file so you can just burn this straight to the microcontroller.






Open the Curtains: (Prototype CNC Axis) Implemented

F28_CurtainControlMounting.JPG
F26_CurtainDriver.JPG
F27_CurtainControlBox.JPG
The curtain driver was required the most in terms of electrical and mechanical assembly. The frame to hold the system together was made from oak and measures 41.5’’ in length. The electronics were assembled as was described in the plant watering implementation system and placed in an identical RadioShack project box with a size K coax DC power connector attached flush with the side of the project box. The completed subsystem is shown in the figures above.

A local activation push button and an up/down toggle switch was added to the front of the project box. The local activation switches are wired in parallel to the external activation signal connectors so as to not interfere with the microprocessor activating the system. All signal connections to the outside world were made with screw terminals which can be accessed through drill holes created in the project box and which can be seen in Figure 27.

The stepper motor used for this subsystem is a NEMA size 23 motor and was purchased on e-bay with two other identical units for $30. It has a resolution of 1.8 degrees per step and 56 oz-inches of holding torque.

It is a six lead unipolar stepper motor and can be driven from 12-36 VDC. The frame depth was measured to fit the size 23 motor. The motor was attached to the frame using its mounting holes and three 2’’ machine screws. A hollow metal guide (slider) was placed in line with the motor shaft to hold the threaded rod. The slider rod was bent to fit through the motors final mounting hole and through a drilled guide hole at the top of the frame.

The electronic circuitry was attached to the side of the frame using zip-ties which passed through holes drilled in the project box for mounting. Momentary roller limit switches were mounted on small L-brackets at either end of the threaded rod and wiring to the switches was fed along the back of the frame and into the project box. To reach the limit switches with the wires, holes were drilled through the frame and the wiring fed through and soldered to the switch contacts. This setup kept the system very compact and clean looking. The wiring to the limit switches can be seen in the previous figure, while the motor mounting can be best seen in Figure 28.

The speed of the stepper motor is kept slow to demonstrate the precision control achieved for both linear and rotational motion. As a result the coupling nut takes about a half hour to traverse the length of the threaded rod. For the demonstration the curtain driver was actuated using the local switches. By modifying my code you can easily make that rod spin faster, and have the coupling nut traverse the length of the rod in 10 or so seconds.

Future versions of the curtain driver can be improved by the addition of an emergency stop switch, an external speed controller, and a six pin programming header. The programming header would allow a user to easily interface to the microprocessor without having to take apart the entire system. This can also be used for testing different programs with greater efficiency.

The electrical and mechanical designs are both sound and can be used with slight modifications for a variety of applications . The curtain driver will also be rebuilt using a DC motor with limit switches and an H-bridge.

When I rebuilt this I used a faulhauber gear motor and a reprap magnetic rotary motor encoder which I believe you can now get from makerbotindustries. A photo-resistor and a real time clock were used to make it a standalone blinds opener, but it also accepts a pulsed input so that I can one day connect it to the main system via a wireless link. The actual implementation is similar to this instructable .

My wife didn't like the idea of this thing opening the front blinds when she was walking by in the morning in a bathrobe. So I've decided it will go in the guest bedroom.... you've been forewarned!






Unlock the House With the Phone & RFID

F29_DoorStrikeBD.JPG
The final subsystem was designed to unlock the front door of a home remotely. This is useful for allowing a friend to enter the user’s home without needing to leave them a key.

Specifically for my wife this allows her to unlock the front door when bringing groceries or large packages home without needing to fiddle with her keys. The user can call the house on the way home and unlock the door, or the user can locally open the door with either keys, or by using the Radio Frequency Identification (RFID) tagging system that is installed as a parallel trigger for activating this system.

The system block diagram is shown in Figure 29.






Electronic Door Strike

strike.JPG
F30_DoorStrike.JPG
This system originally was designed to use an electronic door lock, but a typical keypad door lock costs over $100 and the budget was nearly spent. Instead of the electronic door handle an electronic door strike was purchased for $30 and can be seen in Figure 30.

An electric door strike has the same functionality as a regular door strike, namely to hold the latch of a door secure. Both an electronic strike and regular door strike are shown above to let you know what I am talking about. Electronic door strikes are designed so that when a voltage is applied across its input terminals the strike will collapse and the door will be able to swing freely open without needing to be unlocked.

Electronic door strikes can be either normally locked or normally unlocked. An electronic door strike that is normally locked when power is not applied is called a ‘normally open’ type, whereas a normally unlocked door strike is known as ‘normally closed’. Normally open, and normally closed refers the strikes driving electronics and not to the locked or unlocked nature of the door itself.

For this design a normally open strike was chosen so that the door would function in typical fashion without needing to be connected to a power supply. The electronic door strike measures 160 x 25 x 28 mm (L, W, H) and is actuated with 12 VDC and 200-450mA.

This setup is nice because I can leave my door locked all the time and it will remain secure. When I activate the system though, it will unlock for a predefined period of time.






RFID Tag

F31_RFIDReader.JPG
tag.JPG
ParallaxRFID.JPG
As another means of actuating the door a passive RFID tag reading module was purchased on e-bay for $4 (Purchased in bulk) and is shown as the black RFID system above. The RFID reader operates at 125 kHz and can read tags up to 75 mm away. When a valid tag is identified 12 VDC is placed on an output line for as long as the tag is being read. The 12 Volt output is used to drive a 555 timer (just as in the plant waterer). The 555 timer drives a solid state relay which powers the electronic door strike.

The RFID reader comes with a master RFID tag which is used to program up to 25 additional tags into the reader’s non-volatile memory. The reader unit can be run from 9 -15 Volts direct current. The reader was modified to light an external LED when a valid RFID tag has been read. This will provide the user with feedback to know if their RFID tag has been read or not.

Instructions on performing this modification to the RFID reader can be found online, or downloaded from the distributor. Any passive 125 kHz RFID tag can be used in this system, and a variety of shapes and sizes are available from online distributors.

The current system also has a 555 timer operating in monostable mode as described in the plant watering section. This holds the door unlocked for ~5 seconds after a valid tag is read that way you don't have to have the tag read and push on the door at the same time to have it open (which got kind of annoying).

The next version will use a parallax RFID reader which returns the actual tag data instead of just a valid pulse. A micro-controller will then either decide if it's a valid tag or forward the tag info onto a computer which will decided if it's valid or not. This will allow me to log who comes home & when and also signal the computer to update the HVAC system based on who is home.

The parallax reader can be picked up for $20-$35 depending on where you look. Here is another instructable dedicated to Atmel chips and this tag reader. Today instead of the MAX232 I'd use either a FT232 so that I could go straight to USB, or a wireless connection like a Zigbee.






Unlock the House With the Phone & RFID: Implemented

F32_DoorStrike.JPG
The RFID enabled electronic door strike was by far the simplest subsystem to design and build. The major components came in preassembled modules that just required interfacing through the appropriate power and signal controls.
Some modifications are also provided from the manufacturer and can be found online from ebay sellers if you get the same system as I did.

The RFID reader hardware has capabilities far beyond what is being used in the stock system. The default setup only provides a low current 12 VDC output to signify the presence of a valid RFID tag. In stark contrast to this the reader is also capable of TTL and CMOS output levels, as well as providing the decoded RFID tag data in a serial format. A reader with these features being used is generally sold for many times the cost of this system.

The RFID tag reader was modified to provide TTL output levels as well as display on an external LED when a valid tag was present. The same power connector used in the previous modules was added to the RFID reader to give it a cleaner look.

A solid state relay that triggers from a 5 VDC input was attached to the system and its output was used to sink current through the terminals of the electronic door strike. A diode was place across the terminals of the strike to prevent current spikes from damaging the strike itself.

 The addition of the 555 timer circuit made it easier to unlock and open the door when the user’s hands are full. The completed subsystem is shown in above.

 All connections made to the RFID reader were kept internal to the reader’s project box and soldering jobs were protected from shorting by a layer of shrink tubing. The results of testing the RFID activated electronic door strike showed a high degree of reliability.

The system only fails to properly open when pressure is applied to the door strikes latch when it is being activated . This pressure is such as would be experienced by attempting to force the door open.

To test the sensitivity of the RFID reader an activated tag was placed within the proper distance of the reader’s antenna and then the path was blocked by various materials. As long as the material did not produce an RF challenged environment (such as a metal ground plane, or a cup of fluid) the RFID reader would respond correctly.







RFID Door Strike Installed

Reader555Install.JPG
ReaderAntenna.JPG
StrikeLocked.JPG
ReaderActivated.JPG
StrikeUnlocked.JPG
The pictures pretty much speak for themselves read the comments on them to get the gist of it. This allows me to leave my door locked all the time, I've only had to use my key once or twice in the past few years to open the door during a power outage.

The first image is tilted sideways, but it shows the system installed out of view inside of a cupboard which is just inside of my garage door.

Make one and your wife will think you're the greatest thing since sliced bread... and I mean who's to argue with that logic. You are!






Additional Subsystems: Security

DoorOpen.JPG
RollerSwitch.JPG
Using the items in the above picture we will make a simple yet effective security system that can tell use when and what doors/windows are unlocked or open and it will even work when the power is out!

Materials:

9V rechargeable battery
9V battery charger
Magnetic reed switch for all doors/windows
LEDs
Resistors (various values
Microcontroller (optional)
Wire







Additional Subsystems: Security

Charger.JPG
DoorOpenSch.jpg
Choosing a charger & battery :

For this step you will need to decide on an adequate battery and charger system. The battery will be plugged into the charger ALL THE TIME and I mean for YEARS! So you will need to choose a charger that has adequate power delivery to power each LED in the system, but has protection built in so that your battery doesn't explode and catch your house on fire. I've seen Ni-CAD work in this design for a long time, but currently I've been using Ni-Mh.

The CHARGER terminals will actually be the power supply for the system 99% of the time, but if power goes out we still want our security system to work. So we leave the battery plugged in and when power goes out the battery is now powering the system. Even after years of use a battery will typically be able to power a few LEDs for a good long while waiting for the power to come back on.






Additional Subsystems: Security

DoorOpenSch.jpg
GarageRelay.JPG
LightSw.JPG
RollerSwitch.JPG
LEDmount.JPG
The circuit is a basic flashlight circuit but on a bigger scale.

The charger supplies power to an LED through a magnetic reed switch (switch turns on and off in the presence/ absence of a magnet). The magnetic reed switch is hooked up so that when a door or window is open the LED will come on. Alternatively as mentioned you can have the output not light the LED and instead have it signal a micro-controller of it's status and let the uC decide what to do about it.

To hook up the system:

1. Choose an inconspicuous place to put the charger and battery. Low traffic areas are best as you will want to leave it on all the time.

2. Mount the reed switches on your doors/ windows/ garage door etc.

3. Mount the LEDs somewhere that looks good. I would suggest using the type of LED mount I included as an image, and they look best when installed in a standard light switch plate just below the switch. (Don't get shocked when removing the plate, turn off the breaker first.)

4. Make the following connections with wire
     a. From the positive (+) terminal of the battery/charger to the NO (Normally Open) terminal of the reed switch
     b. From the the COM (common) terminal of the reed switch to the long leg of the LED and/or micro-controller input.
     c. From the short leg of the LED through a resistor and back to the negative (-) battery terminal

You may not need the resistor depending on how long your wires are run. The wire resistance may be enough to protect the LED itself from drawing too much current. To calculate what resistor you need or if you need one use the following formula:

     (V-Vfd) / I = R

Where V = 9V, Vfd is the forward voltage drop of the LED (~1.2-3V typically), I is the desired LED current (10-15mA), and R is the combined resistance of the wire and resistor. Using the larger of the values I gave here we'd have:

     (9-3) / 0.015 = 400 Ohms

So the combined resistance of your wire and resistor would need to be ~400 Ohms

If you feed the input into a micro-controller be sure you aren't going to have the micro pull too much either, use a 1k resistor between the wire and the microcontroller pin. LEDs are cheap, popping micro's can get expensive.






Additional Subsystems: Security

LightSw.JPG
DLSw2.JPG
DLSw1.JPG
RollerSwitch.JPG
DoorOpenSch.jpg
To check if your deadbolts are locked embed a roller switch at the back of the hole your deadbolt pathway. If you get it just right the bolt will still fully close and just turn off the switch. As soon as the deadbolt is unlocked the switch will be depressed and turn on the LED or signal to the microcontroller what state it is in.

The images I've included have some rolled up paper wedging the switch to be in just the right spot. These have held steady for years.

This will require the NO (normally open) and COM (common) terminal on the roller switch to be used just as it was with the magnetic reed switch.

The next step is a micro-controller board you can use as an alternate interface to either a PC or with a standard TV remote that uses the RC5 IR standard. This is a great board to send these door and window signals too.






Updating the System: IR User Interface

M8Board.JPG
RC5sch.JPG
38kIR.JPG
Here is a board I made to receive RC5 IR commands from a standard universal TV remote. With this interfaced to the other systems I could activate everything without having to leave my couch. This will use a 38 kHz IR demodulator and an ATMega8 microcontroller to do most of the leg work. Here is a parts list:

Materials :

Copper Clad board (perfboard will work too)
7805 Voltage Regulator
1N4001 diode
100uF Cap
0.1uF Cap
22pF Cap x2
10uF Cap x2
10k Resistor
100 Resistor
Push button Switch
1N914 Diode
6 pin two row male header pins
Female header socket or screwterminals.
ATMega8/88/168/328 (Code is for the Mega8 but it is easy to port it over to the others)
38kHz IR reciever

The schematic and board files were done in cadsofts free version of eagle and I believe I got most of the parts from using Sparkfuns library since they are kind enough to let us use these. Thanks Sparkfun!

I've also taken many parts from other places and made a "package type" library (quicker to prototype when I have a new part I may not use again or when I don't want to make a new part in eagles editor). I don't think any of them are in this design but If you come across any let me know and I'll hunt down the parts I used.







Updating the System: IR User Interface Board

RC5_4.jpg
RC5_1.jpg
The next step is to actually build the RC5 IR board. Circuits usually look better when you don't point-to-point solder them (as I've been doing up until this point) unless you've got mad skills .

There are several options for getting a nice looking PCB, you can go to a fab house, chemically etch the board (this method alone has lots of options ). Personally for small batches or one-of's I prefer to mill out a PCB using the eagle plugin PCBgc ode on my homemade CNC machine. (Working on a second, for PCBs only CNC, that will probably be my next instructable since I'm taking lots of pics). This way I don't have to deal with chemicals, or laboriously drill holes by hand either.

If you're setup with a CNC:

1. Download Eagle
2. Download PCBgcode
3. Setup PCBgcode to match your machine specs
4. Open my RC5 eagle board layout file which was available in the last step.
5. Run the PCBgcode URL to spit out code specific to your CNCs setup
6. Lay some copper clad board FLAT to your cutting bit (I prefer a vacuum table that I painstakingly leveled but there are lots of options)
7. Mill out your PCB
8. Drill your PCB
9. Clean the PCB copper with some sandpaper
10. Prepare to solder.

.... gonna have to make an instructable on this process... The links given above should give you most everything you need until I can get one up though. Ask if you haven any questions this alone is a big subject.







Updating the System: IR User Interface Soldered

Front.JPG
Left.JPG
Right.JPG
RC5Bottom.JPG
Solder it together:

I used single sided copper clad for this board instead of double-sided so I had to jumper some wires. I would suggest always soldering in an IC socket instead of soldering the IC directly. This both protects the IC from being damaged from overheating and allows you to swap out the IC for another if you decide to upgrade it later.

Some Liquid Tin would keep the bottom nice and shiny looking, as well as make it a bit easier to solder

I hope the pictures can speak for them selves about the jumpers I made, if not, let me know and I'll give a bit more detail.







Updating the System: IR User Interface Software

Remote.JPG
RemotePackage.JPG
I admit I am not the greatest of coders and would not have half this project built if it weren't for the contributions of may other people. Newton said that he only saw further then other men because he stood on the shoulders of giants. Here are the giants that held me up for the coding on this project:

Peter Fluery : RC5 Decode
Nate Siedel : UART
Joerg Wunsch: iocompat.h

Thanks for all the example code you guys all give back to the community!

I've left a picture of the universal remote that I used for this project, the code contains the hex values for each button press of this remote. Just put in a switch or elseif statment to determine which buttons were pressed and your microcontroller has just gained about 40 inputs! Make them control any of the described sub-systems directly, or feed the input to a computer over the UART through a FT232 (serial to USB converter) and let it decide what to do with them.






Updates: Wireless Triggering & Subsystem Addressing

TxRx.JPG
Xbee.JPG
We don't want to have to run wire everywhere throughout the house to sense if an event occurred. Instead we'll transmit the commands and statuses using some Zigbee radios. This is particularly nice because professional home automation systems, such as Control 4, use these already which should make it easy to interface them with our own custom systems.

A huge collection of data on using these things is available from ladyada's site . She also uses these in her tweet-a-watts which as you probably guessed will be heading the way of this instructable in the future.

Sparkfun also has some cheap 434 MHz transmitters and receivers that look like they could work well pretty easily.






Automatic Triggers & Computer Interface

cSharpLogo.JPG
Lots of the features of this automation system would be nicer if the user could could configure them on the fly without having to reflash a chip. That's where software like the HAL 2000 stuff typically comes in. Or you can just code your own. If you've never coded a GUI before I would highly suggest picking up C#. As my signals professor used to say "SoooOOOOooo Eeeaaasssssyyyy !!!"

You can get C# for free here.

I'm working on a GUI for this in my spare time now, but you'll have to wait for that. In the mean time you can check out this serial terminal made by Noah Coad that I'm basing my UI on: (He gives permission at his site for use of all his code commercial or other wise. Thanks Noah!)

http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx

Basically using the RC5 board as the final interface to the computer, we can take the DTMF signals, pipe them through the RC5 Decoder board, and send them up to the PC. The PC can hold all the special data like valid DTMF codes, or vital decisions to make such as if the garage has been open for a half hour or longer to automatically close it. Sending it's data back down through the serial port the RC5 can transmit wireless data to the appropriate subsystem. This GUI also makes it so you can trigger everything by remote desk-topping into your home computer.

This will be added sometime after I get done with this semester, but the preliminaries are looking promising.

The microprocessor subsystem described before can also enter a lockdown mode if repeated failed attempts are made at guessing the correct code by an unauthorized user. This lockdown mode would temporarily disable the system for a period of time to discourage unwanted users from repeated attempts at accessing various features of the system (like unlocking your front door). This is an example of functionality that will be moved to the computer from the subsystems.







Repurposing the System: GPS Car Tracking

F34_GPS_BD.JPG
F35_GPS_SW.JPG
F36_Robogellan.JPG
F37_GPS_Compass.JPG
It sounds like a big step to change a home automation system to a GPS car tracker... but really it's not. Small tweaks to the system and you can follow your car wherever it goes.

This is something that I’ve always wanted to build/own but the costs of such systems are staggering. At the time of this writing a similar system designed to be end user programmable, affordable, and easily configured was recently released for use in the US. The base cost for this subsystem was over $1500 and all it did was feed GPS latitude and longitude data over a cell phone line. These costs did not include the costs for the cell phone service.

A basic cell phone and a decent GPS reciever can be purchased for less then $50. If purchased in quanties and at the OEM level a competitve GPS car tracker can be built to integrate with the remote home access system for very little cost.

Figure 34: GPS Car Tracker Block Diagram

The block diagram for the GPS car tracker can be seen in in Figure 34. The existing system can be seen on the right hand side, and the new module on the left. The idea is to call the second module from the user’s home. A cell phone will silently auto answer the call and wake up microprocessor #1 seen above. This microprocessor will pole a GPS unit which will return a NMEA string containing latitude and longitude data.

The microprocessor will convert the NMEA string to an X and a Y value to feed to a DTMF encoder circuit. The DTMF encoder will send the X and Y value back through the cell phone to the calling home phone line where it will be decoded by the existing DTMF decoding system. The decoded X and Y value will be displayed on the LCD screen mentioned above. New X and Y values will be sent automatically back to the calling line until the phone call is disconnected. The software flow diagram seen in Figure 35 illustrates this process.

Figure 35: GPS Car Tracker Software Flow Chart

While it seems like a big leap from home automation to GPS car tracking it isn’t much more then what has been done so far. The GPS decoding module has been built for a Robo-Magellan mobile robot in another project and will easily interface to the existing system because both were designed to run on the Atmel AVRs. A picture of the robot using GPS and a variety of other sensors can be seen in Figure 36.

Figure 36: Robo-Magellan Robot

The only component that hasn’t been built is the DTMF encoder circuit but there are many chips available for just such a thing (Like the HT9200 ). A DTMF encoding sister chip to the CM8870 has been obtained and testing will begin on it this summer.

Another sensor that has been interfaced with the Robo-Magellan robot that would be of use in this subsystem is the HMC6352 digital compass. Using DTMF to relay GPS and heading data to a remote location can be used to tell not only where in the world the vehicle is, but also in which direction it is heading. Some of the potential uses for this system include finding a stolen or misplaced vehicle, keeping tabs on company property, and tracking taxis and buses along their routes. The information that this system can provide would be useful for validating claims and determining the outcomes of issues taken to court.

The GPS receiver is a Rand McNally product with RS-232 output. Many comparable receivers can be obtained for around $20 on the internet. The compass was $55 (the sure dont cost that now) and obtained from Sparkfun Electronics . Figure 37 is a photograph of the GPS receiver and the digital compass being used on the Robo-Magellan robot.

Figure 37: GPS Receiver and HMC6352 Digital Compass on a Robo-Magellan Robot

This subsystem can be exceptionally useful as an automatic trigger for the home automation system. If traveling home from a long trip the system can be polled to detect the distance left until a person arrives. Depending on which vehicle was detected a variety of other subsystems can be controlled. Temperature and other predefined settings can be set based on a predicted arrival time. This way the user’s home will be just the way they like it as soon as they arrive.








Final Words

Arduino.JPG
Head.JPG
I've got more details on the build and other projects I've worked on at my website . It's quite old though I haven't updated it in years, and the time before that last update was a few years as well so I've got plenty more to post here to the wider community... now if I can only find more time.

I've tried to give all credit to people that inspired or helped this project along in any way. If you think I've left anybody out let me know and I'll gladly add them.

If you liked this instructable please vote for it in the 3rd Epilog Challenge and in the Makerbot Challenge.

If I were to win the laser engraver and after engraving everything I could fit inside the machine I would be most immediately excited about using it to cut out solder stencils for surface mount soldering, making custom engravings on knife handles for the boys in my scout troop, cutting out gears, making project enclosures, bootstrapping a business.... to tell the truth I'm not sure what I wouldn't do with a laser engraver... okay so hottubbing is right out !

If I were to win the Makerbot, I would probably download and print half of Thingiverse . Then I'd look into purchasing a copy of David Laser Scanner and printing out my head to replace those pommels that are at the bottom of stairway banisters. Then I'd see about making a 3d puzzle of a brain based on the scans taken from an MRI.

I can't shake the feeling that I'm leaving something out of this instructable..... So here a picture of an Arduino.... you know just for blog cred ;)

Good Luck all it was fun!