What it shows
Computers set their clocks by asking time servers over the internet using the Network Time Protocol. A NodeMCU can do the same and display accurate Indian Standard Time without a clock chip.
The science
The ESP8266 connects to Wi-Fi and calls configTime(19800, 0, "pool.ntp.org"). The number 19800 is the offset of India from UTC, 5 hours 30 minutes in seconds, and India has no daylight saving. The library then asks a time server for the current UTC time and keeps it up to date using the board clock. getLocalTime or the time functions give the hour, minute and second to print.
Materials
Cost: under Rs 1,500. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A NodeMCU ESP8266 board with a micro USB cable
- A 0.96 inch SSD1306 I2C OLED display
- A breadboard and jumper wires
- A phone hotspot or home Wi-Fi with a known password
- A power bank
- A small box as case
Safety
For this project: USB power only. Do not share your Wi-Fi password in published code; keep it in the sketch only on your own computer.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Connect the OLED: VCC to 3V3, GND to GND, SDA to D2 and SCL to D1 on the NodeMCU.
Install the ESP8266 board package, the Adafruit SSD1306 and Adafruit GFX libraries.
Write a sketch that connects to Wi-Fi with WiFi.begin(ssid, password) and waits for the connection.
Call configTime(19800, 0, "pool.ntp.org", "time.nist.gov") after connecting.
In loop, read time(nullptr) and convert with localtime to get hour, minute, second, day and month.
Draw the time in large digits on the OLED and the date in smaller text below it.
Update the display every second and show a Wi-Fi symbol when connected.
Compare your clock with a phone over a few days and note any difference.
What you should see
The OLED shows the correct Indian time and date within a second, set automatically after each power on.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1What is NTP?
The Network Time Protocol, used by computers to get accurate time from servers.
2Why is 19800 used?
India time is UTC plus 5 hours 30 minutes, which is 19800 seconds.
3What happens without Wi-Fi?
The clock cannot set itself and will start from the wrong time.
4How could it keep time without the internet?
Add a DS3231 real time clock chip with a coin cell.
Take it further
Add a buzzer alarm and a web page that lets you set the alarm time from your phone.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
