This circuit is designed to control a micro servo motor based on the time provided by an RTC (Real-Time Clock) module. The system uses an Arduino UNO as the main microcontroller. The RTC module keeps track of the current time, and the Arduino UNO reads this time to determine when to activate the servo motor. The servo motor is used to perform a specific action, such as feeding fish at predetermined times.
Arduino UNO
RTC (Real-Time Clock)
Micro Servo 9G
#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>
RTC_DS1307 rtc;
Servo myServo;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
myServo.attach(9); // Attach servo to pin D9
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Set the RTC to the current date and time
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
// Feed the fish at 7:00 AM, 12:00 PM, and 6:00 PM
if ((now.hour() == 7 && now.minute() == 0) ||
(now.hour() == 12 && now.minute() == 0) ||
(now.hour() == 18 && now.minute() == 0)) {
feedFish();
}
delay(60000); // Check every minute
}
void feedFish() {
myServo.write(90); // Rotate servo to 90 degrees
delay(10000); // Wait for 10 seconds
myServo.write(0); // Rotate servo back to 0 degrees
}
Wire.h
for I2C communication, RTClib.h
for RTC functionality, and Servo.h
for controlling the servo motor.setup()
function. If the RTC is not running, it is set to the current date and time.loop()
function checks the current time every minute. If the time matches 7:00 AM, 12:00 PM, or 6:00 PM, the feedFish()
function is called.feedFish()
function rotates the servo to 90 degrees, waits for 10 seconds, and then rotates it back to 0 degrees.This documentation provides a comprehensive overview of the circuit, including the components used, their wiring, and the code that controls the system.