Introduction: No Blue Lamp

About: Lazy Old Geek

So this Lazy Old Geek (L.O.G.) has been working on a Blue Light Project:

https://www.instructables.com/id/Blue-Light-Projec...

https://www.instructables.com/id/Blue-Light-Projec...

Well, for the next step I wanted a lamp that would be bright during the day and had no blue light in the evening/night.

Design Hardware:

I decided to use an RTC (Real Time Clock) to control the times for light changes.

I chose the DS3231 as it has better time keeping accuracy than the DS1307. The DS3231 can be 5v or 3.3v.

For light, I will use a WS2812B LED string. These have a simple three wire interface and controllable Red, Green and Blue LEDs. WS2812B are 5v devices.

For the microcontroller I will use a Pro Micro, 5v 16MHz.

While the WS2812B will probably work with 3.3V, it’s better to use a 5V Arduino.

The Pro Micro is a cheap Arduino using an Atmega32U4 microcontroller.

The lamp will have an on/off switch to turn lamp on or off.

There will be a potentiometer to control the brightness.

Design Software:

The DS3231 RTC would control the timing, it has battery backup so should keep the time even if power is lost.

During the day, all the RGB LEDs would be on, controllable by the pot up to full intensity.

Early evening, the Blue LEDs will be off, Red and Green on max.

As evening progress, the Red and Green LEDs will dim down, with preference of Red over Green (My testing in Part 2 suggest the Green LEDs have some Blue in them).

After around 10p.m. all the LEDs will be off.

PROBLEM:

Back to the DS3231 RTC module, I bought mine from Aliexpress like I did for the other components.

These are supposed to work with and charge an LIR2032 rechargeable battery. I tried it out. After about a day, the battery was dead.

Well after some searching on the Internet, I found this article.

https://www.onetransistor.eu/2019/07/zs042-ds3231-...

I agree with this analysis but thought the LIR2032 would charge adequately but not excessively. I was apparently wrong. My DS3231 although also marked as ZS-042 as in the article was slightly different then his but almost the same. So I unsoldered the diode seen in the picture and installed a CR2032 battery. Without the diode the module will not try to charge the battery. Now the DS3231 holds the correct time even with power disconnected and the battery should be good for many years.

Power requirements:

The WS2812B is a string of RGB LEDs called sometimes called NeoPixels. Each NeoPixel requires a maximum of 60mA. I’m using 12 Neo Pixels so need 0.72A. I’m using a 2A USB adapter so have plenty of current.

Step 1: BlueLamp PCB

So as I usually do, I used the free Eagle Cadsoft software (now Autodesk) to layout and create my PCB.

https://www.autodesk.com/products/eagle/free-downl...

The Eagle schematic and board files are attached along with the schematic in a picture.

One comment about the schematic, the 330 ohm resistor and 10,000uFd capacitor are recommendations by Adafruit’s neopixel guide:

https://learn.adafruit.com/adafruit-neopixel-uberg...

The toggle button I used “Torch pushbutton switch’ was from here:

https://www.aliexpress.com/item/32904942704.html?s...

The 10K (B103) potentiometer from here:

https://www.aliexpress.com/item/32672253655.html?s...

Step 2: Assembling the Lamp

I happened to have a heavy base from a lamp I purchased. It had a big round pin on it. I took a piece of PVC pipe that fit over it. It was a little loose so I took a bolt and a couple of nuts so I could tighten it. (see picture)

The WS2812B can be cut into the number of NeoPixels you desire. The strip I bought has wide spaces between the NeoPixels. I wanted it to be a little brighter so I cut two 6 NeoPixel strips and ran them in parallel slightly offset. The WS2812B strips can be cut between the NeoPixels. In this case I needed a 180 degree change so I cut the strip and ran jumper wires between. If you ever do this make sure the signals and the direction arrows are correct.(see picture)

This WS2812B also has wires and a connector (this connector is a JST-SM 3pin connector if you want to use it elsewhere). Since this connector was already there, I just soldered the wires to my PCB. For this WS2812B the red wire is 5v, green is signal and white is ground.

Once I made the PCB, I put some tape on the bottom and stuck it to the base. Then I plugged in the Pro Micro and the DS3231.

Step 3: Arduino Sketch

Although I purchased my Pro Micro from Aliexpress.com, I used the following information to get Arduino to work:

https://learn.sparkfun.com/tutorials/pro-micro--fi...

To install the library for the DS3231, I use this one:

https://github.com/PaulStoffregen/DS1307RTC

Download the Zip file

Open Arduino, select ‘Sketch’ ‘Include Library’ ‘Add .zip library’

Install the following use the same method

Time Library PaulStoffregen

https://github.com/PaulStoffregen/Time

Timezone Library

https://github.com/JChristensen/Timezone

When completed, start Arduino.

Under Tools Boards select “Sparkfun Pro Micro”

Click on Tools again, there will be a selection for processor

You may need to change it “Atmega32U4 (5V 16Mhz)”

WARNING: If you’re careless like I am, I selected “Atmega32U4 (3.3V 8Mhz)” by mistake. This ‘bricked’ it so the Arduino couldn’t see it. Well, I usually try to read up on new stuff before I got it and remembered something about this happening:

https://learn.sparkfun.com/tutorials/pro-micro--fi...

In this guide, there is a section called “How to Revive a ‘Bricked’ Pro Micro” As it mentions, it’s a tricky procedure but I did manage to recover mine.

FYI: If you’re wondering why there are two versions with different voltages and speeds, the Atmega32U4 (same as Atmega328) will work fine at 5V with a 16MHz clock. But at 3.3V the design spec says the 16MHz clock will not work, that’s why they have the clock at 8MHz. Generally, speaking the Arduino software will take care of any timing issues.

RTC TIP: Most of the software written for DS1307 will work with the DS3231 as they have very similar software.


Daylight Saving Time

Well, I wanted to implement DST, so I didn’t have to reprogram my lamp twice a year. I worked on this for several days. I couldn’t find any good simple explanations on how the Time, TimeLib and RTClib worked.

I actually wrote some DST code for my IPClock:

https://www.instructables.com/id/NO-MORE-SPRING-FO...

that worked for Internet time but I couldn’t get it to work for RTC time.

I finally ran across the following by JChristensen:

https://forum.arduino.cc/index.php?topic=96891.0

https://github.com/JChristensen/Timezone

To use this, you first have to set the RTC to UTC (Coordinated Universal Time), this is time in Greenwich, England. Well, didn’t know how to do that but found this article:

https://www.justavapor.com/archives/2482

Rewrote it for Mountain time (attached) UTCtoRTC.ino

Then I incorporated the timezone into my Sketch. To be honest, I haven’t tested it out so just assuming that it works.

My sketch is attached MTS_BlueLamp.ino.

Step 4: Conclusion

I made a little hook at the top for my CPAP face mask. I used to hang it on my old bed lamp.

Basically very happy with this lamp. Fully bright during the day and no blue in the evening and night.

One thing I don’t like is that I can’t use it after 10p.m. and before 5a.m.

I also found that I don’t use the toggle on/off as I usually just use the dimmer switch.

In the future, I may rewrite the sketch and change the button to scheduled or unscheduled (full on) switch. But with my poor coding skills I might wait a while.

PCB Design Challenge

Participated in the
PCB Design Challenge