building a pic controller for an aladdin light lift

24
1 Building a PIC Controller for an Aladdin Light Lift® By Roy Seifert Introduction As with many new two-story homes built today, my home came with an open, two-story entryway/foyer. At the top of the entryway, about 16 feet above the ground, is a hexagonal brass and glass light fixture. At the time I looked at the new model homes my first thought was, “Who is going to climb up there to change a bulb and clean the glass?” Although I don’t have a fear of heights, I have a fear of ladders – falling off of them that is! So I started looking around to see if someone had something to keep me from having to climb a ladder. Figure 1: Aladdin Light Lift® A visit to a local lighting store introduced me to the Light Lift® manufactured by Aladdin Light Lift Inc. There were other, less expensive light/chandelier lifts on the market, but the Light Lift® had a longer cable, and did not reel the electrical cable with the lift cable. This allowed the Light Lift® to use a single, longer, non-electrified cable. The light was connected to a circuit board that broke electrical contact when the light was lowered from the ceiling. Since there was no AC power on the lights when lowered it was much safer for the user. When the light was raised back into the ceiling, contact was made with the circuit board so the lights worked normally. I called around town to all of the lighting companies I could find in the yellow pages and found a distributor willing to sell me a Light Lift® at wholesale! Apparently they weren’t selling and he wanted to get it out of his inventory. So I carried it around in the back of my car for 2 weeks until I closed on my house, and then installed the unit myself.

Upload: allprocom

Post on 02-Oct-2014

87 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Building a PIC Controller for an Aladdin Light Lift

1

Building a PIC Controller for an Aladdin Light Lift® By Roy Seifert

Introduction As with many new two-story homes built today, my home came with an open, two-story entryway/foyer. At the top of the entryway, about 16 feet above the ground, is a hexagonal brass and glass light fixture. At the time I looked at the new model homes my first thought was, “Who is going to climb up there to change a bulb and clean the glass?” Although I don’t have a fear of heights, I have a fear of ladders – falling off of them that is! So I started looking around to see if someone had something to keep me from having to climb a ladder.

Figure 1: Aladdin Light Lift®

A visit to a local lighting store introduced me to the Light Lift® manufactured by Aladdin Light Lift Inc. There were other, less expensive light/chandelier lifts on the market, but the Light Lift® had a longer cable, and did not reel the electrical cable with the lift cable. This allowed the Light Lift® to use a single, longer, non-electrified cable. The light was connected to a circuit board that broke electrical contact when the light was lowered from the ceiling. Since there was no AC power on the lights when lowered it was much safer for the user. When the light was raised back into the ceiling, contact was made with the circuit board so the lights worked normally. I called around town to all of the lighting companies I could find in the yellow pages and found a distributor willing to sell me a Light Lift® at wholesale! Apparently they weren’t selling and he wanted to get it out of his inventory. So I carried it around in the back of my car for 2 weeks until I closed on my house, and then installed the unit myself.

Page 2: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

2

Control Panel

Figure 2: Homemade Control Panel

The control panel that came with the unit had a single (on)-off-(on) key switch (the parenthesis indicate momentary contact). This switch required that I continuously hold it in one position or the other to keep the unit moving. I can guess that this was to prevent the user from walking away and having the light lower too far. Unfortunately, the key switch was faulty – it only worked in one direction; but with a few dollars and a trip to Radio Shack, I purchased the parts I needed to make my own control panel and it’s been working for 12 years! It consisted of an on-off key switch to prevent accidental use, and an on-off-on toggle switch for up and down. The toggle switch connected common to either the up or down wire, but I didn’t have to hold it while the unit was moving. The original control cable and control panel came with interlocking connectors, but I replaced them with Radio Shack 4-pin connectors 274-224 and 274-234. 5-Second Delay The owner’s manual that came with the Light Lift® stated that I needed to wait a minimum of 5 seconds before reversing the motion of the lift. This was to prevent causing problems with the motor, brake, and pulley system. I’m really the only one who ever operates the unit; but what will happen if I sell the house? Most people won’t take the time to read the instructions and could possibly damage the unit; especially realtors showing the house. Fast-forward 12 years to the present. I have started learning about programming PIC microcontroller units (MCU) as a hobby so I decided I wanted to program the 5-second delay into a microcontroller to prevent a quick reverse. Light Lift® Smart Controller I was browsing the Aladdin web site and found that they manufacture a programmatic controller that not only prevents the quick reverse of motion, but it also allows the user to program it so the light always lowers to the same location every time. The price for their unit was $99.00, but I was able to manufacture my own for less than half that amount. My controller doesn’t work exactly the same as the Aladdin unit, but it does perform the following functions:

• LED’s indicate when ready to operate and other status. • Lower the light down from the ceiling with one press of a toggle switch and indicate down

motion. The toggle switch does not have to be held down.

Common

Page 3: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

3

• Raise the light up to the ceiling with one press of a toggle switch and indicate up motion. The toggle switch does not have to be held up.

• Indicate when the light gets to the home (ceiling) position and automatically stop up motion. • Force a 5-second delay before allowing a change in direction. • Load default duration which was 2 1/2 minutes for my house. I use this feature to restore the 2

1/2 minute duration for my house in case I change the programmed duration. • Program default duration. Normally this should never change, but I made it somewhat universal

so others could use it. • Program duration for lowering the light. • Cancel or change the programmed duration. • Ignore the programmed duration. • Remove power from the controller with a key switch when not being used. This both saves

power and prevents accidental use. Reading the instructions for the Aladdin controller, my guess is that their controller is always powered on, but requires a button press/sequence for it to “wake up” from sleep mode. I decided I didn’t want my MCU powered on all the time. I attended a computer technology school right out of high school to learn how to fix large-scale mainframe computers, and worked at that occupation for 11 years. During that time I taught myself programming, so between my computer, electronics, and software background, I felt this project was well within my capabilities. PIC Microcontroller Programming

Figure 3: EasyPIC6 Development Board

Searching the Internet I found mikroElektronika, a company in Serbia that produces both the hardware and software that I needed to program the microcontroller. The EasyPIC6 development board they manufacture allows me to program many different PIC microcontrollers, and contains the circuits to develop and test LED’s, LCD graphical and character displays, switches, one analogue to digital

Page 4: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

4

converter (ADC) and various interfaces. It also contains a port expander and access to the microcontroller’s ports via header pins. The software that comes with the board contains examples designed for the PIC16F887 microcontroller, and the board comes with one of those microcontrollers. What a great tool for developing different applications! I used this board with its switches and LED’s to develop and test my controller. Software MikroElektronika allows you to download trial versions of each of their compilers. Assembly language is a bit cumbersome for me, I know nothing of Pascal, I know some C language, but I am very fluent in BASIC, so I decided to purchase their MikroBASIC Pro compiler for PIC. Microcontroller

Figure 4: PIC16F688

A microcontroller is essentially a computer in a small, integrated circuit package. It has all the capabilities of a larger computer, but with less capacity. A microcontroller is normally programmed to perform one function, rather than many functions. Microchip Technology Inc., a manufacturer of microcontrollers, publishes a selection guide for choosing the right microcontroller. I chose the PIC16F688 for the following reasons:

• Small footprint, 14-pin DIP • At least three pins had weak internal pull-up. These would be used for the switch inputs. • 7 output pins, 5 for LED’s, (Ready, Home, Up, Down and Program) and 2 to drive reed relays

connected to the Light Lift®. The reed relays take the place of the toggle switch in my original control panel.

• EEPROM for storing duration. This was an important feature since I didn’t want the duration to be erased when the microcontroller was not being used and powered off.

I am using just a small percentage of the capabilities and capacity of this MCU, but it only cost $1.62.

Page 5: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

5

Hardware

A

B B

C C

D D

1

1

2 3 4

4

5

5

Title: Lite Lift Controller - Home

Rev: 6.01 Eng.: Roy SeifertSheet: 1 of 1Date: 2010.09.01

Up Sw

Down Sw

Ready Green LED+

Home Sw

Home Yellow LED+

Up Blue LED+

Dn Orange LED+

Pr Red LED+

Lite Lift Up - Red

Lite Lift 16VAC - White

Key Sw

K1

K2

Key Sw

Lite Lift Down - Green

21

1

4

4

3

3

2

Lite Lift Common - Black

GND

Home Sw

C3.1uF

IC2PIC16F688

VDD +5

RC5

1

5

2

6

3

7

4 11

8

12

9

13

10

14

RA5

RC4

RA4

RC3

RA3

VSS GND

RA0

RC0

RA1

RC1

RA2

RC2

R1 220

R2 220

R8 120

R3 220

R7 120

R4 47

R5 120

R6 137

2 3

D11N4005

C2.1uF

C147uF

IC1LM7805

A

1

2

12

10

8

14

4

6

16

3

15

5

13

7

9

11

Black - CommRed - UpGreen - DownWhite - +16VAC

Light Lift Cable

Up Sw 1 2 LL 1616-Pin Header

4 GND6 Home Sw8 Key Sw10 Key Sw12 LL Comm14 LL Up16 LL Down

Dn Sw 3Home Sw 5

Up Blu LED + 7Dn Org LED + 9

Pr Red LED + 11Hm Yel LED + 13

Rdy Grn LED + 15

Key Sw

GND

S1 Key Switch

S2 Toggle Switch

Switch Plate

D2 Green

D3 Blue

D4 Orange

D5 Red

D6 Yellow

Up

Down

LED+

LED+

LED+

LED+

LED+

Key Sw

Figure 5: Light Lift® Controller Schematic

It turns out that there is a fourth wire in the control cable that comes from the Light Lift®. This contains a full wave rectified, 26 VAC that comes from the unit. In the above schematic I take that 26 VAC, feed it through an isolation diode D1, filter it with C1, and feed it to IC1 an LM7805 +5-volt regulator. This provides the power for the PIC MCU. The key switch S1 disconnects common from the circuit, thereby disabling power when not in use. Since timing is not so critical I decided to use the internal 8MHz clock of the microcontroller to save a few cents on components. I chose different colored LED’s to indicate status as follows:

• Green – Ready. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 – 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain)

Page 6: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

6

• Blue – Up. This LED required 3.9 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 47 ohm resistor. (4.7 – 3.9 = .8, .8/.02 = 40 ohms; 47 was the closest I could obtain)

• Orange – Down. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 – 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain)

• Red – Program mode. This LED required 2 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 137 ohm resistor. (4.7 – 2 = 2.7, 2.7/.02 = 135 ohms; I was able to obtain a 137 ohm resister)

• Yellow – Home position. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 – 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain)

Notice that most of the current limiting resistors I am using for the LED’s have a slightly higher value than what was required. This helps to ensure that the LED runs at lower than maximum current so the LED’s should last longer. R1 – R3 are static protection for the input to the MCU as recommended by numerous documents published by Microchip Technology Inc. K1 and K2 are 5-volt reed relays with a built-in diode. I used a dual row, 72-pin header strip that I cut to make the 16-pin header; 2 rows of 8 pins. I purchased most of the parts I needed from Mouser Electronics and Radio Shack. A list of parts can be found at the end of this article. Radio Shack no longer sells the key switch I purchased 12 years ago, so I purchased one from Mouser. This turned out to be the most expensive component of my controller. Firmware As mentioned before, I used the EasyPIC 6 development board with its integrated switches and LED’s to develop the firmware. I designed the firmware so that when the PIC is first powered on the LED’s flash in a sequence then the green Ready LED stays on indicating the controller is ready. I used a center-off, momentary contact rocker switch to initiate motion. It turns out the rocker switch was not the best solution, so I replaced it with a momentary toggle switch; more about this later. Press the toggle switch up to move up (the blue Up LED comes on), or press it down to move down (the orange Down LED comes on). Another press of the toggle switch stops the motion, the corresponding motion LED shuts off, and the green Ready LED blinks for 5 seconds. This 5-second delay prevents initiating a quick reverse and possibly damaging the Light Lift®. When the green Ready LED stops blinking motion can again be initiated. When the light reaches the ceiling a Home LED comes on and motion stops automatically. Holding the toggle switch up or down when the controller is first powered on causes all of the LED’s to come on and the default duration is loaded from the EEPROM. Pressing the toggle switch up or down allows the controller to go ready. To enter program mode, press and hold the toggle switch up or down for 3 seconds; the Program LED comes on. In program mode the user can perform a number of functions:

1. Program duration – press and release the toggle switch down; the light moves down. When the proper height is reached, press and release the toggle switch down again to stop motion. The duration is stored in EEPROM memory and the unit will stop at the same location every time.

Page 7: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

7

2. Program default duration - press and release the toggle switch down; the light moves down. When the proper height is reached, press and release the toggle switch up to stop motion. The Program LED blinks for 3 seconds. Press and release the toggle switch up within the 3 seconds; the duration is now the default duration and is stored in EEPROM memory. If the toggle switch is not pressed within the 3 second duration, no changes are made to the memory.

3. Delete program duration – press and release the toggle switch up. The program LED shuts off and the programmed duration is removed from the EEPROM memory.

4. Exit program mode – press and hold the toggle switch up or down for 3 seconds. This exits program mode without making any changes.

Once duration has been programmed, when the light is moving down it always stops at the programmed duration. When the light is moving down, holding the toggle switch up or down for 3 seconds causes the controller to ignore the programmed duration. I discovered that it takes exactly 2 1/2 minutes for my light to reach a suitable height, so I programmed the MCU with that default duration. However, this default duration can be changed for other users. I have included a copy of the BASIC code at the end of this article. Home Switch In the junction box at the top of the ceiling are two switches used to stop the motor when the light reaches the top. Only one switch is used; the other is a backup. I attached two wires to the common and normally open connectors of the spare switch and ran that cable to the junction box for the control panel. These two leads are tied to RA4 input of the MCU and ground. Sensing the home position shuts off the up reed relay when the light is moving up. PCB

Figure 6: Light Lift Controller PCB

I found a PCB design program on the Internet called Abacom Sprint Layout 50. Figure 6 shows my PCB design for the controller. I used red to indicate the outline of the components to ensure they would fit on the board and not interfere with each other. This board is fairly small, only 1.5” x 2” so it will fit into a single-gang outlet box. I decided to make the installation modular by using a 16-pin header to

Page 8: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

8

connect a ribbon cable to the board. I connected the ribbon cable to the LED’s, control panel switches, and the Light Lift® and home switch plugs. There are a number of methods for producing PCB’s at home. The key to the process is being able to transfer the artwork onto the copper board in preparation for etching. I don’t have a laser printer so the iron transfer method wouldn’t work for me. Another method is to make a silk-screen stencil, but I didn’t want to spend the $20 for two sheets of stencil, and whatever it would cost for the proper paint. Plus, since this method was new to me, I didn’t want to spend the extra money to experiment, learn and possibly make mistakes. I’ve had good luck in the past with photo-sensitive boards so I decided to go with this method. I purchased a positive photo-sensitive board and the developer solution from Mouser. I probably should have purchased 2 boards in case I messed one up, but I was on a tight budget for this project.

Figure 7: PCB Artwork

The photo-sensitive PCB I purchased was 3” x 5”. I cut it so I could produce my board and still have some unexposed board left in case I made a mistake. The heavy green section at the bottom in the above figure did not get etched; this allowed the etching process to complete quicker. It also allowed me to attach the artwork to the PCB with a piece of tape on this area folded under the board. I first printed a mirror image of the PCB etch side on 3M transparency CG3480. This transparency is specifically designed for use with ink-jet printers. My artwork printed heavy and sharp. Following the instructions that came with the board, I laid the artwork print side down (which is why I had to print a mirror image) onto the sensitized side of the board, attached it with a piece of tape, and covered it with a piece of glass I removed from an old picture frame. I positioned it five inches below a florescent light and exposed it for 10 minutes, then placed the board into the developer solution I diluted with ten parts cold tap water. I constantly wiped the board with a foam brush I purchased from my local hardware store. The development process took about 6 minutes. After the board was developed I washed off the excess developer in running tap water; now the board was ready to etch.

Page 9: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

9

Figure 8: Etched PCB

I purchased a bottle of PCB Etchant Solution from Radio Shack #276-1535, and using a glass tray, etched my circuit board. This process took about 16 minutes to remove the excess copper. I used a hair dryer to warm the solution and keep it moving over the board which sped up the etching process. Ok, so now I had to drill the holes for the components. I am fortunate to have a MAXNC 10 CL CNC hobby mill that I use for fabricating parts. Abacom Sprint Layout 50 allows me to export all of the component holes as a plotter file which I import into my CAD/CAM program, BobCAD-CAM V20, and use to drill the holes in the board.

Figure 9: Corel Draw® Plot

It’s actually not quite that easy. I first imported the plotter file into Corel Draw® 12. Each of the holes gets imported as a node. I then connected two nodes with a line. BobCAD-CAM V20 doesn’t recognize the nodes if I import the plotter file directly, but it does recognize the lines I created with Corel Draw® 12.

Page 10: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

10

Figure 10: BobCAD-CAM Drilling

Next I exported the lines to a drawing file, which I then imported into BobCAD-CAM V20. At the end of each line I placed a point; each point became a hole location which I programmed with the CAM portion of the software. In the above figure you can see the points and lines on the left, and the resultant “G” code drilling instructions on the right.

Page 11: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

11

Figure 11: Drilling PCB Holes

I purchased a circuit board maker kit from Drill Bit City that contained the correct size bits I needed to drill the component holes. I drilled holes in the corners of my board and mounted it to a piece of wood using screws. Using my MAXCNC 10CL mill and the CAM program I created I drilled the component holes in the circuit board.

Figure 12: Completed PCB

Once the holes were drilled I cut off the bottom and populated it with the components I purchased from Mouser. I mounted a 14-pin DIP socket onto the board so the MCU wouldn’t be permanently installed in case I needed to reprogram it. I put some heat-shrink on the LM7805 to insulate it, and also on the back of the board to prevent the solder pads from shorting against the metal body of the key switch.

Page 12: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

12

Control Panel

HOME

Figure 13: Control Panel Design

I used Corel Draw® 12 to design the layout of the control panel as shown in Figure 13 above. It was designed to fit onto a blank wall plate cover. I exported the design to my CAD/CAM software and created the milling file for the cutouts.

Figure 14: Control Panel

Using my MAXCNC 10CL mill, I used a 3/32” square end bit to mill the cutouts. Even though I used my hobby CNC mill, I could have done the same thing with hand tools; I’ve done it before. I printed the

Page 13: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

13

text on adhesive labels, cut them out, then applied them to the panel. I sprayed a coat of clear lacquer onto the plate to protect the labels. Wiring Harness

Figure 15: Wiring Harness

After the panel was milled I created a wiring harness to connect the individual components. I connected the wires from the ribbon cable to the appropriate hardware as shown in the schematic. To make it modular and easy to replace components I used plugs and connectors where possible. For the key switch pins I used two female pins from a Radio Shack 274-234 connector and covered them with heat shrink tubing. The lens for each LED socket snaps on making it easy to install and remove from the panel. I left the up and down wires off of the Light Lift® plug for testing purposes. I didn’t want the unit to move during testing.

Page 14: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

14

Figure 16: Completed Light Lift® Controller

As mentioned before, my original design used a rocker switch, but pressing on the rocker switch caused the plastic panel to crack and eventually break. I decided to use a 3-position toggle switch with up and down momentary contact, and center off. With a toggle switch, pressure is placed vertically on the plate, instead of horizontally, which should prevent the plate from cracking and breaking. I plugged in the control panel to the Light Lift® cable, turned on the light switch, turned on the key switch, and to my relief, the LED’s went through the ready sequence so that the green Ready LED stayed on. I tested all of the controller functions to make sure everything worked correctly. This was a good thing because I hadn’t really bread-boarded or tested the circuit. Finally, I turned off the power, installed the up and down pins into the controller interface plug, connected the home switch, and turned on power for the final test. The Light Lift® moved up and down as it should and I was able to program the duration. Now, whenever I lower the Light Lift®, it always stops at the same location so I can clean the glass and change a bulb. Instruction Card I printed a small instruction card using heavy card stock. I laminated the card using press-on adhesive laminate, and installed an eyelet on the card. I then installed this card onto the key ring that came with the keys for the key switch. Now anyone operating the controller will have access to the instructions. I have included a copy at the end of this article. Summary This project required a number of processes in order to complete:

• Program a microcontroller • Design the circuit • Fabricate the circuit board

Page 15: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

15

• Fabricate the control panel • Install all of the components

I lower the unit maybe once every six months to clean the glass, but there is no power applied to the controller when not in use, so depending on the life of the individual components, this controller should last for years before requiring any maintenance. Hopefully it adds to the resale value of my home, not to mention I have the pride of designing and building a nifty little project. The advantage to using a DIP socket on the circuit board was that I could remove the MCU whenever I needed to upgrade the firmware. Since writing this article I have made two improvements to my initial program, which I have loaded into the MCU. I also added a short routine to blink the green Ready LED based on the firmware revision number. I am currently up to revision #2. Parts List The following table contains the list of parts I purchased for this project. Capacitors and resistors are so inexpensive that I usually purchase in quantities of 5 so I have spares on hand for other projects.

Source Ref Part # QTY Description Mouser C1 140-XRL10V47-RC 1 Aluminum Electrolytic Capacitors - Leaded

10V 47uF 20% Mouser C2, C3 581-SR215C104K 2 Multilayer Ceramic Capacitors (MLCC) -

Leaded 50volts 0.1uF 10% X7R Mouser D1 625-1N4005GP-E3 1 Rectifiers 1N4005 Vr/600V Io/1A Mouser D2 78-TLHG4400 1 Standard LED - Through Hole Green Tint

Diffused Mouser D3 78-TLHB4400 1 Standard LED - Through Hole Blue Tint

Diffused Mouser D4 78-TLHO4400 1 Standard LED - Through Hole Orange Tint

Diffused Mouser D5 78-TLHR4400 1 Standard LED - Through Hole Red Tint

Diffused Mouser D6 78-TLHY4400 1 Standard LED - Through Hole Yellow Tint

Diffused Mouser IC1 512-LM7805CT 1 LM7805 Positive Voltage Regulator 1A Mouser IC2 579-PIC16F688-I/P 1 PIC16F688-I/P MCU Mouser K1, K2 816-9007-05-01 2 Reed Relay 1FORMA 5V W/DIODE Mouser R1, R2,

R3 291-220-RC 2 Carbon Film Resistors - Through Hole

220ohms Mouser R4 660-CF1/4C470J 1 Carbon Film Resistors - Through Hole

47ohms 5% Mouser R5, R7,

R8 71-CCF07-G-120 2 Metal Film Resistors - Through Hole 1/4watt

120ohms 2% Rated to 1/2watt Mouser R6 660-MF1/4DC1370F 1 Metal Film Resistors - Through Hole 137ohm

1% 100PPM Mouser S1 633-CKL12BTW01-

042 1 Keylock Switches 19MM ON-ON RMVE

1POS TUBE KEY#042 3A LUG

Page 16: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

16

Mouser S2 642-637NH2 1 Toggle Switch SPDT (ON)-OFF-(ON) Mouser 593-1700C 5 LED Lenses Clear Fresnel Lens Cliplite 3mm Mouser 593-CNXBX4108 5 LED Mounting Hardware T1 2-Lead LED

Con 8 Mouser 590-603 1 Prototyping Products 3x5 Copper Clad Bd

presensitized 1/16 Mouser 590-418-500ML 1 Chemicals Developer 600 series Mouser 649-67997-472HLF 1 Headers & Wire Housings 72P HDR – 2 Row Mouser 164-9008-E 1 Headers & Wire Housings IDC SOCKET 16

PIN W/STRAIN RELIEF Radio Shack 274-224 1 4-Position Male Polarized Connector Radio Shack 274-234 2 4-Position Female Polarized Connector Radio Shack 274-222 1 2-Position Male/Female Polarized Connector Radio Shack 278-1610 1 Multicolor Heat-Shrink Tubing (12-Pack) Radio Shack 64-4039 1 Female Crimp-On Quick Disconnects (10-

Pack) Radio Shack 276-1535 1 PCB Etchant Solution Drill Bit City

301-R8WSFBRB 1 Circuit Board Maker Kit

Page 17: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

17

BASIC Code ' * Project name: ' Light Lift Controller Home ' * Copyright: ' (c) Roy Seifert, 2010 ' * Revision History: ' 20100901: ' - initial release; ' 20100907 ' - Version 2 ' Pressing the toggle switch up while in program mode stores the duration ' in the default location. ' * Description: ' This firmware provides programmatic control of the Light Lift. It provides ' an automatic 5-second delay when reversing the direction of the Light Lift. ' The duration of down motion can be programmed and is stored in EEPROM so ' the unit stops at the same position every time. Up motion stops when the ' home switch is activated. Since the internal pull-ups are enabled the ' switch input is 1 for off, and 0 for on. LEDs indicate the status of the ' controller. ' ' * Test configuration: ' MCU: PIC16F688 ' http://ww1.microchip.com/downloads/en/DeviceDoc/41203E.pdf ' Dev.Board: EasyPIC6 ' http://www.mikroe.com/en/tools/easypic6/ ' Oscillator: Internal 8.0 MHz ' Ext. Modules: None ' Software: mikroBASIC PRO for PIC 4.1 ' http://www.mikroe.com/en/compilers/mikrobasic/pro/pic/ ' * NOTES: ' RA0 - PB switch input with pullup, up ' RA1 - PB switch input with pullup, down ' RA4 - PB switch input with pullup, home ' RA5 - Reed relay output, up ' RC5 - Reed relay output, down ' RC0 - Up (blue) LED ' RC1 - Down (orange) LED ' RC2 - Program (red) LED ' RC3 - Ready (green) LED ' RC4 - Home (yellow) LED ' ' EEPROM addresses 00-01 and 02-03 set to default duration of 2 1/2 minutes program Lite_Lift_Controller ' Output port declarations dim up_relay as sbit at PORTA.5 ' Up relay port dim down_relay as sbit at PORTC.5 ' Down relay port dim up_LED as sbit at PORTC.0 ' Up LED port dim down_LED as sbit at PORTC.1 ' Down LED port dim program_LED as sbit at PORTC.2 ' Program LED port dim ready_LED as sbit at PORTC.3 ' Ready LED port dim home_LED as sbit at PORTC.4 ' Home LED port dim up as boolean ' Moving up flag dim down as boolean ' Moving down flag dim up_button as boolean ' Up button pressed flag dim down_button as boolean ' Down button pressed flag dim prog as boolean ' Program mode flag dim home as boolean ' Home flag dim ignored as boolean ' Ignored flag dim count as integer ' Count duration of motion dim press_count as integer ' Count duration of button press dim EEdur as integer ' Programmed duration stored in EEPROM '******************************************************************************* ' This procedure initializes the MCU bits and registers. '******************************************************************************* sub procedure init

Page 18: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

18

OSCCON = 0x77 ' Internal 8MHz clock INTCON = 0x00 ' Disable interrupts PIR1 = 0x00 PIE1 = 0x00 ANSEL = 0x00 ' Configure all analog inputs as digital CMCON0 = 0x07 ' Comparators off ' RA0 - PB switch input with pullup, up ' RA1 - PB switch input with pullup, down ' RA4 - PB switch input with pullup, home ' RA5 - Reed relay output, up ' RC5 - Reed relay output, down ' RC0 - Up (blue) LED ' RC1 - Down (orange) LED ' RC2 - Program (red) LED ' RC3 - Ready (green) LED ' RC4 - Home (yellow) LED ' TRIS bits: 1 = input, 0 = output TRISA = %00010011 ' RA 0, 1, 4 input, RA 2, 3, 5, 6, 7 output TRISC = 0x00 ' RC 7:0 output OPTION_REG = 0x00 ' Enable individual PORTA pull-ups WPUA = 0x13 ' Enable pull-ups on A0, A1, and A4 PORTC = 0x00 ' All outputs low up = false ' Initialize all flags to false down = false up_button = false down_button = false prog = false home = false ignored = false '******************************************************************************* ' When the PIC is first programmed all EEPROM locations are set to 0xFF by the ' PIC Flash programmer. This routine sets EEPROM locations 05 to 0x00 only ' after the PIC is first programmed. A value of 0 in location 05 indicates that ' the EEPROM has been initialized so it won't be initialized again when powered ' on. Set EEPROM addresses 01, 00 and 03, 02 to 0x0973 for initial 2 1/2 ' minute duration. Addresses 01 and 00 store the programmed duration. ' Addresses 03 and 02 store the default duration which can be restored by ' holding a button pressed during power on. delay_ms(250) count = EEPROM_Read(0x05) ' Initialize EEPROM to 0 if count <> 0 then EEPROM_Write(5, 0) ' Store initial programmed duration 0x0973 into EEPROM delay_ms(20) EEPROM_Write(01, 0x09) delay_ms(20) EEPROM_Write(00, 0x73) delay_ms(20) ' EEPROM addresses 02 and 03 store default duration 0x0973 EEPROM_Write(03, 0x09) delay_ms(20) EEPROM_Write(02, 0x73) delay_ms(20) end if '******************************************************************************* '******************************************************************************* ' Load stored duration from EEPROM. Stored duration is an integer ' which requires two bytes. The upper byte is stored in EEPROM address 01 and ' the lower byte is stored in EEPROM address 00. hi(EEdur) = EEPROM_read(0x01) ' Read high byte lo(EEdur) = EEPROM_read(0x00) ' Read low byte '******************************************************************************* '******************************************************************************* ' If a button is pressed at power on, turn on all LEDs, restore default duration ' from backup EEPROM location, bypass the rest of the initialize routine.

Page 19: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

19

if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then PORTC = 0x1F ' Turn on all LEDs ' Restore duration from backup EEPROM location hi(EEdur) = EEPROM_read(0x03) ' Read high byte lo(EEdur) = EEPROM_read(0x02) ' Read low byte delay_ms(20) EEPROM_Write(01, hi(EEdur)) delay_ms(20) EEPROM_Write(00, lo(EEdur)) delay_ms(20) ' Wait for button to be relesed while Button(PORTA,0,1,0) or Button(PORTA,1,1,0) wend ' Stay here until powered off or button press while true if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then Break end if wend end if '******************************************************************************* ' Flash LEDs to indicate working. Wait 1/4 second between LED action. Leave ' ready LED on to indicate ready to use. PORTC = 0x1F ' All LEDs on delay_ms(250) PORTC = 0 ' All LEDs off for count = 1 to 2 delay_ms(250) down_LED = not down_LED ' Toggle down LED delay_ms(250) program_LED = not program_LED ' Toggle program LED delay_ms(250) up_LED = not up_LED ' Toggle up LED delay_ms(250) home_LED = not home_LED ' Toggle home LED delay_ms(250) ready_LED = 1 ' Turn on ready LED Next count for count = 1 to 4 ' Blink ready LED for version number ready_LED = not ready_LED delay_ms(250) next count end sub '******************************************************************************* '******************************************************************************* ' This procedure stops motion and resets the flags. '******************************************************************************* sub procedure stop_all up_relay = 0 ' Stop all motion down_relay = 0 up_LED = 0 ' Turn off up LEDs down_LED = 0 ' Turn off down LED program_LED = 0 ' Turn off program LED up = false ' Reset flags and motion counter down = false for count = 1 to 20 ' Blink ready LED for 5 seconds to ready_LED = not ready_LED ' prevent quick reverse delay_ms(250) next count count = 0 ' Reset motion counter ' Restore EEPROM duration if ignored if ignored = true then hi(EEdur) = EEPROM_read(0x01) ' Read high byte lo(EEdur) = EEPROM_read(0x00) ' Read low byte ignored = false ' Reset ignored flag end if end sub '*******************************************************************************

Page 20: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

20

main: init ' Initialize MCU and registers while true ' Loop waiting for a button press ' Up or down button pressed if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then ' Up button pressed if Button(PORTA,0,1,0) then up_button = true else ' Down button pressed down_button = true end if ' Wait until button is released press_count = 0 while Button(PORTA,0,1,0) or Button(PORTA,1,1,0) delay_ms(62) press_count = press_count + 1 ' Button held for 3 seconds to enter program mode if press_count = 48 then ' Must not be moving to enter program mode if (up = false) and (down = false) then ' Not already in program mode if prog = false then prog = true ' Set program mode flag program_LED = 1 ' Turn on program LED else ' Already in program mode prog = false ' Reset program mode flag program_LED = 0 ' Turn off program LED end if delay_ms(1500) ' Time delay to remove finger from button else ' Moving and button pressed for 3 seconds if down = true then EEdur = 0 ' Clear EEdur so light lift will not stop at programmed duration ignored = true ' Set ignored flag to reload duration when stopped program_LED = 1 ' Blink program LED delay_ms(250) program_LED = 0 end if end if up_button = false ' Reset button flags down_button = false end if wend ' Finger removed from button, no buttons pressed, perform action if a ' button was pressed if Button(PORTA,0,1,1) and Button(PORTA,1,1,1) then ' If moving, stop motion If ((up = true) or (down = true)) and ((up_button = true) or (down_button = true)) then ' Store duration in EEPROM if down stopped while programming if (down = true) and (prog = true) then ' Store duration if down button pressed if down_button = true then prog = false ' Reset program mode flag EEPROM_write(0x00, lo(count)) ' Write low byte to EEPROM EEPROM_write(0x01, hi(count)) ' Write high byte shifted right 8 bits to EEPROM EEdur = count ' Set programmed duration with count value end if ' Version 2 ' Store default duration if up button pressed if up_button = true then

Page 21: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

21

down_relay = 0 ' Stop down motion to wait 3 seconds down_LED = 0 ' Turn off down LED for press_count = 1 to 12 ' Wait up to 3 seconds for up button press delay_ms(250) program_LED = not program_LED ' Blink program LED ' Up button pressed again within 3 seconds if button(PORTA,0,1,0) then EEPROM_write(0x00, lo(count)) ' Write low byte to EEPROM EEPROM_write(0x01, hi(count)) ' Write high byte shifted right 8 bits to EEPROM EEPROM_write(0x02, lo(count)) ' Write default low byte to EEPROM EEPROM_write(0x03, hi(count)) ' Write default high byte shifted right 8 bits to EEPROM EEdur = count ' Set programmed duration with count value while button(PORTA,0,1,0) ' Wait for finger to release button wend Break ' Exit for loop end if 'Down button pressed If button(PORTA,1,1,0) then EEPROM_write(0x00, lo(count)) ' Write low byte to EEPROM EEPROM_write(0x01, hi(count)) ' Write high byte to EEPROM EEdur = count ' Set programmed duration with count value while button(PORTA,1,1,0) ' Wait for finger to release button wend break end if next press_count prog = false ' Reset program flag program_LED = 0 ' Turn off program LED end if ' End version 2 end if stop_all ' Stop motion, reset flags, blink ready LED up_button = false ' Reset button flags down_button = false else ' Not in motion ' Up button pressed if (up = false) and (down = false) and (up_button = true) then ' Clear EEPROM duration if up pressed while programming if prog = true then EEPROM_write(0x00, 0) ' Write 0 to low byte in EEPROM EEPROM_write(0x01, 0) ' Write 0 to high byte in EEPROM EEdur = 0 ' Set programmed duration to 0 prog = false ' Reset program mode flag program_LED = 0 ' Turn off program LED else ' Not in program mode if home = false then up_relay = 1 ' Move up up_LED = 1 ' Turn on Up LED up = true ' Set up motion flag end if end if up_button = false ' Reset button flag else ' Down button pressed if (up = false) and (down = false) and (down_button = true) then down_relay = 1 ' Move down down_LED = 1 ' Turn on Down LED down = true ' Set down motion flag down_button = false ' Reset button flag end if end if end if end if end if

Page 22: Building a PIC Controller for an Aladdin Light Lift

Building a PIC Controller for an Aladdin Light Lift®

22

' Count duration to load into EEPROM if (down = true) and (prog = true) then delay_ms(62) ' 62 ms chosen to allow quick response to button press count = count + 1 ' Increase count value end if ' Set home flag and LED if home switch pressed if button(PORTA,4,1,0) then ' Home switch pressed home = true ' Set home flag home_LED = 1 ' Turn on home LED else ' Home switch not pressed home = false ' Reset home flag home_LED = 0 ' Turn off home LED end if ' Auto stop if moving down and motion = EEPROM or if moving up and home ' switch pressed. if (up = true) or ((down = true) and (prog = false)) then delay_ms(62) count = count + 1 ' Count motion duration if ((down = true) and (prog = false) and (count = EEdur)) or ((up = true) and (home = true)) then stop_all end if end if wend end.

Page 23: Building a PIC Controller for an Aladdin Light Lift

23

LIGHT LIFT Controller

5. The program duration is now set to the default duration. Change Default Duration (Green Ready LED must be on,

yellow Home LED must be on) NOTE: This should only be performed one time immediately after the controller is installed. 1. Start with the light raised up to the home (ceiling)

position and the yellow Home LED on. 2. Press and hold the toggle switch up or down for 3

seconds. The red Program LED comes on. 3. Press the toggle switch down, then release. The

orange Down LED comes on and light begins to lower. 4. When the light reaches the desired location press the

toggle switch up then release. The light stops moving, the orange Down LED turns off, and the red Program LED blinks for 3 seconds.

5. Before the red Program LED stops blinking, press the toggle switch up then release. The red Program LED turns off and the duration is now the new default duration and also the new programmed duration.

NOTE: To make no changes to the default or programmed duration, do not touch the toggle switch while the red Program LED is blinking. After 3 seconds the red Program LED stops blinking and turns off and no changes are made.

4

LIGHT LIFT Controller

Ready Controller 1. Turn on the light switch so the lights come on. 2. Insert the key and turn to the On position. All LED’s

flash then the green Ready LED stays on indicating the controller is ready. If the light is up to the home (ceiling) position the yellow Home LED also comes on.

Lower Light (Green Ready LED must be on) 1. Press the toggle switch down, then release. The

orange Down LED comes on and the light moves down. 2. If duration has been programmed, the light stops when

the programmed duration has been reached.

Raise Light (Green Ready LED must be on, yellow Home LED must be off)

1. Press the toggle switch up, then release. The blue Up LED comes on and the light moves up.

2. The light stops when it reaches the home (ceiling) position and the yellow Home LED comes on.

Stop Light Motion (Green Ready LED must be on) 1. While the light is in motion, press the toggle switch up

or down, then release. The light stops moving, the corresponding LED turns off, and the green Ready LED blinks for 5 seconds. The light may not be moved again until the green Ready LED stops blinking.

1

Page 24: Building a PIC Controller for an Aladdin Light Lift

24

LIGHT LIFT Controller

2. The light also stops automatically at the programmed

duration when moving down, or at the home (ceiling) position when moving up.

3. Turn the key to the Off position. The green Ready LED turns off.

4. Remove the key and store it in a safe location.

Program Duration (Green Ready LED must be on, yellow Home LED must be on)

1. Start with the light raised up to the home (ceiling) position and the yellow Home LED on.

2. Press and hold the toggle switch up or down for 3 seconds. When the red Program LED comes on, release the toggle switch.

3. Press the toggle switch down, then release. The orange Down LED comes on and the light begins to lower.

4. When the light reaches the desired location press the toggle switch down, then release. The light stops moving and the red Program LED and orange Down LED turn off. The light now stops in the same location when the programmed duration is reached.

NOTE: To exit program mode without making any changes; with the red Program LED on, press and hold the toggle switch up or down for 3 seconds. The red Program LED turns off.

2

LIGHT LIFT Controller

Delete Program Duration (Green Ready LED must be on) 1. Press the toggle switch up or down and hold for 3

seconds. When the red Program LED comes on, release the toggle switch.

2. Press the toggle switch up, then release. The duration is deleted and the red Program LED turns off.

Ignore Program Duration (Green Ready LED must be on) 1. While the light is moving down, press and hold the

toggle switch up or down for 3 seconds. When the red Program LED blinks indicating the programmed duration is being ignored, release the toggle switch.

2. Motion must now be stopped manually (see Stop Light Motion on Page 1 of this card).

3. After motion is stopped, the programmed duration is restored so the light will again automatically stop at the programmed duration when moving down.

Set Program Duration from Default Duration (Key switch

must be off) 1. Turn on the light switch so the lights come on. 2. Press and hold the toggle switch up or down. 3. Insert the key and turn to the On position. When all

LED’s come on, release the toggle switch. 4. Press and release the toggle switch up or down. All

LED’s flash then the green Ready LED stays on indicating the controller is ready.

3