Introduction: High-speed Clock for Slow-motion Videos
This is an entry in the
Epilog Challenge 9
Almost everyone with a modern smartphone has a high-speed camera that can be used for making spectacular slow-motion videos. But if you want to show how long it actually takes for that soap-bubble to burst or that watermelon to explode, you may find it hard to display the time on your videos: a stopwatch has a very small display and has a precision of only 1/100th of a second. If you want to do quantitative measurements, I found out that the published frame-rate is not something that you can really rely on!
Fortunately, it is really easy to construct a clock with ms precision and bright large digits using an Arduino and a 4-digit 7-segment display. Moreover, the 12 pins from a standard 0.56” display exactly match the pin-layout of the Arduino Nano, and can be directly soldered onto it.
There is no start/stop/reset on this timer. It just starts running when you switch it on and overflows after 10 seconds. The idea is that to measure the duration of a certain process, we anyway measure the time difference between the end and the beginning.
Step 1: Materials
- An Arduino Nano, without the headers soldered onto it.
- A 0.56” 4-digit 7segment display. Both common-anode or common-cathode are OK
In case you want to put it in a sturdy box, and be battery-operated on 2 AA batteries, add:
- A 60x100x25 electronic project box
- A 2xAA battery holder
- A step-up mode
- A 10x15mm on/off rocker switch
- Soldering iron
To mount it in a box:
- A rotary tool to crude-cut the holes for the display and the switch
- Hand-files to fine-cut the holes
- A hot-glue gun to fix the components in place.
Step 2: Connecting the Arduino to the Display
Amazingly, the pins of a standard 4-digit 7-segment display match the layout of an Arduino Nano in such a way that all 12 pins of the display connect to IO pins of the Arduino. This allows to solder the display directly on the Arduino without needing a PCB, connectors or cables.
Solder the bottom pins of the display (recognizable from the decimal dots and the print) to the analog pins A0-A5. Solder the top pins of the display to the digital pins D4-D9.
Red LED’s have a voltage drop of only 2V, so connecting them to a 5V is usually not a good idea, and a series resistor is usually applied to limit the current. However, maybe due to the interleaving, I found that it works OK without series resistors. If not, here is a detailed instructable on how to add series resistors directly on the Arduino Nano
Step 3: The Code
Upload the attached sketch to the Arduino Nano. The present code is for a common-anode display, but the lines for common-cathode can be uncommented.
Once the code is uploaded, the timer should start running every time the Arduino is started up. You could stop here or see in the next section an example how to mount it in a sturdy box and make it battery-operated.
Some comments about the code:
The time is taken from the micro() functions, instead of the millis() function, for two good reasons: The Arduino implementation of millis() is terrible: they increment every 1.024 ms, and then once in a while a millisecond is skipped to compensate! Not all Arduinos have high-precision crystals. If you find that you are off by more than a permille, you can adjust the divider in the line “unsigned long t=micros()/1000 ;” to make the clock go faster or slower.
The digits are interleaved, meaning that only one digit is lit at a certain time. When changing the segments of a digits, all digits are off, so that on garbage digit is shown at any moment. I measured the update frequency of the digits to be 750 microseconds, so every digit gets update at least once at every millisecond!
I have not seriously optimized the clock for speed, since the present speed is good enough for displaying milliseconds. I think the Arduino could be made to show two digits more (corresponding to the 100 and 10 microseconds), but it would require
- Disabling interrupts and directly use the timers
- Direct port manipulation
- Connecting all segments to a single port and the digits to another port
- Avoid explicit calculation of digit values, but use increments instead (division and modulus operations are slow)
If I could get a hand on a slow-motion camera with >1000 fps I could give it a try, for now I’m happy with ms precision.
Step 4: Mounting It in a Box
A cheap 100x60x25mm electronic project box, not waterproof, easily fits this timer, together with batteries, a step-up module and an on/off switch. For battery operation, a combination of 2 AA batteries with a step-up module will give a safe and stable 5V voltage to the Arduino. By putting an on/off switch directly on the battery (instead of on the output of the step-up), the batteries are not affected by leakage from the stup-up module, and can last years, if used sporadically.
The step-up module that I used had a female USB connector, which I removed with pliers, in order to be able to solder wires to the output. Alternatively, you can use a regulable step-up, and set it to 5V output.
Start by cutting out the two holes that correspond to the display and the on/off switch. I drew with a pencil the approximate holes, then cut out the holes a bit too small with a rotary tool, and then filed them with hand-files to the exactly matching size.
Cut off some of the multi-strand flexible red and black cable from the battery box, and connect them to the step-up module, with either the positive or the negative interrupted by an on/off switch. Then from the step-up module straight to the GND and the +5V or the Arduino.
I used hot-glue to keep all elements in place: the battery box, the step-up module, and around the sides of the display.
The end result is a timer in a sturdy box with a dead-simple operation!
We have a be nice policy.
Please be positive and constructive.