Monday, 5 December 2011

Arduino Alarm Clock with Wake-up Light

Prefix
This post will be a continuous babble  about my progress in building an alarm clock based on the well known Arduino Uno. The content and structure of this post will change as I go on. So this will very much be a Work in progress post.
I will not go in to deep details about solutions to general or known problems in this post. In stead I will link to the solution and thereby giving the proper site/author the credits and also avoid introducing errors.

This is my first bigger usable project using Arduino.



Introduction
For quite some time now I have wanted to have one of those wake-up lights. There are a few on the market, but I find them either too expensive and not very nice.
After having played around with the Arduino for some time now I decided to go ahead and build one my self. With the Arduino and a few extras this should be easy to do - I thought. But here and there I have been running in to problems.

Because this build have to be used on a daily basis, and it must be very stable - and not to forget - It will be one of the first things I will see in the morning, so I want it to be easy to use and nice to look at.

The wake-up light will be a quite prominent feature of the alarm clock, which gives me a few difficulties in deciding on a design. But I will get there - eventually. My Danish roots often lead me to what I call B&O design. Not that my design will get even close to their design (I wish), but I will try to at least keep the design and usage as simple and functional as possible.

Other problems have mainly been down to my lack of knowledge about C++ programming. I come from the C# world and I am used to work with all the tools and helpers build into Visual Studio’s programming environment. But with thanks to this instruction I am now able to do the programming in Visual Studio, which does make things go a little more smoothly.

So after many ‘happy hours’ of programming I finally have something that works, at least in my bread board version. There are still a few issues and elements that have to be build and programmed, but the main functionality is more or less there.

At the end of this post I will keep a to do list.

Hardware
Arduino Uno
DS1307 Real Time Clock
LCD Display
LED wake-up light and driver
6 button analogue keypad
AM/FM Radio module
Audio amplifier
12V Power supply


Basic Functions 
Display Time with large digits
Wake-up light
Alarm or radio
Sleep function
Set-up menu
Quick Settings menu
Manual control of light and radio
Info display

Arduino Uno
It should be no surprise that the Arduino Uno board will be the heart of the alarm clock.

Real Time Clock with battery back-up
The alarm clock is equipped with a DS1307 real time clock module. The real time clock has a back-up battery, so the time is not lost if the power should fail.

The real time clock is not the most precise I have ever seen, so I might have to get the 'big brother' at a later stage. But because I can easily update the time, either via USB or just adjust the time manually on the clock now and then, I will keep this version for now.
I have thought of adding an auto adjust function to automatically update the clock once or twice a month, to compensate for the inaccuracy of the RTC. I will need to see how great the inaccuracy is - at the moment it seems to be loosing a couple of minutes in month - which is quite a lot if you compare it to the accuracy cheap clock modules you buy for next to nothing.

The real time clock is connected on the I2C bus. Getting it to work didn't cause any problems. And there are plenty of information to find on the web if one should get stuck.

As mentioned the real time clock keeps its time even if the power is turned off. Other settings that should be kept when power is off or by power failure are; Alarm time, snooze time, wake-up light fade in time, radio frequency etc. All these settings are stored in the EEprom on the Arduino. This means that the alarm clock will continue waking me up in the morning even after a temporary power failure.

LCD Display - Displaying large digits
The display used is a standard HP compatible 2 x 16 characters LCD display. I have made a small circuit board that fits at the back of the LCD display. This circuit drives the display as a three wire interface using a shift register. See  this blog for details.

To be able to show large digits a set of special characters have been created.

On this picture you can just get a glimpse of my add on print.
Update:
After playing around with the I2C bus, and realizing how easy it was, I decided to buy a new LCD display that like the real time clock also is controlled over the I2C bus. This LCD display is blue with white letters and is back-light. The blue display does look much nicer I think.

A very premature version of the current set up. The blue LCD does have a nice look to it.
Alarm On/Off indicator
For the alarm on/off indicator the colon ‘:’ between hour and minute is used.
If the alarm is off the hour/minute separator dots are blinking at the same time, once a second. If the alarm is on, the separator dots are blinking alternatively.  This gives a clear, yet discrete, indication of the alarm status. The blinking speed shown below is not accurate.

Alarm is On
Alarm is Off
Wake-up light
The alarm clock has a wake-up light function. The wake-up light gradually increases light intensity from 0 – 100% starting 30 minutes (default) before the alarm goes off.
For the wake-up light 84 bright bluish (465nm) LEDs are used. The LED panel was used for a winter mood light, published in Elector some time ago. The colour of the LEDs should be specifically good to help against winter mood. Still have to see if this is fact or fiction though.
The LED panel will be driven by one of the PWM outputs through a MOS-Fet driver. Because this neither have to be high speed nor high power I have just used a simple driver. The extra transistor is there to help turn the MOS-Fet totally on and off. The 5 volts from Arduino was not enough with the Fet I had on stock.


LED Panel



The original LED panel for the Wake-up light.

Update: 5-11-2011 - The blue LEDs does not produce enough light. As a LED panel for the winter mood light it gives sufficient light, because you are supposed to have it quite close to you when using it. But for lighting up my bedroom they are too weak. So I have ordered a bunch of bright white LEDs now and will have to see if this works better. I hope so – because there is going to be a lot of drilling and soldering.

Update: 7-11-2011 - The LEDs are now in, and I have done a quick test, with just 24 of these babies; the bedroom is just bright enough to read a book. So 80 should be enough to have the room fully lit.
Unfortunately my printer has stopped responding, it does not like the non original Epson cartridges I presume. That means I can't get to create new circuit boards until I get a new one. I probably buy a laser printer this time. I hope I will get better transfers with that. Have a look at my babble about how I create my circuit boards. 

Update: 12-05-2014 - I have replaced the LED panel with 3 power LEDs. I only run the LEDs  at 300mA, this gives a good reading light, and keeps the temperature so low that I only little cooling. The 3 LEDs are mounted side by side on a piece of aluminium.

Update: 19-11-2011 - Finally got a new printer. Went for a Samsung Colour Laser printer. The printer was quickly up and running - so I have made the first few tests today. When I saw the first transparency print, it looked very, well transparent, not the full cover I'd expected. After fiddling around for a couple of hours, with colour settings, contrast, print quality e.t.c.,  without getting a much better result, I tried to make a small test print. The result was surprisingly  good. So it seems like the toner is very efficient in blocking the UV light despite the, in my opinion, very thin layer of toner.

The first attempt using my new printer. Most tracks are 24mill.
Using a laser printer is not only faster, it also gives a much sharper result and is much less of a hassle. With the old ink jet printer I had to wait for hours for the ink to dry totally - before printing the same sheet again, to get a proper coverage. 
The above circuit board is the main board for the alarm clock and only took a couple of hours to make.

Detail of print. A few specks of dust has landed in the fix spray.


The Alarm
For the alarm sound I use a small 8Ω speaker, from an old phone if I remember right. The speaker is driven with just a normal small signal transistor, 2N2222 from the stock pile, with a current limiting resistor in series with the speaker. Using the tone library I can easily adjust the frequency or the annoyance of the alarm.

Speaker driver for buzzer.

Snooze function
The alarm clock has a Snooze function that extends the alarm time with 9 minutes (default) when pressed.

The Radio
The radio is a pre-build module from Sparkfun. It contains an AM/FM radio. In my set-up I will only be using the radio in FM mode.  At the moment I'm not sure if I want to build a small audio amplifier or just use an existing set of PC speakers with build-in amplifier. Currently I'm just using my old PC speakers.
The radio module does have a bug though, so it had to be modify. Fortunately the modification is quite easy made. A small signal diode is soldered between GPO1 and pin 12 and the track is cut. See also this link for full details.

There is very little space to solder the diode, but with a little patience it is possible.
 In the above image I have bend to VRef pin so it doesn't connect to the Arduino Board. If connected the Analog inputs does not respond and I do need them for the analogue keypad and the I2C bus.

The diode just fits in the existing holes.


Sleep function
The sleep function can be set from 15 minutes to 90 minutes in intervals of 15 minutes.

The analogue keypad
To save pins I have chosen to go for a simple analogue keypad with 6 buttons. The buttons are menu, enter, left, right and up, down. The navigation buttons and enter button is placed in a typical 'joystick' like layout, the menu button is made somewhat larger because it is also used as the Snooze button.

Analogue Keypad



Button functions of keypad.




Simplified work flow
The work flow of the alarm clock is quite simple. The biggest challenge has been to create an easy to use set-up menu.


I will post the full code when it is bug free and cleaned up.



Here is my very simplified pseudo code.

Setup() {
  Initialize
  Read Eeprom
}

Loop() {
  GetCurrentTime()

  if (lastSecons !=  currentSecond)  {
    Get current time from RTC
    Check alarm time and wake-up light time
    Display Time
  } 

  key = CheckKeypad()

  switch (key) {
    case btnMenu: Execute Set-up menu
    case btnDown: Execute Quick Set-up
    case etc...
  }
}

Download
The  current version of the source code can be seen here. This is my working code, so neither optimized nor bug free. There are still some loose ends here and there.
 
In the setup() method, after the initialization, settings such as alarm time, snooze time and so on, are read from the Eeprom.

In the main loop() method, the time is read from the real time clock. The current time is compared with alarm time and wake-up light time and a flag is set if the comparison is true. The display is updated once every second.

When not updating the display or checking the time, the keypad is checked and depending on the key state and the state of the alarm clock, running, alarm on and so on, the appropriate function is executed.

I have split the set-up menu in sub functions for setting date, time and numeric values. While in the set-up menu the main loop is not executed.

The box
I have started to create a box for the alarm clock. I'll keep the box as simple as possible, mainly because my limited tool collection. The box will be build from 3mm MDF board. It's easy to work with, and though this MDF is very thin, it is still possible to create a quite sturdy box. I have also been using MDF for my other projects.
I have decided to use external speakers for the alarm clock. There are a couple of reasons for that. Firstly - Using internal speakers would make the clock much too big, at least if I want an acceptable sound quality. Secondly - I already had a set of old PC speakers that sounds reasonably good. The disadvantage here is the two extra wires, power and signal.

I found an old 'universal' remote in one of my drawers, that newer worked for more than 5 minutes before loosing its settings. So I decided to use the buttons for the alarm clock. The buttons is made from the usual semi soft - nice to touch rubber. Five of the buttons are placed in the typical Up, Down, Left, Right and Ok fashion. See photo below. The power button, which is used as the Menu/Snooze button, is not as large as I would have preferred, but it serves its purpose. The original text and symbols on the buttons I remove with fine sandpaper.
With a jigsaw I cut out the holes for the buttons, it was quite a fiddle to do but I think the result turned out Ok. A small circuit board, with the 6 push switches, is placed behind the rubber buttons.

Here are some photos of the box:

Box with the holes in place. The holes are cut with a jigsaw. 
Wish I had that laser cutter though.

Inside of the box, with the buttons in place. The base is clued together with wood glue. 
Only the top and back uses screws.

Circuit boards added. A little annoying that Sparkfun, the designers of the radio module,
have placed the audio plug on the wrong end of the board.

Front view. Here I still need to remove the printing on the buttons.

Top view.

Wake-up light closed.

Back view. Antenna, USB, audio out, speaker and power cord.


Links
Circuit diagrams are all created with Eagle editor.
The Arduino Uno board and LCD displays are bought by iPrototype.



To do and extras. 
Multiple alarms.
Week Schedule.
Sleep function.
Auto adjust time to compensate for RTC inaccuracy.

Tuesday, 28 September 2010

UV Light Box

Makes it much more fun to make printed circuit boards.

When I began working with electronics again after a long break, I quickly realized that I needed a UV light box to produce my circuit boards.

Breadboards and test prints are good for prototyping, but at a certain point is it necessary to have a more robust and portable version.

When I make printed circuit boards I use positive photo printing. The layout I print on transparencies on my ink-jet printer. To get good coverage I need to print layout twice on the same sheet.

Update:

The old ink jet printer gave up and have now been replaced with a new colour laser printer. I no longer need to do double printing to get a good result. That saves oceans of time, because the old ink jet transparency needed to dry totally between prints. That could easy take a couple of hours with the ink I used, even using a heating source to speed it all up a little.
The first test prints on the new printer have been quite successful. I was a little sceptic when I saw the first transparencies though - they looked quite weak, but to my surprise the result was surprisingly good. This circuit board only took a couple of hours to get to this stage. The circuit board obviously still needs the drilling.



The UV light box is made from 9mm MDF (Medium Density Fibreboard). The light source is a 8W UV-A lamp that I have taken out of an old handheld face browner I had lying around from my more vain days. After some experimenting I found the optimal exposure time to be about 25 minutes. So of course I needed a timer circuit.


The first version was a simple timer, with the familiar 555 as the main component. It worked OK and served its purpose. But I wanted to be able to get an indication of the time left, so I decided to build a new timer using CMOS technology. This time with the proven 4000 series.


The cover is locked with a small snap lock.
The UV light and reflective parabola.
The parabolic reflector is made ​​from ordinary kitchen aluminium foil glued to thin cardboard. The UV bulb is placed in the focal point of the reflector. A piece of perspex is used as the top. On the inside of the lid, I have placed some adhesive rubber foam to keep the PCB in good contact with the layout of the film.

The initial timer was build around the well known 555 timer.
Running.
There is drilled a small hole in the lid and a piece of clear plastic is inserted in the hole. That way I can see if the lamp is lit. I suspect that it will give up one day.

UV lamp was purchased somewhere in the mid 80s. Fortunately, I almost never used it, so with some luck should be able to use it for quite a few cycles before it burns out.

The wire can be curled up for easy storage.
The finished UV light box. Now with a digital timer build with the good old 40XX series CMOS.
The new timer from can be set from 1 to 99 minutes.

Saturday, 5 June 2010

Circuit Board Etcher

Small portable circuit board etcher.


After having had a several years long break from working with electronics I have finally got started again. I started with building very small projects build on experimental board. Quite soon though, I wanted to make proper circuit boards. It is not really a big job to make your own circuit boards. It just requires some good working space and the proper equipment. Living in a flat in the centre of Amsterdam, space is sparse. So I have been creating my circuits on the kitchen table. But mixing photo print developer and etchant with food production is not an ideal situation.

So to keep things a little more efficient and less space (and time) consuming I wanted to build a device that would do the etching without me having to stay constantly over the whole etching process. And more importantly; when finished etching it is easy to clean and store the etcher in the cupboard.

The Etcher

The etcher has been build entirely from materials I had lying around. Well almost - I bought the power plug so I could avoid having to sling around with a fixed wire. This also makes the etcher easy to store in the cupboard when finished etching.

From another project I had a few pieces of 4mm MDF over. Looking through the kitchen cupboards I found a transparent dishwasher proof food container with lid. The stepper motor and the cog are from an old HP Ink-Jet printer. I never got to use the motor because of its quite low step resolution. Fortunately the stepper motor is quite strong, taking its size in to consideration. The only special component is the stepper driver IC. I had a couple of the driver ICs in my component drawer from some experiments I had been doing some time ago. The rest of the components are all standard components.


The stepper motor has a resolution of 48steps/revolution.


The etcher will tilt the etchant container slowly up and down with the help of an eccentric wheel attached via a cog to the stepper motor. The eccentric wheel is, like the box, made from 4mm MDF. It was meant for testing purpose only, but turned out to work quite well. I polished the rim with fine sand paper and gave it a couple of layers of floor varnish to make the surface both extra smooth and hard. The eccentric wheel only needs to lift a couple of hundred grams so the wear and tear is quite limited.

With my initial build I mounted the eccentric wheel directly to the cog on the stepper motor. This made the whole etcher vibrate quite a lot and made it very noisy. I tried to run the stepper motor in half step mode and that reduced the noise to a quite actable level. After doing a few etches though I decided that the noise was too much anyway. So I mounted an extra cog between the stepper motor and the eccentric wheel. That also meant that I could increase the speed of the stepper motor and thereby reducing the vibrations and make it nearly silent.

The initial eccentric wheel mounted directly on the stepper motor. This caused the whole etcher to vibrate and be quite noisy.


Using a cog between the stepper and the eccentric wheel allowed me to increase the speed of the stepper and thereby reducing the noise to a minimum.


The etcher box is build from 4mm MDF I had lying around. I glued the pieces together with good wood glue. I attached a piece of piano hinge to the back and lid of the etcher to allow both the tilting of the etchant container and to give access to the circuit board.

Under the hood.


The Circuit

The circuit diagram below contains stepper motor driver with speed control, the temperature control and power supply.

Circuit Diagram


Stepper Driver

The stepper motor I have used is actually a 6 wire bi-polar motor but I use it here as a 4 wire uni-polar motor. The reason for that was basically that I had a driver for that configuration lying in the drawer.

The stepper motor driver is build around an H-Bridge driver IC - MC3479. The stepper motor has a quite low step resolution (48 step/rev.) and it is rather noisy if run at a low speed.

The clock input of the stepper motor driver is created by a simple oscillator build around the well known CD4093. This is a quadruple 2 input NAND gate with smith trigger input.

The speed can be adjusted so that the etchant slowly waves over the circuit board to be etched.

Heat Control

I am using natriumpersulphat for etching. This etchant works best at a temperature between 45°C and 50°C. To heat the etchant to the optimal etching temperature, some kind of heating element was needed.

My initial idea was to use some length of constantan wire for the heating element. But that gave me a couple of challenges to overcome. Firstly; my local electronics store only sells constantan wire in big roles with several hundred meters of wire and costing nearly €60. I would only need a few meters so I thought it was a little over the top. Secondly; I would have to build some kind of mechanical frame to hold the constantan wire.

Another idea was to use some power resistors. That would be a cheap solution, but again the mechanical build would be bulky and unpractical. So after a few calculations and experiments with a circuit board I decided to try it out.

The heating element is simply made from a piece of 100 x 100 mm thin circuit board with one long single track. The total track length is around 5.5 m. The track width is 12mil (0.012”) that gives a resistance of the track just around 12 Ohm. The heating element is glued to the etchant container with heat resistant epoxy glue to give a good thermal connection.

The heating element glued to the bottom of the etchant container with heat resistant epoxy glue.


The heating element is connected to the box with a short length of wire and a plug. This makes it possible to detach the etchant container for rinsing, cleaning and storage.

View of the etcher with power cord, stepper motor and connection to the heater.
The whole unit is fed from a 2 x 9V 1.5Amp ring core transformer. Again; I had it lying around from another project that had been shelved. The transformer is therefore also slightly under dimensioned - but I didn’t want to go buy a new one - they are quite pricy. Because of the under dimensioned transformer the speed of the stepper is slightly slower when the heater is on because of the voltage drop.

The heater gets fed from the total 18V. The rest of the circuit and stepper motor is fed from one 9V winding only.

The temperature is controlled by a very simple circuit build around a second gate of the CD 4093 smith trigger. It uses a voltage divider consisting of a 15k NTC resistor and a 10k trimmer. The midpoint of the voltage divider is fed to the input of the smith trigger which drives a transistor that switches the relay off when the desired temperature is reached. This is a very simple solution but in my setup it works like a charm. It keeps the etchant temperature just around 47°C.

The NTC resistor is mounted under the etchant container and is spring loaded so it stays in good thermal contact with the heater. So I do not measure the temperature of the liquid but the temperature of the heater itself. I used a normal thermometer, while doing the adjusting, to measure the temperature of the liquid.

The etchant container sits on a piece of 5mm thick foam. Mainly to keep the noise to a down, but it also ensures a good thermal contact between the NTC resistor and the heating element. It also makes the container sit quite sturdy. In the initial build it had a tendency to glide around, like when a mobile vibrates on the table.


The 'spring loaded' NTC resister from the top and bottom.

The heating element can heat 1dl of etchant from room temperature to 45° in about 15 minutes. If preheating the etchant, the heater only needs to keep the temperature to the desired temperature while etching.

I usually pour the etchant in the etcher and start it at the same time as I start to expose the circuit board in the UV light box. In the time it takes to expose the circuit board the etchant has reached its optimal temperature. It now only needs to be kept the right temperature by the heating element. I use a light box build around an 8W UV-A lamp hacked from an old face browner I bought years ago in my more vain days. See this post. The developing of the photo print takes about 25 minutes with the mentioned lamp so that leaves plenty of time to raise the temperature of the etchant.

Etching a circuit board

Here you can see the progress of the etching process.
The circuit board immediately get a pinkish colour.

The etching is in progress.

Just a few minutes left.

The finished circuit board. Normally I do not use hatch pattern, so this was kind of an experiment.



Circuit Board

Below is the circuit board. You can download the corresponding Eagle files here .



Work Bench

Let the chaos be gone.

A place where I can keep my electronics and do my experimenting - and still have a tidy living space.

Ever since I was a young lad, around 12 years old or so, I wanted to own a bureau or chatol, as it is called where I come from. I think my fascination came from a bureau , I saw in an old antique shop, in the town I grew up in.
That, of course, was a proper bureau. It was made from beautiful dark wood. It had loads of drawers and doors and of course some secret doors and drawers too.

At that age I started working with electronics as a hobby. Being four brothers in the same house, meant that there were quite a bit of sharing spaces. So a bureau would be perfect for all my experimenting. I never got around to get one, but coming from quite a creative family, I decided finally to try to build my own simplified version. Now I only hope my old childhood dream finally comes to good use.

Well I haven't aimed to build a it like the one I saw in the shop. First of all, it would be way too big and way out of my comfort zone. The content of my toolbox is limited to a nail file and a pencil sharpener (more or less). So I have to, and want to, keep it simple. At least for this - my first piece of furniture.

It is just supposed to be a place where I can work with electronics and be able to literally close the lid when taking a break, without having to clean everything up.

Living in an Amsterdam flat, in the middle of the old city, space is very limited. So every corner has to be used to its optimal, without making it in to a total clutter of course.

As you can see on the images below, one drawer section can rotate outwards to give more leg space when sitting working. The total width of the chatol is 110cm. I obviously wanted plenty of drawers on both sides. The drawer section on the right side is 30cm wide and full depth, 40cm. This fits an A4 with room to spare. The swing drawer, as I have decided to call it, is 40cm wide and 30cm deep. This gives 50cm of leg space. That is enough while sitting, but when getting up you will bump into one of the drawer sections. So by swinging one drawer away while working, gives just that extra space needed. I could have made a drawer on wheels, but that would make the construction unstable.

Here under is a model I made from 4mm MDF. I wanted to check if my design was stable enough. The full scale version is made mainly from 18mm MDF.

This small model is actually amazingly strong. I’m not sure if this is a scientific correct approach. But I have trusted my instincts and started the build.


This is a scaled model to check the stability. It is made from 4mm MDF and cardboard. And a couple of tooth picks :-)


Well it's not too way off.


Only the kitchen could do with a kind hand.

http://www.microshan.nl/UserFiles/Image/WorkBench/Img_1148.jpg
Oh - what to do with the wall socket?


Yes it swings!


Just need to cut out the bottom plate.


First test run. I just couldn't help it.
By the way, look at that kitchen table. It's all shiny.



Oh the everlasting paper stacks. Soon I will get rid of them. Or at least stuff them in one of my new drawers.


Well, just another angle. But I haven’t got the faintest idea what colour to give it.