Hello,
I have a sketch that has been working fine that will no longer compile. The error message I get says "RTC_DS1307 does not name a type" so I looked into the library.
I'm can't think of what would have changed, except that the library RTClib now appears in my custom library tab for some reason. I tried to delete RTClib from the custom library tab and got a yellow popup box that says "error while deleting library". That seems weird to me. I see there is another post on this topic that was resolved a while back so maybe a similar issue?
Any thoughts?
//Catomatic: An automated cat food and water station
//A hair-brained project by Wayne Gatlin
//last edit 25Jan2018 this version solves the delay block that was making the water dispense too long
/*
Description of the project:
The purpose of this project is to control the timing of two outputs that are used to
dispense food and water to Murf. One output is a low-torque electric motor (12v)
that turns a worm drive to dispense food and the other is a soleniod (12v) that
dispenses water. An Arduino Uno with a RTC controls the timing of food and water cycles.
Each output is activated by a seperate TIP120 transistor that receives a 5v signal from the
Arduino that opens the defined output to the 12v current.
Description of the circuit:
*A DC 12v 1.5A power supply, with the ground wire connected to 12v breaboard ground and the power
connected to the 12v breadboard power
*A DC motor connected to 12v power and a TIP120 tranistor
*A DC solenoid valve connected to 12v power and a TIP120 tranistor
*Feedmotor TIP120 tranistor, with the Base connected to digital pin 3, the Emitter to 12v ground,
and the Collector to one lead from a 12v DC motor
*watersolenoid TIP120 tranistor, with the Base connected to digital pin 4, the Emitter to ground,
and the Collector to one lead from a 12v DC solenoid valve
*manual feed Pushbotton that completes 12v circuit from motor to ground, bypassing transistor control
*manual water Pushbotton that completes 12v circuit from solenoid to ground, bypassing transistor control
*RTC to control timing of events
The objective of this code is to:
1. Use the arduino's outputs to send 5v signals to the transistors for the motor and solenoid
so that they turn on at the defined times and are open for the correct amount of time
2. Define a set amount of time that each output is open (longer=more food or water dispensed)
3. Create a timed daily cycle of three food and water events (breakfast, lunch, dinner)
4. Ideally allow the Arduino to "sleep" until it is interruped for the next event
*/
//Step 1: Call libraries
#include <Wire.h> //This library allows the Uno to communicate with I2C / TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin.
#include "RTClib.h" //I beleive this library allows the RTC to communicate with the Arduino
#include <TimeLib.h> //This header file contains definitions of functions to get and manipulate date and time information.
#include <TimeAlarms.h> //I believe this libarry allows me to schedule time-based tasks
RTC_DS1307 RTC; //this defines a variable named RTC of type RTC_DS1307; it's defined in RTClib.h
time_t syncProvider() //this does the same thing as RTC_DS1307::get()
{
return RTC.now().unixtime();
}
//Step 2: Define the variables
//int is the 'data type' for the variables --int means integer (whole number)
int feedmotor = 3; //The motor for food will be controlled by digial output pin 3
int watersolenoid = 4; //The solenoid for water will be controlled by digial output pin 4
/**************************
SETUP FUNCTION
***************************/
// Step 3: Run the setup
//The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc.
//The setup function will only run once, after each powerup or reset of the Arduino board.
void setup()
{
//establish communication with computer
Serial.begin(9600); //My understanding is that this sets the communiaction rate with the computer(?) and is necessary for all sketches
//Call the libraries that were included in Step 1
Wire.begin(); //Starts the wire library
RTC.begin(); //Starts the RTC library
setSyncProvider(syncProvider); //reference our syncProvider function instead of RTC_DS1307::get()
//Tell the arduino what I've called the outputs
pinMode(feedmotor, OUTPUT); //Defines that the feedmotor (pin 3 from step 2) is an output device
pinMode(watersolenoid, OUTPUT); //Defines that the watersolenoid (pin 4 from step 2) is an output device
pinMode(LED_BUILTIN, OUTPUT); //defines onboard LED
//Test to see if the RTC is NOT running properly
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
}
//Test to make sure the RTC is running properly
if (RTC.isrunning())
{
Serial.println("RTC is workin fine!");
}
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
//Define the times that food and water will be delivered
Alarm.alarmRepeat(11,00,00, Breakfast); // An alarm called Breakfast happens at 6:30am every day
Alarm.alarmRepeat(17,30,00, Lunch); // An alarm called Lunch happens at 12:30pm every day
Alarm.alarmRepeat(22,00,00, Dinner); // An alarm called Dinner happens at 6:00pm every day
//for some reason the RTC gets set 5 hours ahead of the current time when the sketch uploads from my macbook
}
/**************************
LOOPS
***************************/
//Step 4: Describe the loop
void loop() { //curly bracket that defines start of the loop
//this sets the RTC clock to current time and date in the serial monitor
//Does this require an LCD? I would like to add one in the future.
DateTime now = RTC.now(); //this calls current time and date from RTC
Serial.print(now.hour(), DEC); //this set of functions prints the time every second in the serial monitor
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
//this is required, or the alarms won't fire.
Alarm.delay(1000); // wait one second between clock display
}
//Create a loop that defines a feeding
void FoodWaterON() { // A title for this particular function
digitalWrite(feedmotor, HIGH); //Turns the feedmotor on
Serial.println("Feeding the Beast"); //text on the future LCD
//future project: LED indicator light
//future project: LCD scrolling message
//future project: sound bite to announce feeding
delay(10000); //This is the amount of time the motor will turn dispensing food
Serial.println("Feeding Complete"); //Text on the future LCD
digitalWrite(feedmotor, LOW); //Turns the feedmotor on
delay(12000); //delay between food and water
digitalWrite(watersolenoid, HIGH); //Turns the watersolenoid on
Serial.println("Hydrating"); //text on the future LCD
//future project: LED indicator light
//future project: LCD scrolling message
//future project: sound bite to announce watering
delay(3000); //This is the amount of time the motor will turn dispensing food
Serial.println("Hydration Complete"); //Text on the future LCD
digitalWrite(watersolenoid, LOW); //Turns the watersolenoid on
}
//Create a loop that defines a watering
/*void WaterON() { //I think this is just a title for this particular function
digitalWrite(watersolenoid, HIGH); //Turns the watersolenoid on
Serial.println("Hydrating"); //text on the future LCD
//future project: LED indicator light
//future project: LCD scrolling message
//future project: sound bite to announce watering
delay(3000); //This is the amount of time the motor will turn dispensing food
Serial.println("Hydration Complete"); //Text on the future LCD
digitalWrite(watersolenoid, LOW); //Turns the watersolenoid on
}*/
//Define what will happen at each of the three scheduled meal times
void Breakfast() {
Serial.println("test run");
FoodWaterON();
}
void Lunch() {
FoodWaterON();
}
void Dinner() {
FoodWaterON();
}