1

I want to make a very small 7-hour timer circuit that can turn on a relay after 7 hours. I am trying to make the first prototype with an Arduino Nano but I can't understand how to program it for such purpose. So please help me out.

Once I make a prototype in Arduino then I was thinking to make a small one using an ATtiny13. Can I use an ATtiny13 for such purpose?

4
  • Never seen an Arduino core for the tiny13. You may have to program it at the avr-libc level. Commented Jul 1, 2017 at 14:52
  • 1
    You could try a timer with millis. 7 hours is (7L * 60L * 60L * 1000L) milliseconds. The ATtiny13 has an internal oscillator for the CPU clock, the 7 hours will not be accurate. I have ATtiny13 chips and I have seen the Arduino core for it, but I never tried it: github.com/MCUdude/MicroCore
    – Jot
    Commented Jul 1, 2017 at 15:02
  • I have investigated the MicroCore code and compared it with my project for ATtiny13 (I did not actually compile a similar project). The overhead is not too bad, and it makes fast prototyping possible because it is pretty Arduino compatible. The millis function is very inaccurate though, because that uses the watchdog timer. For normal basic use of the ATtiny13 I would recommend the MicroCore. I think the MicroCore is well made, I like it a lot (@EdgarBonet).
    – Jot
    Commented Jul 2, 2017 at 1:46
  • Could you please tell in your question: 1) what event will start the timer? 2) will the tiny13 have something to do during these 7 days other than count time? 3) what accuracy do you need (7 days ± how much)? 4) what clock source do you plan to use on the tiny13? Commented Jul 2, 2017 at 7:53

2 Answers 2

2

The question is whether its a one shot triggering ON the relay after 7 hours and thereafter you always leave it ON or its some periodic process where every 7 hours, you want the relay to trigger ON and OFF alternatively. Presuming the latter, this can be done in 2 ways:

1) Configure a hardware timer interrupt to call a small function every second and increment a variable within that function. So after 1 hour your variables value must be 3600, therefore after 7 hours it will be 25,200. Once the variable is equal to 25200, you can ON the relay and reset the variable to 0. Factors such as the number of hardware timers and its resolution differs from one MCU to another.

2) Use a Real Time Clock like the DS1307 for this purpose and save you hardware timers for performing some other time critical operations.

Hope this helps!.

3
  • You wrote: “Configure a hardware timer(32 or 16 bit)”: there is no such thing in the ATtiny13. Commented Jul 3, 2017 at 9:48
  • @EdgarBonet, I am not aware if ATiny13 has any inbuilt hardware timers as I haven't used it. However, until today whichever MCU's I have used had at least one hardware timer. For example, the esp8266ex has one 32 bit hardware timer, similarly the TICC3200 has four 32 bit hardware timers. Commented Jul 3, 2017 at 9:53
  • Just did a Google search and found a few examples as well where they are flashing an LED using the timer interrupts. And between, just got to know its an 8 bit controller, hence edited my answer. Commented Jul 3, 2017 at 10:14
1

cant understand how to program it for such purpose so please help me out

it is fairly easy to approach such questions:

1) you can program any?

2) can you program this mcu to blink an led?

3) can you program this mcu to do short time counting?

4) can you program this mcu to do long time counting?

what you help helps you the most depends on your answers to those questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.