Friday, 18 April 2014

Pendulum Controlled Arduino Clock With Alarm




Introduction

Years ago when I was around 11 or 12 my grandfather gave me a clock box he made. My grandfather was a church carpenter so he made furniture and decorations for churches.
The box he gave me is made from teak wood as far as I remember, it has a nice domed front window for the clock face and plain glass for the lower pendulum part. My grand farther made the box in 1944 so 70+ years ago.
The clock box has moved around with me for years, but I never really got to use it for anything sensible. For some years I used it as a small alcohol cabinet (I'm not a big drinker), but for the most of the time it has been hidden away in the basement.
One day I watched a video from AndyDavisByTheSea creating an pendulum clock. Here is a link to the 1st video in the series.
The videos inspired me to start experimenting with my own pendulum. I didn't want to go pure mechanical as Andy, but wanted the pendulum to be the main time keeper and then use an Arduino board for the display. I also decided that I did not want to spend any money on the project. Everything had to be made from stuff I had lying around anyway.

Construction

The pendulum weight and the chime bell are both disks from an old hard drive. The pendulum rod is a ø6mm aluminium tube. The rocker is a piece of hard springy metal from a CD-drive.
At the end of the pendulum rod is a small strong magnet.

I was not really sure how to make the pendulum adjustable. As I only had one aluminium rod in house, and I did not want to go buy a new one, I had to be careful not to cut it too short while experimenting with the pendulum length. So after some drawing and experimenting I came up with a quite simple solution allowing me to make both coarse and fine adjustments.

Sketch of the pendulum length adjustment.

The first version of the pendulum adjustment. This construction allows me to do a coarse adjustment with the two pine wood mounts and do fine adjustment with the round top nut. 
The two aluminium angles are mounted on the wrong side of the disc on this photo. 
They are supposed to sit on the back of the disc so they don't block the disc.

Coils

I tried using different home wound coils, but soon realized that the power needed to drive the pendulum was so minute that the small coil from an old electrical toothbrush was enough. This coil also uses much less current than my home wound coils.

A couple of my initial coils. One with core and one without.


This is the coil from the electrical tooth brush I decided to work with.

The rocker mechanism

It has been quite a challenge to create a rocker that was stable, smooth and frictionless. My first attempts used a couple of small ball bearings. This worked quite good, but because the ball bearings are very sturdy in the axial direction, they also required the clock to be placed very accurately. (I live in an old Amsterdam flat, so neither walls nor floors are straight.) The construction was also to clumsy for my taste. So I decided to use a ‘knife’ construction for the pendulum.
This gives a very low friction, and it is quite insensitive to the placement of the clock itself as I could quite easily create an adjustable rocker assembly.
The rocker interrupts the light from an old light barrier, I think I got that from an old HP printer.

The spring loaded rocker assembly. The distance screws at the back are fixed, the two in the front can be adjusted to make sure the rocker is perfectly horizontal.

The height of the light barrier can be adjusted with a small screw. This adjustment determines when the coil ‘fires’. 

Close-up of the rocker and the adjustable light barrier. As can easily be seen here, everything is made from old scrap.

The placement of the coil is very critical to how the pendulum works. It is very important that the coil is directly in line with the pendulum movement. Else the pendulum will jitter. Also the offset of the coil is very important for the swing of the pendulum. And the distance from the pendulum tip (magnet) to the coil also influences the pendulum swing greatly.
On top of that comes the current through the coil and the length of the pulse. The coil is only supposed to give the pendulum a very small kick and the pulse cannot be so long that is attracts the coil after it has swung by the coil.

Here experimenting with the trigger time and pulse length using long exposure on the camera.

The strength and the length of the coil pulse is easily adjusted with the circuit, but the mechanical adjustment was quite a challenge. I needed to adjust in tree directions. For the X and Y position I came up with the design shown below.

The elongated holes allows me to adjust the coil position in the X and Y direction.

The X and Y position of the coil can be adjusted sliding the coil left, right, backwards and forwards. The height adjustment I still need to figure out.

Close-up of the chime mechanism. The “bell” is made from a disc from an old hard drive just like the pendulum. The disc has a nice crisp sound when hit with the little wooden hammer. The two rubber suspensions come from an old CD-drive.

The chime will sound X times every hour, two short at a quarter past and a quarter to the hole hour and three short chimes at half past the hour.

I don’t expect the clock to be highly accurate. Temperature and humidity will probably have quite an influence on the precision because I use ordinary MDF or pine wood for construction. But for home use I think it should be more than good enough. Anyway the pendulum will be driving an Arduino for the clock display, so I can always do some compensation there if needed.
Currently I just use a LCD display, but it is my intention to create a clock face with a ring of LEDs like the one I build back in the 80’s. Though in this version I want to be able to see through the centre of the display so the rocker mechanism will be visible.

My old LED clock I build in the 80’s. It is using all 40xx parts on a single sided circuit board, hence the large number of top wires. Time keeper is taken from the 50 Hz net frequency.

 
Just a peek inside while ticking away.


 
The chime sounds a little harsh here, mainly because I used a small metal screw in the hammer head, but also because of my old but trusty camera. In the current version I have removed the screw. That gives a softer sound. Also the chime sound is dimmed when the lid is closed.

Electronics

The electronics driving the pendulum is very simple, just one 4093 quad Schmitt trigger Nand gate. I have seen even more simple analogue circuits, but I decided to take the more digital route. 
Block diagram of the pendulum driver.


The small circuit reads the pulse from the light barrier, creates a short pulse using a mono stable flip-flop and a small driver transistor for the coil. At the bottom right is the chime driver.


Very simple circuit board for the pendulum driver. I’ll probably redesign this later when I start to implement the ring shaped clock display.


The second pulse from this circuit triggers one of the interrupt pins on the Arduino.
The Arduino program is in this first version very simple. It simply counts the second pulses, and converts them to minutes and hours. The result is displayed on a 4 x 20 character LCD display. 

Control application

To adjust and measure the accuracy of the pendulum clock, I have created a small control application that prints a graph over time, showing the time variations. I used my function generator to generate a 1 Hz pulse to calibrate the readout.
The application also enables me to get and set the time of the clock, set the alarm time plus a few test functions.

Screen shot of the control application for the pendulum clock. It graphs the time variations in micro seconds compared to a 1 Hz signal from my function generator. The red graph is the current pulse time. The blue is averaged over the last 5 minutes.

Update: 12-05-2014

Ring display and new control board

I have finally finished ring display, this is the first time I have used a large amount of SMD components, so I have spend quite some time on designing the circuit board. This is also the first time I work with through hole rivets. I did practice on a few 'failed' boards so I didn't mess up the final board and the result is actually quite good. The through hole rivets I used are ø0.6 * ø0.4, so it was quite fiddly, but using one of those dentist 'pokers', the handling of the small rivets went smoothly.
I managed to fit the whole display on two pieces of 100 * 160 mm double sided board by splitting the ring up in 4 equal pieces.

Each of the ring display parts are soldered together on both top and bottom side at the edge. This makes the display quite sturdy.


The assembled ring display. Next to it the dental 'poker' I used for handling the through hole rivets. Unfortunately you can't see the pointy end on this photo.
It' alive. Well the photo is a little blurry (no flash and no tripod)
 
Well it is Saturday morning - Nigella Lawson is cooking away in the background. 
So time for a quick look on the display powered up with some test code. The flickering comes from the camera.
Close up of the ø0,6 * ø0,4 through hole rivets.


Ring display mounted for the first testing. I wanted to be very careful when mounting the ring. It has to be spot on center and I did not want to drill any 'faulty' holes in the box my grand farther made more than 70 years ago.

New Control board

The new control board contains both the driver for the ring display and the pendulum control from the old board. This board is also double sided, but only contains through hole components. This is mainly because I already had all the components in house. On this circuit board I also used through hole rivets, but I used a little larger rivets, ø0.8 * ø0.6 to match the pin size of the IC sockets.
The new controller board. Upper part is the pendulum driver, the lower part is the display driver.






The updated circuit board. Upper circuit is unchanged from the first version. The lower circuit is the display driver using four 74HC595 Shift registers. 
I use 1k current limiting resistors. This gives more than adequate light both in daylight and at night. As an experiment, I have added a photo resistor (LDR) together with a 10k series resistor, and feed the divider voltage to one of the analogue inputs of the Arduino. With that I can adjust the intensity of the Leds. I probably build that on to a small shield as I'm not sure I want to create a new version of the driver board just for two components, one of which will have to be mounted off board anyway.

Here are a few new pictures of the latest development.
Arduino Shield for the Real Time Clock module, menu buttons (from an old HP Ink Jet printer) and connectors for the main board. The spun wire goes to an LDR so I can adjust the brightness levels for day and night.
The painted chime. The copper wire at the bottom limits the hammers bounce back swing.

Everything is mounted, more or less. The wiring is still a little bit of a mess though.
While testing I mounted my LCD display on the ring display as can be seen here. But I have decided to keep it, maybe replace it with a 2 row version. I do need a display when setting the clock and alarms and luckily it is out of view when the door is closed. As a unplanned extra the Led on the back of the LCD display casts a faint red light on the main board mounted on the backwall of the clock.


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.