Automatic Pet Feeder dengan Input Waktu via Handphone
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memberi pakan hewan dengan fitur bisa input waktu menggunakan handphone android. alat ini berbasis arduino dengan media transfer data melalui bluetooth. untuk lebih jelasnya berikut adalah daftar komponen dan programnya
a. Arduino Uno
b. Bluetooth HC-05
c. Mini Servo
d. Lcd + I2C
e. Motor Stepper
f. RTC DS3231
g. Program Android
h. Program Arduino IDE
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <Servo.h>
#include <DS3231.h>
#define DS3231_I2C_ADDRESS 0x68
LiquidCrystal_I2C lcd(0x27, 16, 2); //lcd masuk ke pin sda dan scl arduino
DS3231 rtc(SDA, SCL);
//pin stepper masuk ke pin 8,10,11,12
int IN1 = 8;
int IN2 = 10;
int IN3 = 11;
int IN4 = 12;
int delaytime = 10; //makin kecil delay, makin cepat motor berputar
int i;
int mark;
String dataku;
int jampagi;
int jamsore;
int jammalam;
int delayjampagi;
int delayjamsore;
int delayjammalam;
Servo myservo1;
Time t;
void setup()
{
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
myservo1.attach(9); //servo masuk ke pin 9 arduino
myservo1.write(10);
Serial.begin(9600);
lcd.begin();
lcd.clear();
//lcd.noCursor();
rtc.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to WEDNESDAY
//rtc.setTime(13, 11, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(23, 06, 2021); // Set the date to January 16st, 2021
}
void loop()
{
t = rtc.getTime();
lcd.setCursor(0, 0);
lcd.print(t.hour, DEC);
lcd.print(":");
lcd.print(t.min, DEC);
lcd.print(":");
lcd.print(t.sec, DEC);
lcd.print(" ");
delay (1000);
if (Serial.available() > 0)
{
dataku = Serial.readString();
if(dataku.startsWith("x"))
{
dataku.replace("x", "");
jampagi = dataku.toInt();
}
if(dataku.startsWith("y"))
{
dataku.replace("y", "");
jamsore = dataku.toInt();
}
if(dataku.startsWith("z"))
{
dataku.replace("z", "");
jammalam = dataku.toInt();
}
if(dataku.startsWith("a"))
{
dataku.replace("a", "");
delayjampagi = dataku.toInt();
}
if(dataku.startsWith("b"))
{
dataku.replace("b", "");
delayjamsore = dataku.toInt();
}
if(dataku.startsWith("c"))
{
dataku.replace("c", "");
delayjammalam = dataku.toInt();
}
lcd.setCursor(0, 1);
lcd.print(jampagi);
lcd.print("/");
lcd.print(jamsore);
lcd.print("/");
lcd.print(jammalam);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print(delayjampagi/1000);
lcd.print("/");
lcd.print(delayjamsore/1000);
lcd.print("/");
lcd.print(delayjammalam/1000);
lcd.print(" ");
}
if((t.hour == jampagi)&&(mark == 0)){
myservo1.write(40); //buka servo
delay(delayjampagi);
myservo1.write(10); //tutup servo
mark = 1;
//stepper putar 4*100 step
for ( i=0; i<100; i++){
maju();
}
}
if((t.hour == jamsore)&&(mark == 1)){
myservo1.write(40); //buka servo
delay(delayjamsore);
myservo1.write(10); //tutup servo
mark = 2;
//stepper putar 4*100 step
for ( i=0; i<100; i++){
maju();
}
}
if((t.hour == jammalam)&&(mark == 2)){
myservo1.write(40); //buka servo
delay(delayjammalam);
myservo1.write(10); //tutup servo
mark = 0;
//stepper putar 4*100 step
for ( i=0; i<100; i++){
maju();
}
}
}
void maju(){
//step 4
step1();
delay(delaytime);
//step 3
step2();
delay(delaytime);
//step 2
step3();
delay(delaytime);
//step 1
step4();
delay(delaytime);
}
void mundur(){
//step 4
step4();
delay(delaytime);
//step 3
step3();
delay(delaytime);
//step 2
step2();
delay(delaytime);
//step 1
step1();
delay(delaytime);
}
void step1(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,HIGH);
}
void step2(){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
void step3(){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
void step4(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
i. VIDEO HASILNYA