Contents
Today we will try to create a precision timer using RTC (Real Time Clock) module and Arduino Nano. As an additional power module, we will use the LM2596 module which can source a current at 3A max. Also, we provide a relay (5 pins) as interfacing to an external system which can handle up to 10A load. Wrapping all components up, here is the design of the precision timer relay.
Arduino Precision Timer Relay – Tools and Materials
- Arduino Nano
- Relay 5V (5 pins)
- Power module (LM2596)
- RTC module DS3231 mini (usually called ‘for Raspberry Pi’ in the market)
- Transistor BD139 + resistor 1K + diode 1N4001 for relay driver
- Terminal block (2p and 3p)
- L-male pin header (5p for DS3231 module)
After all components are completed, let’s build the circuit as the wiring design below:
Once the circuit has been built, we can upload the script using Arduino IDE to our Arduino Nano. Here is the sketch
#include "RTClib.h" #define relay 7 RTC_DS3231 rtc; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; void setup () { Serial.begin(9600); pinMode (7,OUTPUT); digitalWrite(7,LOW); #ifndef ESP8266 while (!Serial); // wait for serial port to connect. Needed for native USB #endif if (! rtc.begin()) { Serial.println("Couldn't find RTC"); Serial.flush(); while (1) delay(10); } if (rtc.lostPower()) { Serial.println("RTC lost power, let's set the time!"); rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } } void loop () { DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(" ("); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.print(") "); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); Serial.print("Temperature: "); Serial.print(rtc.getTemperature()); Serial.println(" C"); Serial.println(); if ((now.minute()==24)&&(now.second()==0)) digitalWrite(relay,1); if ((now.minute()==34)&&(now.second()==0)) digitalWrite(relay,0); if ((now.minute()==54)&&(now.second()==0)) digitalWrite(relay,1); if ((now.minute()==4)&&(now.second()==0)) digitalWrite(relay,0); delay(1000); }
To compile the script correctly, you must install the library ‘RTClib.h’. For instant installation, you can use ‘Library Manager’ in Arduino IDE through the menu ‘Tools-Manage Libraries’ then type ‘rtclib’ in the search box then click ‘Install’ (or ‘Update’) button (see picture below)
After making it, upload the script to your board (plug the Arduino Nano in then select COM Port correctly). If everything is correct then the result will be :
In the above script, we made to turn on/off the relay every specific time. We turn the relay on every minute 24th and 54th then turn the relay off in minutes 34th and 4th). So as the final result, the relay will be turned on for 10 minutes every 30 minutes. For other purposes, you can simply modify the script as you need.
The PCBA
You need to assemble all components on a PCB board. To print a PCB you need to design a PCB layout using PCB designer software like Eagle, KiCad, Proteus, Fritzing, etc. Here is the PCB layout design using Frtizing
And here is the result
if you need a PCB printing service you can order from our startup, indomaker.com at a reasonable price
a Technopreneur – writer – Enthusiastic about learning AI, IoT, Robotics, Raspberry Pi, Arduino, ESP8266, Delphi, Python, Javascript, PHP, etc. Founder of startup Indomaker.com