Arduino DCF77 radio clock receiver
November 5, 2006 – 9:31 pm
As a first sketch, I developed a little DCF77 library for the arduino. The DCF77 sender broadcasts the exact time in Germany. It uses a binary format which needs to be decoded - which is exactly what the library does.
There are others around who wrote a DCF77 decoder: I would like to thank Captain for his DCF77 code. You need to have an Arduino and a DCF77 receiver in order to use this sketch.
I use the “DCF-Empfänger BN 641138″ of Conrad. You need a pull-up resistor as displayed here:


When everything is connected, the exact time is printed on the serial line. Note that this is a very early release of the software - there is a lot of functionality missing. From the README:
The current todo list is: * Use interrupt routines for detecting signal changes * Use interrupt routines to add seconds automatically (currently, the 59th second is shown properly) * Implement parity checks to prevent faulty time signals to be evaluated
The sketch eats up 6400 of the 7168 bytes in the Arduino. I am currently considering to upgrade my board to the ATMega 168 processor in order to have 16kb of memory…
You can download the code here:
The code is released under terms of the CC-GNU GPL.
11 Responses to “Arduino DCF77 radio clock receiver”
hallo, nice idea!
But is it so that the Arduino can get the time ONLY when you plug in the DCF77 or time is checked every now and then?
Thanks
Ale
By ale on Jan 26, 2008
In a private eMail, ale asked:
“Does your arduino code check the time on the DCF77 only once or it updates the time once in a while? I’ve read you still didn’t implement interrupts, but may be there’s a dummy time-update every.. ‘n’ seconds?”
Actually, the time is only updated when the DCF77 receiver is connected. I receive an external interrupt each second from the receiver. While I update my internal buffers, I also update the current second counter. If the received time is valid (i.e. the checksums match), I use this time as the current time. If something goes wrong, I use the old (internal) time which has been updated each second.
So, to sum it up: This version relies on a working receiver all the time.
By md on Jan 28, 2008
wow!
thanks for your answers! I’ll try the code as soon as I get a DCF77 receiver. Btw, you think that you can find a DCF77 receiver disassembling a DCF-clock? Some of them are ridicously cheap..
By ale on Jan 29, 2008
hi ale,
I heard of someone who disassembled an old radio-controlled clock and just used the receiver. Unfortunately, I don’t have a link ;-) You can try it. Typically, a DCF77 receiver module has an open-collector signal output as well as GND and VCC to power the module - so it’s pretty simple to connect. However, I don’t know whether the input voltage of 5V would be tolerated by a custom-build receiver for another device.
On the other hand, tinkering for 3 Euros… Give it a try and tell me!
-Mathias
By md on Jan 29, 2008
Hi
I got one “radio clock receiver” from Conrad. But,it does not work, it seems that this code is not compatible for my Arduino board(Diecimila).
Because, following statement does not work on my arduino program, if I used “#include ” in my code.
Serial.println(”bla bla”)
Actually, your code, it self does not give any compilation error, but in my program it does not show any output, I tried to debug it using Serial.println(”"); , but it gives error.
Your help in this matter will be really appericiated!
Code:
#include
#define redPin 13
int DCF77Pin=7;
int blinkPin=13;
int seconds=0;
int previousSecond =0;
int minutes=0;
int hours=0;
DCF77 myDCF=DCF77(DCF77Pin);
void setup(void) {
pinMode(blinkPin, OUTPUT);
}
void loop(void) {
int DCFsignal = myDCF.scanSignal();
if (DCFsignal) {
digitalWrite(blinkPin, HIGH);
} else {
digitalWrite(blinkPin, LOW);
}
hours=myDCF.hh;
minutes=myDCF.mm;
seconds=myDCF.ss;
if (seconds != previousSecond)
myDCF.serialDumpTime();
delay(20);
previousSecond = seconds;
}
Best regards
Ali Mahmood Khan
By Khan on Dec 17, 2008
Hi Khan,
You write “Because, following statement does not work on my arduino program, if I used “#include ” in my code. Serial.println(”bla bla”)”. This actually sounds to me as if your development environment is somehow broken. In the code snippet you posted, there is no Serial.println(foo) anyway. It would also be helpful if you could post the error message.
Please note that I don’t know whether the code will work on recent Arduino development environments or the Diecimila board (although the board is compatible, AFAIK).
-Mathias
By md on Dec 17, 2008
Have you tried to setup the serial connection? ;)
Now, in my house are:
Time: 22:32:38 Date: 31.1.2009
void setup(void) {
pinMode(blinkPin, OUTPUT);
// open the serial port at 9600 bps:
Serial.begin(9600);
}
Tnx for your dcf77 code! :)
Ciao!
By Fab on Jan 31, 2009
Hi! I have now the DCF-Empfänger BN 641138″ of Conrad. BUT it is not working very well. I live in Sweden, 250 km west of Stockholm. Maybe the BN 641138 can’t handle this distans? I am reciving pulses but only now and then. Any idea? Positioning the BN 641138 don’t seem to help.
Best regards
/Dag
By Dag Israelsson on Mar 5, 2009
Hi Dag,
my suspicion is that the receiver is not able to pick up the signal reliably. Be careful, it needs some minutes sometimes to stabilize - so just try to leave it alone for some time. You might also try to change the value of the pullup resistor - I found that there is quite some tolerance from one receiver to another.
HTH,
-Mathias
By md on Mar 5, 2009