Friday, July 22, 2016

Custom Stairway + Hallway Lighting Project - Part 7 - Done. For Now.

The last 6 weeks have been rough on my time and health and stuff has taken far longer to get done, however, I've finally finished the project (or at least as finished as it can be for now).

A fair amount of fine tuning of the programming has occurred.  I found that the dimming was taking far longer than it should, so long that you could see each step down of the PWM signal.  I finally tracked this down to the debug logging I had in place.  It turns out that writing to the serial port is extremely expensive.  It could take upwards of 3-4ms to write out a line to the serial port.  Multiplying that out, some of the code was taking 40 or 50 ms per loop. (compared to my expectation of it taking a total of < 5ms to do all the checking and calculations and taking actions).  Once I removed the debug code, the fading out was much better.

I also added code to make the lights dimmer based on the ambient light of the sensors at the time that the lights were tripped.  The darker it is in the room the dimmer the lights are.  I'm still not totally settled on the lowest level of light and where the trigger levels are, but it's much closer now than it was before.

The next physical step in my work was to cut the channels in the drywall and run the power.  This necessitated a bunch of crawling around in my attic.  I'm not a fan of attics normally and I'm less so this one.  All of the HVAC runs around the attic and it makes moving from point A to point B annoying.  I used my oscillating saw to do the drywall cuts and it went pretty well.



I put some holes in the back of the aluminum channels so that I could screw them into the studs.  I did this because, like all wooden homes, there are slight variances in the wall.  It isn't perfectly straight and this would bend the channel to match the wall.  I also had to add some bracing at both ends where there were no studs.  I took a couple of small pieces of plywood and slide them in through the hole from the channel and screw them into the drywall.  It was a fun feat to do so without hurting myself or the wall.  This was done down the hall, below is the picture of just 1 half of it.




Once I got the channels in, I installed the lighting and tested it out to make sure that was all wired up right.  Then I puttied all the holes and sanded them.




And finally it was painted.


Next up was the sensors.  These were of a slightly different construction than the ones for the stairs.  Largely because you could see them and because they used PIR (Passive Infrared) sensors instead of Active Infrared sensors.  After search around I settled on using Christmas ornament shells that you could get from the local craft store (my wife's idea).

I used a step drill bit to drill out the hole for the sensor.  The picture doesn't show it, but I also cut that tab off then painted it.



For reasons I can't begin to explain, I forgot to take a picture of the finished inside of the sensor once the pcb and photo resistor was installed, but I did take a picture of the outside.



It turned out pretty well I think.



Monday, October 26, 2015

Custom Stairway + Hallway Lighting Project - Part 6 (Milestone!)

My parents came into town this past weekend though only for a short time.  They had a wedding to go to in a city about 2 hours away.  They were here Saturday Night through this morning.  That said, Sunday my father and I made great progress on the cabling and I finally have finished results for the first segment of the house: the stairs.  That said, I'm really sore today.  Spent alot of time contorting myself around the furnace closet to pull and run wires.  Thankfully only minor scrapes and bruises were had.

Before they got here, I needed to get the rails up.  To get the rails up I needed to put ends on both the Cat5 and the power wires.  This was a mostly uneventful affair.  I am using XT60 polarized terminals for the power.  Normally these things are used for RC cars/planes battery connections, but their ratings make them ideal for this application as well.  The only hard part about this is getting 16 gauge wire and connectors to hold them hot enough to flow solder, but not so hot as to melt the wires and or the connectors is a pain.  But overall it looks pretty good.


I used a standard keystone jack for the networking.  Between this and the XT60, getting the rail off the wall is pretty easy.  I did offset the connectors by about 1" in length so that only 1 connector would need to come out of the hole in the wall at a time.


The first order of business when my father and I started was to cut a hole in the wall of the HVAC room.  The nice thing is that this room is unfinished (seriously even the mudding is terrible, they didn't bother to sand or anything).  I used my Black and Decker oscillating saw to do the cuts.  That has to be one of my favorite tools.  It cuts drywall like butter and for the most part is clean cuts if you are careful. I forgot to take a picture after we took this out, but it was an empty space with studs, so you probably can imagine that (or maybe not).


Initially the plan was to use my 12" long 5/16" bit to drill down, but we figured out that with the studs and the floor joists that was just too short.  We ended up getting a 9/16" 36" boring bit.  A little costly, but it worked like a charm.  We got the wires fished and ends put on them. The hole in the wall is just a little bigger than the keystone, but small enough that the end of the rail hides it entirely.


I needed power in the closet so we pulled it in from an outlet on the other side of the wall.  Of course that was on the other side of the wall from where everything else was.  We used wire molding to get it over to the other side.  There is a drain near where the outlet ended up (about 3' below it), so we ended up using a GFCI outlet, just in case.  Normally this stuff is stick on, but we used some screws into the studs to re-enforce it.  The space on the left of the room is only about 12" wide.  Lots of contorting around to get back there.



We also ran some molding to carry the cat 5 and power wires from the wall over to the box.


And then we hung the box.  2 screws into a stud and 2 into metal drywall anchors.  I do plan to put some Velcro wraps around the cables to clean them up some.  I also need to print out cable labels too.


And finally. Let there be light....



We finished late and initially the bottom stairs sensors weren't functioning.  Quick diagnosis showed that the values were all over the place as if the pins were floating (not connected).  But girl child was needing to go to bed, so it waited until this morning.  I found that the connector at the end of the cable in the closet had 2 of the wires switched.  (specifically +5V and the input for the resistor.  Thankfully that specific configuration couldn't have hurt anything, but it would make everything crazy unstable.

So what's next?  Well there is some fine tune programming that needs to happen.  I need to adjust the light sensor levels so that the lights don't turn on during the day and also program the logic to adjust the max light level based on the initial light levels. (so the brigher it is in the room, the the brighter the lights are.  When it's really dark and your eyes are used to it being dark full power is too bright.

Once that is done then it will be time to plan out the details for the other 2 hallways.  I have the general plans of course, but I need to figure out exact measurements so I can buy the lights and channels.  I also still need to pick up a couple more photo resistors and PIR sensors.

Friday, October 23, 2015

Custom Stairway + Hallway Lighting Project - Part 5

It has taken me almost 2 weeks to get through the next steps of the project.  I spent an hour or 2 most afternoons/evenings working on the smaller of the 2 hand rails.  A lot of that time was just spent figuring out how to approach it.

There were several problems to solve.  First, how to route the path into the wood to hold the aluminum channel.  Second, how to get the wires through wood.  the power wires only needed to be at one end, but due to how my walls are laid out I needed to run the sensor wires the entire length of the wood.

I started with drilling the access holes to bring power into the rail.  These holes were drilled with a 5/16" bit and a hand drill.  Overall I ended up coming very close to my target.  On the right I added some red lines to give you a general idea of where the holes were drilled.  Keep in mind I had to drill off center so that I'd miss the area where the holes were drilled for the brackets. 





My approach for this rail was to use a 1/4" routing bit on the routing table.  I drew up lines on where I wanted the cuts to go.  For some reason I didn't take a picture directly after this step, but here is what it looked like right before.


Here you can see part of the routing job and also the connecting hole.  Overall I was not pleased with the routing job.  There were quite a few problems with it.  The first of which was that the bit I had really wasn't designed for hogging out that much wood.  The second was that it was very difficult to measure exactly where to set the backplane when you can't see the thing you're routing out.  It was also difficult to control and that caused bumps.   That said it did work and all the less desirable look of it will be hidden under the aluminum channel.  You'll also note that in the center of the channel it is deeper than on the edges.  This is the place where the I/O lines will run.


So even though it didn't look great underneath it looked pretty good with the channel in.  This was a dry fit of course, there was a lot of work left to do.



I needed to figure out exactly what shape the sensor box was going to be. Below are all of the pieces (except a small capacitor) that needs to be dealt with.  The PCB actually goes into the black box there.  I knew I was going to use acrylic to make a box that I could paint and thus mostly hide.


Like the other side, I needed to drill holes into the sides of the rails to provide access to fish the lines through.  Additionally another hole needed to be drilled where the sensor box was going to go.


Here you can see the 2 horizontal holes and 1 vertical hole.  The very long horizontal hole was drilled with a 12" 5/16" bit.  I took a small 2x4 and put a 5/16" hole into it at the height I wanted using the drill press so it was exactly square.  I then clamped the 2x4 to the end of the rail to provide a guide so that the bit wouldn't drift over such a long distance.


I decided a good place to put the photoresistor was in the empty space of the IR sensor.  So I drilled a couple holes in the plastic and stuck it in.  Then I filled it with some silicon to insulate it.  (Though I'm thinking hot glue next time.)



Next up was the wonderful fun of wire fishing.  The holes I drilled were just 1 size bigger than the bare minimum, so pulling this stuff around corners was a challenge.  Even more so for the network cable as it is solid core with riser rated insulation, which makes it stiff.  I ended up having to shed the outer insulation at both ends to make the turns.  Not a huge deal, it's surrounded by 3/4" of wood, so it's pretty safe.


On the other end I had to bring in both power and the I/O cable.  I ended up using 1 line of power (which was pretty easy to move through by itself) to first pull the other line of power which also had I/O cables taped to it.


After the wires went in I went to building the acrylic box to house the sensors.  I also painted the sensors once with white spray paint.  The boxe's outside was sanding down so that it would take the paint better since I want it to be the same color as the rail.


Next up was to start cleaning this rail up so that it looks like it did before.  Using some Bondo (which I've never used before, but holy crap it stinks), I filled the 3 holes that aren't going to be used going forward and which can be readily and easily seen.




While waiting for the Bondo to cure, it was time to start getting the led strips into the channel which includes cutting one of them to that it will fit



After sanding the Bondo down to match the wood, I put on the first coat of paint (which would be a total of 4 coats, 2 on bottom half, 2 on top half.  All this work so far has marked the heck out of the rails.


Finally putting in the aluminum channel for near the last time.  It fits quite well.  I ended up using some black electrical tape on the back, not to adhere it to the channel, but because the back of the strip has metal contact points that I very much don't want to short.



And Finally this one is now done! (well almost still need to put ends on the wires before they go into the walls, but I am not going to do that until I determine how much slack I want there.




So after my adventures with the short rail I learned a few things to make the 2nd one go *much* faster and mostly easier. Two big changes with this one vs the other one.  The first is how I went about routing out the holes.  I purchased a top-bearing 1/2" router bit with a 1/4" cut depth.  I then got 2 pieces of square steel tubing and used those as the guide for the bearing.  Most this approach worked.  The worst part was that I expected the steel tubing to be straight.  That was not the case though as it tended to bow some.  The cuts were cleaner, but not perfect.

The second change was to route out the entire channel all the way from the first bracket to the last.  The reason is I still needed to get the wire all the way down and I had 2 brackets in the middle to deal with.



Like the other one, I did 2 levels of routing for the wires.  In the picture below, though its hard to tell.  I took the bearing off of the bit and cut under the wood.  This gave me most of a channel to run the wires in.  It wasn't quite enough, but that's ok.  The wood insert I'll be cutting to replace the wood I routed out can handle it.




Next using the same approach as last time I fished the wires through both ends.





I needed to replace the wood that I routed.  To do that I cut out a piece of poplar and then used the band saw to cut notches into it.  I then glued it into place and after letting it set, sanded it down to be flush with the rail.  The band saw cuts weren't the greatest, but they were close enough.  Once the channels are in, no one will be the wiser.  (except everyone who reads this, all 5 of you).


Time precluded me taking pictures of putting the channels in and soldering stuff, but here is the finished product.






At the same time I was doing the rails I had a few more modifications I thought I should make to the controller.  The first was to add a fuse to the 12V rail.  Since I'm sticking wires in the wall, even low voltage ones, I'd rather be safe than sorry.  I got fast blow glass fuses and stuck a 6 Amp one in.  Another thing was that the override button showed up.  This was a 12V LED latching vandal switch.  When pressed it would suspend all the I/O and simply turn the lights on full.  

While testing that though I found something odd.  The LED in the switch was on, but dimly.  This was odd because the LED doesn't share a circuit with the switching mechanism itself and I was only powering the micro controller via USB.  The 12V supply wasn't plugged in.  I realized that when the microcontroller is plugged into USB, the regulated 5V supply actually comes out of the voltage input line.  This was bad because neither the micro-controller nor USB is capable of driving the current that the 12V rail was supposed to support.  To that end I added 2 diodes to the system.  One on Vin on the microcontroller and one right after Gnd on the micro controller.  This way the controller can't accidentally try and power the 12v bus.



And here is the new schematics.


I also found a bug in the calculations for the distance sensor.  I forgot when I switched it to the new averaging method that I was initializing the base total with values at 100 for each.  The problem is that was skewing the average to 30-35" instead of what it really was which was usually 15-20".  Also needed to add the code to handle the switch.

Next up is finally seeing some results.  I need to put the rails back up at least for the weekend since my parents are in town, but I'm hoping my father will be able to help run the wires in the wall up into the HVAC room.  Then just plug everything in and turn it on and hope it doesn't explode.  (pretty sure it won't after all the testing, but...)