To
switch something (in this case the Sky News Radio audio at the top of each hour) on and off on a timer with the time from NTP:
(this is a work in progress)
- Use an Arduino Ethernet board (or an Arduino Uno with Ethernet shield) connected to an ethernet cable.
The small red board is an FTDI adapter which you'll need to upload the 'sketch' to the ethernet board (it's not needed with the Uno board) If using Windows 8.1 get the driver (the setup executable version) from ftdichip.
- Download the excellent time library for Arduino. Extract from the zip file into the C:\Program Files (x86)\Arduino\libraries folder.
- Edit the TimeNTP example sketch; change the MAC address to match the sticker on your board, change the NTP server to suit your network or country, add outputs for the relay and LEDs, add a conditional "if (minute() == 59 && second() > 55) {
digitalWrite(A1, HIGH);
}
if (minute() == 2 && second() < 5) {
digitalWrite(A1, LOW);
}
" or similar.
- Incase the ethernet connection isn't working at boot up - after the line
"Serial.println("Failed to configure Ethernet using DHCP");"
add
"digitalWrite(A1, HIGH);
delay(10000);
asm volatile (" jmp 0");"
- As getting the time via NTP can take 1500mS repeat the switching for several seconds incase the switching time and the NTP time check coincide (the NTP time check happens when the board is turned on and every 5 minutes thereafter)
- The Arduino outputs can each give/take 40mA so one will power an LED or a high imp' relay but not both so use one output for the relay and another for the indicator LED.
- Here's the circuit diagram
- Here it is built into a box (the relay used is a 5V 'signal' relay, Omron part G5V-2-HI)
Questions:
How quickly does time drift when there's no NTP server available? About 8 seconds per hour (more testing needed)
How to add a secondary NTP server?
Can it reach an NTP server by name (with DNS)?