PLANNING BOARD


dag wijzer bord

dag wijzer zijkantdag wijzer voorkant

How I got the idea In my home we have a planning board on the wall. We had to move a piece of plastic to know what day it was. But we forgot to move it every day. And my mom did not like it when the board is not used. Stuff I found in my closet I made this. I used Arduino shields, UTP cable and lamps that were from beer.

What it does It lights up the correct day of the week using seven LEDs hooked up to an Arduino UNO. It took me two days to make. On day one it was soldering and coding it. The code can be found at the bottom of the page. The second day I installed everything.

How it works It works by asking the time from a time server (time.nist.gov) when first turning the Arduino on. The time server returns the amount of seconds from the 1st of January 1970. Then I use a library to convert it to the day of the week, with leap years. The downside is that the Arduino forgets the time when it loses power.

Hardware Arduino Uno (controls the LEDs) + Ethernet shield (to ask the time to the server) + Protoboard (easy to use for the connections).

Software Arduino ide from Arduino.cc

Source code

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
#include <TimeLib.h>

long timeZone = +2 * 60 * 60;
int const NUM_PINS = 8;
int ledPins[] = {2, 2, 3, 5, 6, 7, 8, 9}; //13 not used start counting with index 1

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0xFE, 0xB5
};

unsigned int localPort = 8888;
char timeServer[] = "time.nist.gov";
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[ NTP_PACKET_SIZE];

EthernetUDP Udp;

void setup() {

  for(int i = 1; i < NUM_PINS; i++) {
    pinMode(ledPins[i], OUTPUT);
  }

  for(int i = 1; i < NUM_PINS; i++) {
    digitalWrite(ledPins[i], HIGH);
  }

  delay(500);
  
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    for (;;)
      ;
  }
  Udp.begin(localPort);
}

void loop() {
  sendNTPpacket(timeServer);

  delay(1000);
  if (Udp.parsePacket()) {
    Udp.read(packetBuffer, NTP_PACKET_SIZE);

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);

    unsigned long secsSince1900 = highWord << 16 | lowWord;
    Serial.print("Seconds since Jan 1 1900 = ");
    Serial.println(secsSince1900);

    Serial.print("Unix time = ");
    const unsigned long seventyYears = 2208988800UL;
    unsigned long epoch = secsSince1900 - seventyYears;
    Serial.println(epoch);

    setTime(epoch);
    adjustTime(timeZone);
    UpdateLeds(weekday());
    
    Serial.print("the day of the week = ");
    Serial.println(weekday());
  }
  delay(10000);
  Ethernet.maintain();
}

void sendNTPpacket(char* address) {
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}

void UpdateLeds(int dayOfWeek) {
  for(int i = 1; i < NUM_PINS; i++) {
    if(i == dayOfWeek) {
      digitalWrite(ledPins[i], HIGH);
    }
    else
    {
      digitalWrite(ledPins[i], LOW);
    }
  }
}



Type:

en_GBEnglish (UK)