Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk memberikan pakan kepada hewan secara otomatis, alat ini menggunakan prinsip dasar timer atau pewaktu sebagai penandanya, jadi disini pada contoh pada jam 13.00 wib dan jam 20.00 wib alat akan memberikan pakan dengan cara membuka katup menggunakan motor servo kemudian akan menutup kembali selama satu detik membuka. alat ini menggunakan arduino sebagai processornya dan motor servo sebagai kendali valve pakannya, yang harus diperhatikan yaitu kosumsi arus yang diberikan agar motor servo bisa stabil dan tidak terjadi drop tegangan. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Mega
b. Modul RTC
c. Modul sms SIM800L
c. Motor Servo
d. LCD 16x2
e. UBEC 3A
f. Buck Converter
g. Program Arduino
#include "Wire.h"
#include <LiquidCrystal.h>
#include <Servo.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define DS3231_I2C_ADDRESS 0x68
Servo myservo;
int mark = 0;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup()
{
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else
{
Serial.println("\nstatus=IDLE");
}
if(started) {
//Enable this two lines if you want to send an SMS.
//if (sms.SendSMS("081235906660", "Arduino SMS"))
//Serial.println("\nSMS sent OK");
}
myservo.write(130);
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
myservo.attach(9);
Wire.begin();
//Serial.begin(9600);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
setDS3231time(0,59,12,7,7,1,17);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// send it to the serial monitor
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
if ((hour == 13)&&(mark == 0)) {
myservo.write(80);
delay(1000);
myservo.write(130);
if (sms.SendSMS("081235906660", "Pakan sudah diberikan"));
mark = 1;
}
if ((hour == 20)&&(mark == 1)) {
myservo.write(80);
delay(1000);
myservo.write(130);
if (sms.SendSMS("081235906660", "Pakan sudah diberikan"));
mark = 0;
}
}
void loop()
{
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second
}
#include <LiquidCrystal.h>
#include <Servo.h>
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define DS3231_I2C_ADDRESS 0x68
Servo myservo;
int mark = 0;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup()
{
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else
{
Serial.println("\nstatus=IDLE");
}
if(started) {
//Enable this two lines if you want to send an SMS.
//if (sms.SendSMS("081235906660", "Arduino SMS"))
//Serial.println("\nSMS sent OK");
}
myservo.write(130);
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
myservo.attach(9);
Wire.begin();
//Serial.begin(9600);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
setDS3231time(0,59,12,7,7,1,17);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// send it to the serial monitor
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
if ((hour == 13)&&(mark == 0)) {
myservo.write(80);
delay(1000);
myservo.write(130);
if (sms.SendSMS("081235906660", "Pakan sudah diberikan"));
mark = 1;
}
if ((hour == 20)&&(mark == 1)) {
myservo.write(80);
delay(1000);
myservo.write(130);
if (sms.SendSMS("081235906660", "Pakan sudah diberikan"));
mark = 0;
}
}
void loop()
{
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second
}
h. VIDEO HASILNYA
No comments:
Post a Comment