Hello, i'm new to arduino and while searching i found a code that fitted my needs, it only needed a few changes.
the pourpuse is to log the time and date that a door is opened.
i've made some changes but i haven't made the log part yet, however, my problem is other.
here's the error message
"tabaco2:7: error: 'RTC_DS1307' does not name a type
tabaco2.ino: In function 'void setup()':
tabaco2:15: error: 'RTC' was not declared in this scope
tabaco2.ino: In function 'void loop()':
tabaco2:86: error: 'DateTime' was not declared in this scope
tabaco2:86: error: expected `;' before 'now'
tabaco2:92: error: 'now' was not declared in this scope"
i've the RTClib installed.
here's my code
#include <RTClib.h>
#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(12,11,10,9,8,7);
RTC_DS1307 RTC;
const int hall_sensor = 4;
const int led = 13;
const int piez = 6;
const int override = 2;
void setup(){
RTC.begin();
Wire.begin();
lcd.begin(16, 2);
// RTC.adjust(DateTime(__DATE__, __TIME__));
pinMode(hall_sensor, INPUT);
pinMode(led, OUTPUT);
pinMode(piez, OUTPUT);
pinMode(override, INPUT);
lcd.setCursor(0,0);
lcd.print(" A INICIAR ");
lcd.setCursor(0,1);
lcd.print(" ESPERE ");
delay(5000); //Give the hall_sensor time to calibrate
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" SISTEMA ACTIVO ");
delay(2000);
}
void indicator_hall_sensor(){
digitalWrite(led, HIGH);
tone(piez, 300);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
void key(){
//delay(2500);
int override = digitalRead(2);
//delay(2500);
if (override == HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" CHAVE ACEITE ");
delay(2500);
}
else{}
}
void trip_hall_sensor(){
delay(5000);
int override = digitalRead(2);
delay(2500);
if (override == HIGH){
key();
}
else if (override == LOW){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("INICIAR REGISTO");
indicator_hall_sensor();
}
}
void loop(){
int override = digitalRead(2);
int hall_sensor = digitalRead(4);
if ( hall_sensor == HIGH){
//delay(10000);
trip_hall_sensor();
}
else
digitalWrite(led, LOW);
noTone(piez);
DateTime now = RTC.now();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" SISTEMA ACTIVO ");
lcd.setCursor(0,1);
lcd.print(now.hour(),DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
}