Time relay

I am new to Arduino. I want to create a simple time relay. The electricity has to be switched on during the night hours(8pm - 8am) and switched off during the day (8am - 8pm). I tried to use Time library (time.h), but it doesn't return the current time.

For the actual time-of-day, you need (afaik) to use either a Real Time Clock (RTC) chip or head out to the interwebz with Network Time Protocol (NTP).

automaton2:
I am new to Arduino. I want to create a simple time relay. The electricity has to be switched on during the night hours(8pm - 8am) and switched off during the day (8am - 8pm). I tried to use Time library (time.h), but it doesn't return the current time.

You can probably buy such a relay at your local hardware store. Why use Arduino for this?

It might be that your goal is to learn how to use an Arduino, and you are building a time relay as a small project before moving on to bigger projects.

A time relay has to do three things, in this order:

  1. Figure out what time it is.
  2. Figure out, based on the time, whether the power should be on or off.
  3. If the power should be on, turn it on; otherwise, turn it off.

From what I understand, the Time library can keep track of time just fine, as long as you first set the time. It's kind of the clock on a microwave oven: first you have to set the time, and then it will keep track of time for you... unless there is a power outage, in which case it will lose the time and you will have to set it again.

Personally, I never use the Time library, but plenty of other people seem happy with it.

ardy_guy:
For the actual time-of-day, you need (afaik) to use either a Real Time Clock (RTC) chip or head out to the interwebz with Network Time Protocol (NTP).

RTC chips often come with battery backups. That way, you don't need to reset the time in case of a power outage. Also, RTC chips generally keep much more accurate time than an Arduino without such a chip.

odometer:
From what I understand, the Time library can keep track of time just fine, as long as you first set the time.

That's interesting (possible inaccuracies aside) and I stand corrected.

A daylight sensor (LDR) seems more suitable to turn the lights on/off than a clock.
Especially if you don’t live near the equator.
Leo…