/* * Mengontrol Servo dengan Sensor Ultrasonic * Email :
[email protected] * www.boarduino.blogspot.com */
// Arduino Uno/2009: // ---------------------// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin //
SCL pin -> Arduino Analog 5 or the dedicated SCL pin
// // Arduino Leonardo: // ---------------------// DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin //
SCL pin -> Arduino Digital 3 or the dedicated SCL pin
// // Arduino Mega: // ---------------------// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin //
SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
// // Arduino Due: // ---------------------// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin //
SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
// // The internal pull-up resistors will be activated when using the // hardware I2C interfaces. //
// You can connect the DS3231 to any available pin but if you use any // other than what is described above the library will fall back to // a software-based, TWI-like protocol which will require exclusive access // to the pins used, and you will also have to use appropriate, external // pull-up resistors on the data and clock signals. // http://www.instructables.com/id/Real-time-clock-using-DS3231-EASY/?ALLSTEPS
#include
#include #include <Servo.h> #include <Wire.h> #include #include "RTClib.h"
int buzz = 8; RTC_DS1307 rtc; Servo servo; LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // initialise the LCD
void setup() { pinMode(buzz, OUTPUT); Serial.begin (9600); Wire.begin(); servo.attach(13); servo.write(0); rtc.begin(); { Serial.println("RTC is NOT running!"); }
lcd.begin (16, 2); lcd.setBacklightPin(3,POSITIVE); lcd.setBacklight(HIGH); lcd.clear(); lcd.setCursor(0,0); lcd.print("SMART FEEDER"); delay(2000); }
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(now.hour(), DEC); Serial.print('/'); Serial.print(now.minute(), DEC); Serial.print('/'); Serial.print(now.second(), DEC); Serial.println(); Serial.println(); delay(1000);
lcd.clear(); lcd.setCursor(0,0);
lcd.print(now.year(), DEC); lcd.print('/'); lcd.print(now.month(), DEC); lcd.print('/'); lcd.print(now.day(), DEC); lcd.setCursor(0,1); lcd.print(now.hour(), DEC); lcd.print('/'); lcd.print(now.minute(), DEC); lcd.print('/'); lcd.print(now.second(), DEC);
// Servo ON
if (now.hour() == 2 & now.minute() == 59 & now.second() == 33) { digitalWrite(buzz, HIGH); servo.write(45); delay(3000); servo.write(0); lcd.clear(); lcd.setCursor(0,0); lcd.print("WAKTU MAKAN"); delay(2000); digitalWrite(buzz, LOW); }
// Servo OFF else if (now.hour() == 3 & now.minute() == 00 & now.second() == 10)
{ digitalWrite(buzz, HIGH); servo.write(45); delay(3000); servo.write(0); lcd.clear(); lcd.setCursor(0,0); lcd.print("WAKTU MAKAN"); delay(2000); digitalWrite(buzz, LOW); }
}