I'd like to be able to measure the position of my garage door. Determining if the garage door is fully open or fully closed should be fairly simple with some magnetic reed switches but I'd like to know the position of the door when it's partially open/closed.
A couple of possibilities occur to me. One would be to mount a rotary encoder on a rotating part of the door. Another would be to attach a reed switch to the track and a series of magnets to the door. I suppose you could do something with a proximity sensor as well.
How much precision do you need in the position of the door? What do you know that is deterministic? For example is the door transit time predictable? Is it a positive drive? Do you get to know when the door starts moving? That might be enough right there.
If you can say more about what you're trying to do it would make it easier to provide suggestions and insight.
A linear encoder (usually comprising an LED, a photodetector, and an encoder strip with black lines on it) would work, but a long encoder strip is expensive and probably not reliable a garage environment. You could use a radial encoder attached to the motor, but that is probably too expensive too and overkill for your application.
Ranging devices are often difficult to use with something narrow and dirty like the bottom edge of a garage door. Placing devices on the door itself is probably not the most reliable and inexpensive way to do this either.
A Solution for Any Large Spring Loaded Position Sensing
One way that can be very reliable and is inexpensive is to use two strain gauges. In spite of the low cost, this approach is used in many industrial and laboratory arrangements. You could use an IN114 or a similar 8-pin dip instrument amplifier to convert the differential strain gauge resistance to a Voltage within the range of the Arduino analog input.
I'd guess a cost around $100 with shipping for the IN114, the rest of the circuit, strain gauges, emery cloth, bonding cement, temperature sensor (optional), power supply, jacks, solder, circuit housing, PCB breadboard, and cabling.
You will need to use a Wheatstone bridge at the + and - input of the instrument amp. There are plenty of example circuits. Search for, "instrument amp wheatstone bridge strain gauges," to get some schematic diagrams.
An adjacent two of the four legs of the Wheatstone bridge are the two strain gauges. One of the other two legs would be a potentiometer in series with a fixed resistor to give you offset adjustment. Another potentiometer adjusts gain. The IN114 spec sheet shows how to set the gain and how to power the chip.
Mechanically, the strain gauges would go on opposite sides of the exact same point on the spring, near where it attaches to the stationary frame to which the tracks are mounted. One strain gauge must be bonded to the inside of the spring. The other to the outside, directly opposite the inside one through the thickness of the spring wire. This will allow the Voltage you measure to indicate the strain on the spring which is related to the position of the door.
(The image at http://recordtek.com/sites/default/files/Gauge-spring.png shows a strain gauge bonded to the outside of the spring. The inside complement would go directly underneath it on the inside.)
I'd recommend an Arduino Due to read the output voltage of the IN114, setting the gain and offset to stay within the 1.55 to 2.75 V range of the analog inputs of the Due for all garage door positions. That will take some trial and error with a Voltmeter before you connect the Due.
To calibrate the system, the analogRead() values for ten somewhat equally spaced garage door positions are placed in an array of integers. Another same size array of doubles receives the corresponding door positions in whatever units you want. These can be static arrays that are initialized in your Arduino code.
You would get the position from the analogRead() at any point in time by interpolating the data in the table represented by the two corresponding arrays. That is easier than it sounds. There are articles explaining how and libraries providing linear interpolation in C, some of which may be usable without modification in an Arduino sketch.
Bonding the Strain Gauges
There are many articles available on using strain gauges and how to rigorously clean the surface and position and orient the gauges before bonding them to the metal of the spring. That's critical. They have to point in a particular direction, and the bond will come apart if you don't clean the metal well enough, which would not be good.
Going High End
If you wanted high accuracy, you could enhance your design to possibly get three or more significant figures as you reach expert level.
- Read and factor in temperature when doing the interpolation
- Take more than 10 calibration samples and use larger arrays to match
- Use a quadratic or cubic interpolation instead of linear
- Write a calibration algorithm to fill the two arrays with new values automatically every time the door goes from one extreme position to the other