Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat yang bisa digunakan untuk memberikan makanan kepada hewan peliharaan seperti ikan atau kucing dll. secara otomatis dengan set waktu menggunakan handphone android dan sms, kemudian terdapat motor servo yang digunakan untuk buka-tutup pintu atau katub. alat ini juga dilengkapi dengan sensor jarak yang bisa mendeteksi kondisi pakan ketika masih full atau sudah mau habis. untuk lebih jelasnya berikut adalah skema dan programnya.
a.Arduino Uno
b. Motor Servo
c.Bluetooth HC-05
d. Modul SMS SIM900A
e. LCD 16x2 I2C
f. RTC DS1302
g. Program Android
h. Program Arduino Pet Feeder
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <DS1302.h>
#include <Servo.h>
#define trigPin 3
#define echoPin 4
LiquidCrystal_I2C lcd(0x3F, 16, 2);
DS1302 rtc(7, 6, 5);
long duration, distance;
int mark;
String dataku;
int jampagi;
int jamsore;
Servo myservo1;
Servo myservo2;
Time t;
int sen1;
int sen2;
int sen3;
void setup()
{
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
myservo1.attach(9);
myservo2.attach(10);
myservo1.write(100);
myservo2.write(100);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
//rtc.setTime(18, 02, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(9, 26, 2018); // Set the date to August 6th, 2010
}
void loop()
{
sen1 = digitalRead(A0);
sen2 = digitalRead(A1);
sen3 = digitalRead(A2);
t = rtc.getTime();
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
lcd.setCursor(0, 0);
lcd.print(rtc.getTimeStr());
lcd.print(" | ");
lcd.print(distance);
lcd.print(" ");
delay (1000);
if((sen1 == 0)&&(sen2 == 0)&&(sen3 == 0)){
lcd.setCursor(13, 1);
lcd.print("OFF");
}
if((sen1 == 1)&&(sen2 == 0)&&(sen3 == 0)){
lcd.setCursor(0, 1);
lcd.print("7 | 17 MODE SMS ");
jampagi = 7;
jamsore = 17;
}
if((sen1 == 0)&&(sen2 == 1)&&(sen3 == 0)){
lcd.setCursor(0, 1);
lcd.print("8 | 16 MODE SMS ");
jampagi = 8;
jamsore = 16;
}
if((sen1 == 0)&&(sen2 == 0)&&(sen3 == 1)){
lcd.setCursor(0, 1);
lcd.print("9 | 15 MODE SMS ");
jampagi = 9;
jamsore = 15;
}
if((t.min == jampagi)&&(mark == 0)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 1;
}
if((t.min == jamsore)&&(mark == 1)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 0;
}
if ((Serial.available() > 0)&&(sen1 == 0)&&(sen2 == 0)&&(sen3 == 0))
{
dataku = Serial.readString();
if(dataku.startsWith("x"))
{
dataku.replace("x", "");
jampagi = dataku.toInt();
}
else if(dataku.startsWith("y"))
{
dataku.replace("y", "");
jamsore = dataku.toInt();
}
lcd.setCursor(0, 1);
lcd.print(jampagi);
lcd.print(" | ");
lcd.print(jamsore);
lcd.print(" ");
}
if((t.min == jampagi)&&(mark == 0)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 1;
}
if((t.min == jamsore)&&(mark == 1)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 0;
}
}
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <DS1302.h>
#include <Servo.h>
#define trigPin 3
#define echoPin 4
LiquidCrystal_I2C lcd(0x3F, 16, 2);
DS1302 rtc(7, 6, 5);
long duration, distance;
int mark;
String dataku;
int jampagi;
int jamsore;
Servo myservo1;
Servo myservo2;
Time t;
int sen1;
int sen2;
int sen3;
void setup()
{
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
myservo1.attach(9);
myservo2.attach(10);
myservo1.write(100);
myservo2.write(100);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
//rtc.setTime(18, 02, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(9, 26, 2018); // Set the date to August 6th, 2010
}
void loop()
{
sen1 = digitalRead(A0);
sen2 = digitalRead(A1);
sen3 = digitalRead(A2);
t = rtc.getTime();
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
lcd.setCursor(0, 0);
lcd.print(rtc.getTimeStr());
lcd.print(" | ");
lcd.print(distance);
lcd.print(" ");
delay (1000);
if((sen1 == 0)&&(sen2 == 0)&&(sen3 == 0)){
lcd.setCursor(13, 1);
lcd.print("OFF");
}
if((sen1 == 1)&&(sen2 == 0)&&(sen3 == 0)){
lcd.setCursor(0, 1);
lcd.print("7 | 17 MODE SMS ");
jampagi = 7;
jamsore = 17;
}
if((sen1 == 0)&&(sen2 == 1)&&(sen3 == 0)){
lcd.setCursor(0, 1);
lcd.print("8 | 16 MODE SMS ");
jampagi = 8;
jamsore = 16;
}
if((sen1 == 0)&&(sen2 == 0)&&(sen3 == 1)){
lcd.setCursor(0, 1);
lcd.print("9 | 15 MODE SMS ");
jampagi = 9;
jamsore = 15;
}
if((t.min == jampagi)&&(mark == 0)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 1;
}
if((t.min == jamsore)&&(mark == 1)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 0;
}
if ((Serial.available() > 0)&&(sen1 == 0)&&(sen2 == 0)&&(sen3 == 0))
{
dataku = Serial.readString();
if(dataku.startsWith("x"))
{
dataku.replace("x", "");
jampagi = dataku.toInt();
}
else if(dataku.startsWith("y"))
{
dataku.replace("y", "");
jamsore = dataku.toInt();
}
lcd.setCursor(0, 1);
lcd.print(jampagi);
lcd.print(" | ");
lcd.print(jamsore);
lcd.print(" ");
}
if((t.min == jampagi)&&(mark == 0)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 1;
}
if((t.min == jamsore)&&(mark == 1)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 0;
}
}
i. Program Arduino SMS
#include "SIM900.h"
#include "sms.h"
#include "SoftwareSerial.h"
#include "sms.h"
SMSGSM sms;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup(){
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
if(gsm.begin(9600)){
started=true;
}
if(started){
delsms();
}
delay(1000);
sms.SendSMS("085726496643","SIAP EKSEKUSI");
}
void loop(){
if(gsm.begin(9600)){
started=true;
}
int pos=0;
if(started){
pos=sms.IsSMSPresent(SMS_ALL);
if(pos){
sms.GetSMS(pos,n,smsbuffer,100);
if(!strcmp(smsbuffer,"off")){
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode off");
}
if(!strcmp(smsbuffer,"mode1")){
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode satu");
}
if(!strcmp(smsbuffer,"mode2")){
digitalWrite(A0,LOW);
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode dua");
}
if(!strcmp(smsbuffer,"mode3")){
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH);
sms.SendSMS(n,"mode tiga");
}
delsms();
}
}
delay(100);
}
void delsms()
{
for (int i=0; i<10; i++)
{
int pos=sms.IsSMSPresent(SMS_ALL);
if (pos!=0)
{
if (sms.DeleteSMS(pos)==1){}else{}
}
}
}
#include "sms.h"
#include "SoftwareSerial.h"
#include "sms.h"
SMSGSM sms;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup(){
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
if(gsm.begin(9600)){
started=true;
}
if(started){
delsms();
}
delay(1000);
sms.SendSMS("085726496643","SIAP EKSEKUSI");
}
void loop(){
if(gsm.begin(9600)){
started=true;
}
int pos=0;
if(started){
pos=sms.IsSMSPresent(SMS_ALL);
if(pos){
sms.GetSMS(pos,n,smsbuffer,100);
if(!strcmp(smsbuffer,"off")){
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode off");
}
if(!strcmp(smsbuffer,"mode1")){
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode satu");
}
if(!strcmp(smsbuffer,"mode2")){
digitalWrite(A0,LOW);
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW);
sms.SendSMS(n,"mode dua");
}
if(!strcmp(smsbuffer,"mode3")){
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH);
sms.SendSMS(n,"mode tiga");
}
delsms();
}
}
delay(100);
}
void delsms()
{
for (int i=0; i<10; i++)
{
int pos=sms.IsSMSPresent(SMS_ALL);
if (pos!=0)
{
if (sms.DeleteSMS(pos)==1){}else{}
}
}
}
j. VIDEO HASILNYA
No comments:
Post a Comment