Auto-Off NeoPixel Articulated Reading Light
by gwfong in Circuits > Electronics
2811 Views, 67 Favorites, 0 Comments
Auto-Off NeoPixel Articulated Reading Light
My wife and I have had many reading lights over the years. We attach them to the headboard. We read. We fall asleep. And then sometime in the middle of the night, around 1am or 2am, we end up waking up to turn off the light. To me, the sleep disruption seemed unhealthy. In addition, it's very annoying being woken up by the other person's light and either having to reach over to turn it off or wake the other person up to tell them to turn it off. Lastly, we have kids who each have their own reading lights Sometime they turn them off before they fall asleep, but often not.
So this project is a prototype for a little smarter reading light.
UPDATE: 2016/10/10
The base has been increased to accommodate a 4x AAA battery holder. 3D models have been updated.
Parts and Tools
Parts
- Arduino Nano
- Bourns Rotary Encoder with Switch
- PIR sensor
- NeoPixel Ring - 16 x 5050 RGB
- 10K Ohm resistor
- 6-32 1 1/4" machine screws with washer and nut, qty ~5
- Tiny wood screws, 3/8" or 1/2" length, qty 4
- Heat shrink
- 3D printer filament, lots!
- 28 awg stranded wire of various colors
- Small breadboard
- Wall wart with mini-b usb male connector
- SPST switch, optional
- 9V battery, optional
Tools
The biggest tool that's needed is a 3D printer. I have an Ultimaker 2. Any quality 3D printer that can print at least 160mm tall projects will do. As for the rest of the tools:
- Soldering iron (for the electronics)
- Wire cutters (for the electronics)
- Screwdrivers (for the armature)
- Exacto knife (for 3d print cleanup)
- Tweezers and needle nose pliers (for 3d print cleanup)
- Picks and dental scrapers (for 3d print cleanup)
- Dremel (for 3d print cleanup)
3D Print the Parts
This will take the most time, approximately 5 days of on and off after work and through the night printing. It'll take longer if the printer has glitches, like my Ultimaker 2 does. Also, if it doesn't print true, be prepared to a lot of post print cleanup. All of the detailed slicing information applies only to the slicer that I used, which is Cura. Lastly, make sure that there is enough filament in the desired color.
Print the following:
- base
- base lid
- top clamp
- light housing
- nut
- arms; how many of what type is a matter of personal preference
- connectors; a pair for every articulation point
- knob
The Screw Clamp
A bit about the screw clamp. I was trying to find numerous ways to clip or clamp the reading light onto my headboard rail. With what I had around, it was a bit difficult to find a clip that I could use that look pretty nice. Chip bag clips aren't really strong enough. Binder clips and hardware clamps don't really look good. Without a way to make a strong clip spring, it's hard to make a clip. So I resorted to a screw clamp.
Nearly all screw clamps use metal either for the bolt or for the nut or both. The few that used plastic and was 3D printed were mostly small. I needed something that could take some bit of force. Searching around I found How to build internal and external metric ISO threads in 123d design v2.0 by drive3D. Following his instructions, which after doing it once I found it very simple, and referring to Maryland Metrics Thread Data Charts, Metric Thread Course Pitch for thread dimensions, which specifies unique dimensions for both the bolt and the nut, I was able to create a M36 nut and bolt. I was very pleasantly surprised to find that my test print worked perfectly first time. It's not going to hold up a building, but it will keep the reading light onto a table top or headboard rail.
Base
This is the most complex piece in the group. Make sure that it prints true, that any kind of brim or raft option is used, and that whatever stick technology works for the printer is being used. With all of the experiments and failures, it took me 1 solid week to get something working
Print time: ~15 hours
- Fast print
- Enable retraction: disabled
- Fill Density %: 75
- Print Speed mm/s: 30
- Support type: touching buildplate
- Platform adhesion type: Raft
- Extra margin: 15mm
- First Layer Airgap: 0.1
Reading Light - Bottom Base (increased size) by gary fong on Sketchfab
Base Lid
The lid that attaches to the bottom of the base so that the electronics don't fall out :)
Print time: ~1 hour
- Fast print
- Enable retraction: disabled
- Fill Density %: 20
- Print Speed mm/s: 50
- Support type: none
- Platform adhesion: none
Reading Light - Base housing lid by gary fong on Sketchfab
Print time: ~4 hours
- Fast print
- Enable retraction: disabled
- Fill Density %: 75
- Print Speed mm/s: 30
- Support type: none
- Platform adhesion: none
Reading Light - Nut by gary fong on Sketchfab
Top Clamp
This along with the bottom housing is what keeps the light onto a table or headboard rail.
Print time: ~2 hours
- Fast print
- Enable retraction: disabled
- Fill Density %: 20
- Print Speed mm/s: 50
- Support Type: none
- Platform Adhesion: none
Reading Light - Top Clamp by gary fong on Sketchfab
Light Housing
Print time: ~2 hours
- Fast print
- Enable retraction: disabled
- Fill Density %: 20
- Print Speed mm/s: 50
- Support Type: Touching buildplate
- Platform Adhesion: Brim
Reading Light - Light Housing by gary fong on Sketchfab
Arms
There are 3 arm lengths. Each is a third size bigger than it's smaller version. I thought I would need all three but instead I only used 1 medium and 3 smalls.
Print time for small: ~1 hour
Print time for medium: ~1.75 hours
Print time for large: ~2.5 hours
- Fast print
- Enable Retraction: disabled
- Fill Density %: 50
- Print Speed mm/s: 50
- Suport Type: Touching buildplate
- Platform Adhesion: Brim
Reading Light - Small Arm by gary fong on Sketchfab
Reading Light - Medium Arm by gary fong on Sketchfab
Reading Light - Large Arm by gary fong on Sketchfab
Arm Connector
A pair of these need to be printed for every articulation point in the armature. Cura has the ability to print multiple copies one at a time. I was able to fit up to 10 on the plate.
- Fast print
- Enable Retraction: disabled
- Fill Density %: 50
- Print Speed mm/s: 50
- Support Type: none
- Platform Adhesion: none
Print time: ~13 minutes
Reading Light - Armature Connector by gary fong on Sketchfab
Knob
Control knob
Print time: ~30 minutes
- Fast print
- Enable Retraction: disabled
- Fill Density %: 50
- Print Speed mm/s: 50
- Support Type: none
- Platform Adhesion: none
Post Print Cleanup
Most of the work will be removing any support material, removing strings, smoothing off dots, glue or any residue from the sticky plate technology, etc. Make sure the balls are as round as they can be. Also make sure that the lid fits into the base housing bottom. The rotary encoder has a D-shaft. Make sure that it fits into the knob. Lastly, there are a total of 9 screw holes: 4 in the base, 4 in the lid, and 1 in the knob. Make sure that they still exist. Use a tiny drill bit or something to drill out the hole if it got covered or filled in.
Electronics
Surprisingly, the electronics part of this project is pretty simple especially when using an Arduino Nano. I tried using a Trinket but because of the number of pins I needed, I had to use the ones that aren't really supposed to be used which caused all kinds of problems. Luckily the reading light base can hold an Arduino Nano very easily.
Rotary Encoder
This encoder with the switch acts like a button dial on a modern car stereo. It continuously rotates left or right and can be pressed down to act as a momentary button switch. The encoder library from PJRC works perfectly with the encoder feature. And Bounce2 library is perfect for the switch.
Passive IR Sensor
This is a basic PIR sensor. It has a single data line signals high or low indicating if some motion was detected or not. There are two pots to control the sensitivity and the duration of the high signal. No special library was used to understand PIR signals. I wrote one, though, to just encapsulate the sleep logic as detected by the sensor.
NeoPixel Ring
The NeoPixel ring is a ring of addressable NeoPixels which are basically RGB LEDs. The ring should be a true ring that works with the Adafruit NeoPixel library. I introduced a modified version of the NeoPatterns library to provide the mood lighting.
The Code
The code can be found in my github repository.
Assembly
This assembly is somewhat temporary. The primary reason is that the programming is still in flux. Not until the reading lamp in actual use will I know if anything needs to be tweaked or not.
Test The Electronics
First things first. Wire up the electronics and run the Arduino code to make sure everything works. Don't continue until this step works.
Light Housing
- Cut 4 lengths of wire long enough to reach from the light housing down the arms to the base housing plus a bit more. They'll be used for positive, negative, PIR data and NeoPixel data.
- Cut 2 more small lengths of wire, about 4", one black, one red
- Solder the red to VCC on the NeoPixel ring
- Solder the black to the ground on the NeoPixel ring
- Solder the yellow to the Data In on the NeoPixel ring
- Solder the green to the Data Out on the PIR sensor
- Put a non-conductive barrier, such as tape, between the solder points of the capacitors on the PIR and the NeoPixel ring. The NeoPixel ring exposes some some copper and the solder of the PIR could make contact.
- Hot glue the PIR sensor onto the back of the NeoPixel ring in the center of the ring
- Solder the small red wire from VCC on the NeoPixel to the PIR VCC
- Solder the small black wire from ground on the NeoPixel to the PIR ground
- Feed the wires through the light housing
- Hot glue the NeoPixel ring into the light housing
Armature
- Feed the wires through each of the arms. Make sure the arms are in the preferred order. Near the top I have 3 small arms and at the bottom 1 medium arm.
- For each of the connectors apply heat shrink tubing over each concave joint. Shrink it. The tubing will provide friction between the ball and the connector.
- Attach two connects between each joint joined with a screw, a washer on both ends, and a butterfly nut. Do not over tighten.
- Before connecting the next link, exaggerate the bend in the prior links. This will provide slack for when it's needed.
Base Housing
- Place the top clamp over the base housing
- Use a bit of beeswax (or paraffin) on the threads of the nut and the base housing
- Place the nut on the base housing atop the clamp
- Feed the wires through the base housing
- Attach the final connectors between the base housing and the armature
Electronics
- Connect the Arduino Nano to the breadboard
- Strip and tin the wires
- Attach the wires to the breadboard based on the fritzing diagram in the previous section
- Cut 3 small lengths of wire, black, green, and yellow
- Solder the black onto the ground of the encoder
- Solder the green onto channel A of the encoder
- Solder the yellow onto channel B of the encoder
- Attach the encoder's wire to the breadboard based on the fritzing diagram in the previous section
- Cut 2 small lengths of wire, white
- Solder the white wires to the switch leads on the encoder
- Attach the switch's wire to the breadboard based on the fritzing diagram in the previous section
- Attach the 10K Ohm resistor on the button signal and the ground
- Cut 3 small lengths of wire, 2 red and 1 black
- Attach a red wire to the SPST toggle switch lead
- Attach the other red wire to the battery pack
- Attach the black wire to the battery pack
- Attach the red wire that goes to the SPST to VIN on the Arduino Nano
- Attach the black wire from the battery pack to ground on the Arduino Nano
Rubber Pad
To help keep the light from spinning when it is attach to something round, like the metal round stock of a headboard, attach two pieces of rubber to the faces of the top and bottom clamps. I used scraps from an old bicycle tube that I keep around for just this purpose. The tube has power residue to keep the tube from sticking together. Wash it off. Then cut and glue the pieces onto the clamp faces.
Auto-Off Algorithm
One of the goals of creating the reading light was to have it turn off when it detects that I have fallen asleep. The current algorithm uses motion detection and frequency.
The way it works is as follows:
- An awake movement is any motion that lasts longer than 5 seconds
- The light records movements for a 5 minute period
- If after 5 minutes there were less than 15 movements, the person is considered asleep
- The light is then turned off
Right now it's crude. This is one of the reasons why the Arduino Nano still sits in a breadboard. That give me the ability to pull it out, change the algorithm, put it back in, and then give it another try.