This demo is designed to help you understand how you can control a door using your Parallax microcontroller. This is part 1 of a 2-part series designed to show door control using various types of motors and limit switches.
In this part of the demo, we use a continuous rotation servo under the control of a BASIC Stamp 2 microcontroller to open/close a door with optical limit switches. These sensors detect when the door is in the open or closed positions.
The concepts presented here could be used to control a pet door, the door on a chicken coop, or in any similar system where a door needs to move from one position to another under automated control. Because this demo version uses a gravity sliding door, no downward force is exerted, making it safer for use around animals.
The parts below were used in the making of the specific unit shown in the images. The list provided is meant to be a suggestion of which parts may be required if you intend to replicate this demo in part or in full. The laser cut panels are custom-designed and not included in the parts list.
Download the Schematic:
I didn't do a step-by-step build for this demo because it is intended to introduce the underlying principles, not be recreated exactly as shown. A PDF download of the demo schematic, however, is available by clicking the link above. Mainly I wanted to keep things simple so you can take this knowledge and apply it to your specific application, since the details and requirements of individual applications are always unique. Because I didn't have a ready-made project on which I could demonstrate all three methods, I decided to break things up into three related demos. Each part covers one of three different, but handy, methods of automating door motion (Servo, DC Motor and Stepper Motor) and one of three methods of detecting the door-position limits (limit switch).
My friend and Parallax colleague Matt Gilliland built me these special laser-cut panels so that I could realize this project in a demo format. We stuck to a simple gravity sliding-door system that could be used for all three examples.
The control board and drive motor are at the top of the unit.
The power source is our Lithium Ion battery pack (designed by Matt), and I used a couple of momentary push buttons for control with a bi-color LED for status indication.
The door slides up/down within the frame with gravity pulling it down and the servo motor pulling it up. The limit switches are optical, which means they're based on light; specifically whether light is detected or not. Since we're using phototransistors that are sensitive to a wider range of light frequencies than just infrared, I shielded them from as much ambient room lighting as was possible with this demo design. The phototransistors are mounted on the back of the unit, recessed into the plastic. The IR LEDs are mounted on the front in the same fashion.
If you're using tact switches, you can connect those and the LED to the breadboard on your Board of Education (If that's the board you're using) and the LED as well.
Download the source code:
Source Code for Door Control [2]
For testing purposes I just wrote a DEBUG line that displayed the binary representation of the input signals from the switches and phototransistors. BASICally I just used the following line of code:
DEBUG HOME, BIN Open, BIN Close, BIN Opened, BIN Closed
With this line running in a loop you should see four 1's and/or 0's on your DEBUG terminal. The first two should be 1's unless a button is pressed, then the corresponding bit should become a 0. On the phototransistors you should see a 0 unless the door is interrupting the beam, which is your indication that the IR sensor has detected object blocking the beam. If you're not seeing a 1, but there is no object to interrupt the beam, you can verify your IR LEDs work by simply looking at the sensor with a camera. Your eyes may not be able to see IR light, but the camera in your smart phone, digital camera or camcorder can see it.
If the LED colors are backward you can either reverse the LED, or if it's soldered in you can change (reverse) the pin constants. Additionally, remember that on the Board of Education the switch must be in position 2 for the servo to get power.
On power-up the door will either be open or closed. If it is in between the program will close it automatically. At this point, pushing the Open button opens the door and sets the status LED light to green.
Pressing the Close button closes the door and sets the status LED light to red. If the door is already in the opened or closed position the corresponding button will have no effect. Also, if the door is already being opened/closed you cannot reverse the direction of the door until it reaches the limit switch. This effect can be altered in the code, if desired.
Note that on power-up, the LED status is off until a button is pressed and the door reaches that position limit.
On power-up the code initializes the servo I/O pin, then checks to see if the door is only partially opened or closed by observing that both limit switches are low (0). If this is the case, the Door_Close subroutine is called. Typically the code runs in a loop where you can be doing other things until either the Open or Close button is pressed.
Once a button is pressed the code jumps to that subroutine where it sits in a loop checking to see if the door is in the destination position. If it is, the loop exits, the LED is set to the correct color and the subroutine returns to the main loop. Within the loop the limit switch is checked and then the servo is refreshed, followed by the 20 ms delay required by the servo. This continues until the limit switch goes high (1) causing the code to exit the loop.
The code for this demo was intentionally kept as simple as possible for easy integration into an existing application or to be used as part of a more complex program.
The limit switches work as an IR beam-break system with the IR LED always powered and shining onto the phototransistor. When the door reaches either end position it interrupts the beam causing the phototransistor to no longer be biased. When this happens the 10K pull-up resistor causes the line to go high. When the IR light is shining on the phototransistor it causes the line to be pulled low. The push buttons are also active low in that pressing them causes the I/O pin to be shorted to ground. When the switch is open the I/O line is pulled to 5V via a 10K pull-up resistor.
While the IR LEDs are always on (typical of a beam-break system) you could save a little power by having the IR LEDs only power on during door motion. This would require the use of two additional I/O pins, however.
Stay tuned for Part 2!
Links
[1] https://learn.parallax.com/sites/default/files/Files/Docs/Projects/Door-Control/1/Door-Control-Part-1-Schem.pdf
[2] https://learn.parallax.com/sites/default/files/Files/Docs/Projects/Door-Control/1/Door-Control-Part-1-Code.zip