XXI Century sundial

Update (21/03/09) : now this thing runs on Arduino also, read at bottom.

This is a simple project of a sundial wherein the pinion is replaced by a line LASER I took from a LASER level. The LASER is mounted on a RC servo which in turn is driven by a micro controller. The micro controller keeps the time and turns the RC servo accordingly.

Very basic in design it does exactly what I wanted and has as few parts as I could.

The micro controller is an Atmel Attiny24 with crystal for better accuracy. The internal RC oscillator could be calibrated but in the end the precision can be achieved from a crystal quartz only.

The schematic is very simple, just the micro with crystal and capacitors, the LASER and the transistor necessary to drive it, the servo. The power supply comes from a 5Volt wall adapter.

The micro controller runs a real time clock. Time is converted into minutes from 1:00 hours and converted in PWM pulse which is suitable to drive an RC servo. The source code is well commented, I’d say, and can be easily followed to understand how it works. In case, just comment and ask.

J4 is necessary to program the micro with the In Circuit Serial Programming faciliy like the one provided by the AVR Dragon debugger. If you have the micro already programmed (by a friend, say) you don’t need to mount that. Just be careful not to leave unconnected the R2, J2 and Pin 7 node also…

Upon power on the servo swings from about mid position of the sundial to 1:00 hours. Short pins 5-6 of J1 to make the sundial advance 1 hour at a time. Let it go a few times from 1:00 to 12:00 to see the rotation span. Then remove the short when the LASER points to the right hour.

To set the minutes it might be easier to set the time at the exact hours as the minutes are set to 0 whenever hours are set. Otherwise just short pins 3-4 of J1 counting 2 every second and remove the short when at the correct minute.

Shorting pins 1-2 adds some life to the sundial and makes it count just the seconds. Hypnotic initially, then pointless.

Shorting pins 7-8 makes the LASER on continuously, otherwise it blinks every second, like in the video below.

The circuit and software can be modified to display different things like a voltage at an analog input of the micro making a LASER analog meter. Or to make something like a LASER chronulator.

More of these circuits can be superimposed to display different values on the dial.

This is a picture of the thing.

XXI century sundial, the circuit

The servo I used is a Hitec HS-300BB, a pretty good one I happened to have in a drawer. Any other servo would do, the rotation span being probably a little bit different. It can be adjusted with the SERVO_MIN and SERVO_MAX defines but recompiling would be necessary.

I did not use a PCB, I actually built an UV bed to make PCBs but I never get to the point of actually making one…in case : http://www.instructables.com/id/The-return-of-the-dead-flatbed-scanner/

The pictures show how I attached the LASER to the RC servo : an L-shaped piece of Aluminum, a few tiny screws and a teflon fastener did the job easily. The tricky part is to make the lower end of the LASER line aligned with the center of the rotation of the servo. Anyways, misalignment might give some interesting visual effects when the LASER line does not rotate along one of its end but around a point somewhere in between like the hand of a speedometer. Just experiment.

XXI century sundial, RC servo & LASER detail

The software.

It is written in C and compiled and debugged in AVR Studio. I debugged the code with the AVR Dragon which uses the In-circuit debugging capabilities of the ATTiny24.

The code is commented and should be readable and modifiable as desired in any case a few comments follow.

#define F_CPU 2457600UL // crystal frequency

#define PWM_TOP F_CPU/60 // == 40960 is TOP count for timer 0 (goes into OCR0A)

These pre-compiler instructions define the frequency of the crystal and the value to the placed in the OCR1A register which is going to be the maximum count for timer1 before resetting to zero. We want the PWM frequency to be 60Hz. We are using these 60Hz pulses as the time base for the real time clock also.

The following lines set up Timer1 with fast PWM, no prescaler (that is, the crystal frequency goes straight into Timer1), and PWM compare output is on OC1B pin (read on)

TCCR1A = _BV(WGM11) | _BV(WGM10) | _BV(COM1B1);

TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);

OCR1A = PWM_TOP; // PWM freq = 60Hz

Timer1 now runs from 0 to PWM_TOP which happens 60 times every second (2457600/40960)

The instructions above also make the output pin OC1B high when the counter is below OCR1A and zero otherwise (PWM compare). This is PWM : changing the value in OCR1B from 0 to PWM_TOP makes the duty cycle output from 0% to 100% at the PWM frequency which do not change : 60 pulses every second, the pulses are simply thinner or larger.

The exact meaning will more clear when checked with the datasheet of the ATTiny24.

The following instruction places the servo at OCR1B output halfway between the maximum and minimum position of the servo.

OCR1B = (SERVO_MAX + SERVO_MIN) / 2;

This is not 50% PWM duty cycle, as the servo does rotate from min to max with pulses smaller than 50%, that’s why I defined SERVO_MAX and SERVO_MIN based on the the length of the pulses that place the servo at maximum or minimum:

#define SERVO_MAX PWM_TOP*1.65/(1000/60) // max rotation is at 2.35ms pulse

#define SERVO_MIN PWM_TOP*0.75/(1000/60) // min rotation is at 0.70ms pulse

Now I want the timer overflow to be used also as the timebase for the real time clock :

TIMSK1 = _BV(TOIE1); // enable timer overflow (for real time clock)

sei(); // enable global interrupts

Now every 1/60th of a second the following routine is called :

ISR(TIM1_OVF_vect) { … }

This routine does a number of things :

It counts the real time, 60 times1/60th of a second makes one full second elapsed, so the counter of seconds is incremented together with minutes and hours if required.

It also blinks the LASER for 1/10th of a second every second unless the relevant pin short strips shorted,in which case the LASER is always on.

This routine evaluates also the position to be given to the servo to make it rotate as needed. To do so the time is converted into total minutes elapsed from time 1:00 and the result scaled into the range SERVO_MIN to SERVO_MAX.

servo_pos = servo_min + ((hour-1)*60+min)*((servo_max-servo_min)/(11*60+59));

Shorting JUMP_0 makes the servo display the seconds only (9 to 59) thus the calculation as of above is made on current seconds only and minutes/hours disregarded :

servo_pos = servo_min + sec*((servo_max-servo_min)/59);

The following places the servo in the mirror position to make the LASER rotate clockwise :

OCR1B = servo_min+servo_max-servo_pos; // clockwise

// OCR1B = servo_pos; // counter clockwise (commented out)

If needed the first line can be commented out and the double ‘//’ removed from the second line : this would make (after compiling and downloading to the micro) the servo run counter clockwise.

Finally the routine also checks pin short strips for time set and sets hours and minutes if required. Minutes advance 1 every half a second while hours once per second. Removing the shorts resume regular clock display.

If you are going to modify the and recompile with AVR Studio with AVRGCC, the C compiler, don’t forget to set the fuses to External Crystal mode 0.9 to 3MHz, no watchdog, x8 clock divider disabled. All other fuses should be default.

You can see a video of the sundial below. Please trust me when I say that the light pulses much better than in the video : the bad flicker or disappearing light is just caused by low frame rate, poor camera ( and poor operator ? ). I should have shot the video with the LASER always on. Now I removed the roman lettering from my living room as my sweet half was showing some impatience.

Finally, this is a picture of a real sundial built around 1930 at Tripoli, Libya, I saw recently. Far better than the ones I used to improvise on summertime when I was a kid and didn’t mind melting under the Summer sun.

For questions or comments or anything else, just write, If you build your own, send pictures.

The hex file ready to be burnt into the microcontroller is here, the C source code is here.

The schematic for Arduino is herebelow, click for a larger view (on Flickr) :

The sketch needs the MsTimer2 library you can download from Arduino playground.

…and this one is the sketch to be loaded on Arduino.

Ciao

Alessandro

41 Responses to “XXI century sundial – Now for Arduino also !”

  1. [...] XXI century sundial – Now for Arduino also! Read more | Permalink | Comments | Read more articles in Arduino | Digg this! Posted by Gareth Branwyn at 8:00 pm. Filed under Uncategorized   [link] [...]

  2. Emperor says:

    Super Awesome project, simply a wonderful idea

  3. [...] XXI century sundial – Now for Arduino also! [...]

  4. Joel D says:

    Alessandro,

    It looks like this laser emits a wide beam of light. Is that correct? So when you mount the laser, it is perpendicular to the wall with the numbers on it. That wasn’t clear to me from reading your posting.

    Nice work!

  5. admin says:

    @Joel D , your assumption is correct. But if the beam is not perpencicular the light path during the day is not circular, rather sort of conical giving a better visual appeal IMHO.
    Thank you.
    A.

  6. [...] Toutes les infos sont disponible sur :www.5volt.eu [...]

  7. [...] XXI century sundial – Now for Arduino also! [...]

  8. [...] XXI century sundail — Now for Arduino also ! [5volt via Make] [...]

  9. [...] XXI century sundail — Now for Arduino also ! [5volt via Make] [...]

  10. [...] Allesandro, the creator, includes all the schematics you need for making your own device and even includes a video showing the kit in action. [...]

  11. [...] an axis, marking off the hours of our days as surely as old death takes our lives piece by piece. Allesandro, the creator, includes all the schematics you need for making your own device and even includes a video showing [...]

  12. [...] wirklich effizient aber sehr cool (5volt via Dvice) digg it! yigg it! wong it! del.icio.us technorati [...]

  13. [...] via XXI century sundial – Now for Arduino also !. [...]

  14. [...] Allesandro, the creator, includes all the schematics you need for making your own device and even includes a video showing the kit in action. [...]

  15. [...] 5volt, Via Boing Boing Gadgets VN:F [1.1.7_509]please wait…Rating: 0.0/10 (0 votes cast) Share This: [...]

  16. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo demostrativo.Continue reading Reloj “solar” láser [...]

  17. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo demostrativo.Continue reading Reloj “solar” láser [...]

  18. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo demostrativo.Continue reading Reloj “solar” láser [...]

  19. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo [...]

  20. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo demostrativo.Continue reading Reloj “solar” láser [...]

  21. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo demostrativo.Continue reading Reloj “solar” láser [...]

  22. [...] na filmiku odliczanie sekund. Jeśli zainteresował Was taki projekt to zapraszam na stronę 5volt.eu, gdzie znajdują się dokładne opisy oraz sposób tworzenia takiego zegara. Ostrzegam tylko, że [...]

  23. [...] Página oficial Si te gustó este post, agrega tec.nologia a tu lector RSS [...]

  24. [...] Click here to read more about how you can make one. [...]

  25. [...] A guy takes a laser from a level, a RC servo, a micro controller, and a big chunk of white wall and creates a high-tech laser powered sundial.  He also posted the instructions so that anyone can make one. [...]

  26. [...] XXI century sundial – Now for Arduino also !ATTiny24 code for driving a low current servo directly from the uc. [...]

  27. Alan Parekh says:

    Love the design. Nice and simple with very impressive results.

  28. [...] from 5Volt.eu has made this real simple and cool clock . The Laser Sundial Clock Project uses a Atmel microcontroller to move a servo with a line laser connected to it. The result is a [...]

  29. [...] from 5Volt.eu has made this real simple and cool clock . The Laser Sundial Clock Project uses a Atmel microcontroller to move a servo with a line laser connected to it. The result is a [...]

  30. [...] century sundial with LASER – Arduino sketch included too… Alessandro writes- This is a simple project of a sundial wherein the pinion is replaced [...]

  31. admin says:

    @Alan Parekh,
    thank you.
    Alessandro

  32. Sophi says:

    Does the servo have a full rotation or just 120 degrees?
    Awesome project!

  33. [...] XXI century sundial – Now for Arduino also ! This is a simple project of a sundial wherein the pinion is replaced by a line LASER I took from a LASER level. The LASER is mounted on a RC servo which in turn is driven by a micro controller. The micro controller keeps the time and turns the RC servo accordingly. (tags: arduino microcontroller clock electronics) [...]

  34. admin says:

    Ciao Sophi, the servo I used can do a 270 degrees circa. Any servo should do however.
    A.

  35. [...] think again. The only difference is that this time around things are much more high tech. Over at 5volt there is a fantastic tutorial demonstrating how to build your own laser [...]

  36. [...] moverlo, y una placa Arduino. Si quieres ver las instrucciones sólo tienes que hacer clic aquí. Tras el salto te dejamos un vídeo [...]

  37. [...] 時計の指針として動いているのはレーザービームです。RCサーボモータ(Hitec HS-300BB)の回転はATMELマイコンATTiny24で作ったコントローラ基板で制御しています。家のインテリアに一台作って見ませんか?>>5volt.euより [...]

  38. genel saglik says:

    this is a such a interesting blog…nice job

Leave a Reply

(required)

(required)

Spam Protection by WP-SpamFree