Hello ,
I have installed RTC.h , rtc library by V.manjunath. I have this code given below:-
#include <Arduino.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#define SIX 360
#define EIGHTEEN 1077
const int relay1= 9;
const int relay2= 10;
const int led=13;//pin 19 of physical atmega8 chip
//rtc library by v.manjunath
#include "RTC.h"//rtc library by v.manjunath
void blink(int var)
{ int count=var;
while (count>0)
{digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
count=count-1;}
}
// save cumulative days for each month in flash memory
//const int cumu_days[]PROGMEM = {0,31,59,90,120,151,181,212,243,273,303,334};
const byte cumu_days[]PROGMEM = {0,0,15,30,45,60,75,90,106,121,137,151,167};
// save Sunrise and Sunset timings in flash memory
//minutes after 06:00 in morning
const byte sunrise[366]PROGMEM =
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
{ 74,74,75,75,75,75,76,76,76,76,76,77,77,77,77,77,77,77,77,77,77,77,77,77,76,76,76,76,76,75,75,
75,75,74,74,74,73,73,72,72,72,71,71,70,70,69,68,68,67,67,66,66,65,64,64,63,62,62,61,
60,59,59,58,57,56,56,55,54,53,52,52,51,50,49,48,48,47,46,45,44,43,43,42,41,40,39,38,37,37,36,
35,34,33,32,32,31,30,29,28,28,27,26,25,25,24,23,22,22,21,20,19,19,18,17,17,16,15,15,14,14,
13,12,12,11,11,10,10,9,9,8,8,8,7,7,6,6,6,5,5,5,5,4,4,4,4,4,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,5,5,5,5,6,6,6,6,7,
7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,13,13,13,14,14,14,15,15,15,16,16,16,17,17,17,
18,18,18,19,19,19,20,20,20,21,21,21,21,22,22,22,23,23,23,23,24,24,24,24,24,25,25,25,25,25,26,
26,26,26,26,27,27,27,27,27,28,28,28,28,28,28,29,29,29,29,29,30,30,30,30,30,30,31,31,31,31,
31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,36,36,36,36,37,37,37,38,38,39,39,39,40,40,41,
41,42,42,42,43,43,44,44,45,45,46,46,47,47,48,49,49,50,50,51,51,52,53,53,54,54,55,56,56,57,
58,58,59,59,60,61,61,62,62,63,64,64,65,65,66,67,67,68,68,69,69,70,70,71,71,72,72,72,73,73,74,74};
//minutes after 18:00 in the evening (actually after 17:57 = 1077 minutes)
const byte sunset[366]PROGMEM =
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
{14,14,15,15,16,17,17,18,19,19,20,20,21,21,22,23,24,24,25,26,26,27,27,28,29,29,30,30,31,32,32,
33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,41,42,42,43,43,43,44,44,44,45,
45,45,46,46,46,47,47,47,48,48,48,48,49,49,49,49,50,50,50,50,51,51,51,51,52,52,52,52,53,53,53,
53,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,59,59,59,59,60,60,60,61,61,61,
62,62,62,63,63,63,64,64,65,65,65,66,66,66,67,67,68,68,68,69,69,69,70,70,71,71,71,72,72,73,73,
73,74,74,74,75,75,75,76,76,76,77,77,77,78,78,78,79,79,79,79,79,80,80,80,80,80,81,81,81,81,
81,81,81,81,81,81,81,81,81,81,81,81,81,80,80,80,80,80,80,79,79,79,78,78,78,77,77,77,76,76,75,
75,74,74,73,73,72,72,71,71,70,70,69,68,68,67,66,66,65,64,64,63,62,61,61,60,59,58,57,57,56,55,
54,53,52,52,51,50,49,48,47,46,46,45,44,43,42,41,40,39,38,38,37,36,35,34,33,32,31,30,30,29,
28,27,26,25,25,24,23,22,21,20,20,19,18,17,17,16,15,15,14,13,12,12,11,11,10,9,9,8,8,7,7,
6,6,5,5,4,4,4,3,3,3,2,2,2,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,10,10,11,12,12,13,14};
int hr,minu,sec,date,month,yr;
void setup()
{
// WDTCR=0x0f;//enable watchdog timer to activate resetting after 2.1 Sec
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
pinMode(led,OUTPUT);
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
RTC.begin();
// RTC.setMinutes(24);
// check the current hr/mth/min parameter and blinks the led (para) times.
//such blinking can be used to read and confirm the calendar data
// int var=RTC.getMinutes();
// blink(var);
//If you want to initialize the RTC uncomment the following statements
//and change the time and date as per the current values.
RTC.setHourMode(CLOCK_H24);
RTC.setOutPin(SQW001Hz); //Square wave output with 1 Hz freq
RTC.setTime(15,17,00);
RTC.setSeconds(); //set the seconds
RTC.setMinutes(5); //set the minutes
RTC.setHours(9); //set the hours
RTC.setDay(21); //set the date
RTC.setWeek(); //set the weekday
RTC.setMonth(6); //set the month
RTC.setYear(2021); //set the year
delay(1000);
}
void loop()
{
// byte week,days,total_days ;
int sunset_min,sunrise_min;
int total_days,sunset_time,sunrise_time;
int hrs2min,current_time;
byte sunset_flag,sunrise_flag;
while(1)
{
//now get the date from RTC
date=RTC.getDay();
month=RTC.getMonth();
// yr=RTC.getYear();
//read the cumulative days for the running month
total_days = 2*(pgm_read_byte(&(cumu_days[month])));
//total_days += date;
total_days=total_days+date;
// int var=total_days;
// blink(var);
//find Sunset and Sunrise timing
sunrise_min=pgm_read_byte(&(sunrise[total_days]));
sunset_min=pgm_read_byte(&(sunset[total_days]));
// int var=sunset_min/4;
// blink(var);
//find the Sunset and sunrise timings for current day
sunrise_time = SIX + sunrise_min;
sunset_time = EIGHTEEN + sunset_min;
// get the current time from RTC
hr=RTC.getHours();
// blink(hr);
//now get minutes
minu=RTC.getMinutes();
// sec=RTC.getSeconds();
// Convert the hours to minutes
hrs2min = 60*hr;
current_time = hrs2min+minu;
//compare current time with Sunrise and sunset timings
if(current_time < sunrise_time)
sunrise_flag = HIGH;
else
sunrise_flag = LOW;
if(current_time < sunset_time)
sunset_flag = HIGH;
else
sunset_flag = LOW;
if((sunset_flag ^ sunrise_flag)== HIGH)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2,LOW);
}
else
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
}
delay(1000);
}
}
I am getting Compile time error like:-
Arduino: 1.8.12 (Windows 10), Board: "Arduino NG or older, ATmega8"
C:\Users\sakshi\OneDrive\Documents\Arduino\suntime\suntime.ino: In function 'void setup()':
suntime:76:3: error: 'RTC' was not declared in this scope
RTC.begin();
^~~
C:\Users\sakshi\OneDrive\Documents\Arduino\suntime\suntime.ino:76:3: note: suggested alternative: 'RXC'
RTC.begin();
^~~
RXC
C:\Users\sakshi\OneDrive\Documents\Arduino\suntime\suntime.ino: In function 'void loop()':
suntime:112:8: error: 'RTC' was not declared in this scope
date=RTC.getDay();
^~~
C:\Users\sakshi\OneDrive\Documents\Arduino\suntime\suntime.ino:112:8: note: suggested alternative: 'RXC'
date=RTC.getDay();
^~~
RXC
exit status 1
'RTC' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Please help me with the solution.