Sunrise Alarm Clock Controller Board - Page 1
Forum section: electronics / projects

author: law_freak
author_rank: Contributor
timestamp: January 29, 2017, 05:20:43 am
content: I've been rather enjoying learning to use KiCad lately to layout a board to control a sunrise alarm clock I am working on. This is my first crack at a custom PCB.The Sunrise Alarm Clock project is a silent light-based alarm. Using an LED light strip or board, this project will simulate the rising sun to wake up the user with light. This board interfaces with an Adafruit DS3231 breakout board and a 7 segment display breakout board.The board will control a load up to about 2 amps @ 12 volts.Having no formal training,I would greatly appreciate some feedback on the schematic and layout.The following are the shortcomings that I am aware of and which I intend to fix in a later revision. I'll keep this list up to date to reflect your feedback.No method for setting the time on the DS3231 without a Raspberry Pi or equivelant. I am undecided on the best solution here, but am toying with the idea of a Bluetooth connection to a phone for setting time and alarms.The DS3231 breakout should be replaced with an on-board DS3231Forgot to adjust the solder mask for the vias on the thermal pads!I'd like feedback on some of these specific items as well.Is there a more suitable part than the PSMN022? In particular, I wonder if an alternative with the mounting base connected to SOURCE instead of DRAIN might allow for better heatsinking. Based on my working models, I believe this component will not even get warm though.Are the thermal pads for the 5V regulator and the PSMN022 correctly designed? Over-designed/Under-designed?Attached is a complete KiCad archive.Linked here is the OSH Park page for rev1.5. I haven't order this revision and probably won't until I've fixed at least the problems I am aware of.I have a working breadboard mockup as well as a working earlier revision of the PCB.Rev1.3 can be viewed on OSH Park, but I don't have an archive for that layoutThank you for your attention and interest. Share freely.

author: james_s
author_rank: Super Contributor
timestamp: January 29, 2017, 05:40:11 am
content: I don't see a decoupling capacitor for the CPU, you should have a 0.1uF cap from the power pin to ground as close to the IC as possible. It's also good practice to use a gate resistor on the mosfet, 5-10 ohms is typical.The PCB looks reasonably good, the text on the silkscreen is a bit on the small side though, it probably won't print legibly. Traces look a bit thin, and your clearances between a few traces and the pads is very tight. With a few tweaks it should be in good shape.

author: law_freak
author_rank: Contributor
timestamp: January 29, 2017, 05:48:19 am
content: Thank you.I'll add the gate resistor. Why is such a small value typical?I should have known about the decoupling cap for the micro. Completely forgot.I'll take up the trace size/clearance for the smaller traces. Thanks for the suggestion. Do the larger traces for the LED controller seem appropriate in size?

author: james_s
author_rank: Super Contributor
timestamp: January 29, 2017, 06:07:38 am
content: The gate resistor is to prevent ringing. A mosfet gate is effectively a capacitor, it draws no current steady state but when the state changes it will draw a current proportional to the rate of change and when it interacts with the parasitic inductance of the traces you can get ringing. You can probably get away without it but it's just good practice to use one, resistors are cheap.I generally stick to 10 or 15 mil for signal traces, and for power and ground I try to use 30 mil or larger depending on current involved.You might add a 0.1uF decoupling capacitor across each electrolytic in the power supply too, put them as close to the regulator as possible. Like the gate resistor it will probably work fine without them but it can cause a lot of unnecessary troubleshooting in cases where it doesn't work properly.

author: @rt
author_rank: Super Contributor
timestamp: January 29, 2017, 02:09:00 pm
content: Hi, Some feedback... For any given location, given the date (and it is a clock presumably in a fixed location),you should be able to calculate sunrise more reliably than detect it with a light sensor.

author: texaspyro
author_rank: Super Contributor
timestamp: January 29, 2017, 10:28:56 pm
content: Quote from: @rt on January 29, 2017, 02:09:00 pmCalculating sun position on a micro is not all that easy. The math wants to be double precision and Arduinos only do singlle precision. Most of the algorithms you see on the web are rather poor and fall apart with single precision math... at least if you want a semi-accurate result. Virtually all the web sites that calculate rise/noon/set times are accurate to only a few minutes. Then there is the question of what rise/set time are you wanting... physical, civil, nautical, astronomical? Compensated for atmospheric refaction or not?I added a very accurate (accuracy around 1 second) sun (and moon) position/rise/noon/set feature to Lady Heather and that was quite a rabbit hole to go down. The code uses functions that calculate the sun and moon positions. For the sun position I use Grena's algorithm 5. It is quite small and fast and gives results comparable to NREL's SPA algorithm (which uses several 1000 lines of code and thousands of trig calls). The moon position algorithm is not as accurate, but one that works better is even more complex than SPA.To get rise/noon/set from position it does linear and binary searching and interpolation using a few dozen calls to the position function (linear search to find the hour of rise/set and binary searching and interpolation to refine it to the second). Heather can play a sound (rooster crowing) file at rise/set and (church bells) at solar noon. The moon rise/set calculations are more complex since the moon can rise/set more than once in a day.

author: james_s
author_rank: Super Contributor
timestamp: January 29, 2017, 11:29:23 pm
content: Seems like it would be easier to just use a lookup table. There are only 365 days in a year and surely extreme accuracy of sunrise time isn't going to be that critical for an alarm clock, probably updating every few days or interpolating across a week or so would be fine. A correction factor could be added for locale if this is something expected to be used worldwide.My other half has a commercially made sunrise alarm clock, I've opened it up and it's based on an Atmel 8 bit microcontroller, I forget which one. It makes no attempt to follow the actual sunrise, one could open the curtains for that. You just set the alarm time and the light starts to come up about 30 minutes before then.Incidentally it used to wake me up but now I sleep right through it until the audible alarm goes off, I think I subconciously pull the blankets over my face when the light starts to come on.

author: texaspyro
author_rank: Super Contributor
timestamp: January 29, 2017, 11:51:18 pm
content: Quote from: james_s on January 29, 2017, 11:29:23 pmHow dare you make such a statement!Every second of snooze time is a precious thing.There are around 365.25 days in a year and each one is a different length. Then there is the equation of time to consider that describes the difference between clock time and solar time. When plotted the difference is the width of a figure 8 pattern called the analemma.

author: texaspyro
author_rank: Super Contributor
timestamp: January 30, 2017, 12:38:12 am
content: Here are a couple of links to some sun position algorithms that are Arduino capable. I have not tested them. The second one uses a table.http://www.instesre.org/ArduinoUnoSolarCalculations.pdfhttp://www.cerebralmeltdown.com/projects/arduino-sun-position-program/

author: @rt
author_rank: Super Contributor
timestamp: January 30, 2017, 05:40:03 am
content: I’ve been using this one on various platforms since 2009, and it has proven accurate.The platforms do all have double floats though.http://www.sci.fi/~benefon/rscalc.cI’ve watched it fairly closely both by comparison to web pages, and in person hiking at various locations.Of course, with terrain and elevation, it isn’t easy to pinpoint a minute any edge of the observed disc of the Sun touches the horizon,but I did say more reliable than a light sensor which could get dirty, or see a cloudy or foggy morning,and also subject to the kind of error associated with reading any analogue signal.I’m currently using it with dsPic, and it’s output agrees with the same functions running on Sony PSP, and iPhone.Quote from: texaspyro on January 29, 2017, 10:28:56 pm

author: texaspyro
author_rank: Super Contributor
timestamp: January 30, 2017, 07:52:08 am
content: Quote from: @rt on January 30, 2017, 05:40:03 amHe basically calculates solar noon (not all that accurately) and assumes the time intervals between solar noon and rise/set are the same... but they are not.Granted, knowing sunrise/sunset to the nearest second is not really all that useful in the real world (too much local topography and atmospherics to really matter) but if you are a time-nut, it's the thought that counts.