Translate

Arduino JAM DIGITAL dengan fitur ALARM dan fitur sensor getar PIEZOELEKTRIK untuk OFF ALARM

Arduino JAM DIGITAL dengan fitur ALARM dan fitur sensor getar PIEZOELEKTRIK untuk OFF ALARM


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk menampilkan jam dan juga sebagai ALARM saat tidur, alat ini seperti jam digital biasa yang disetting menggunakan tombol dan ada alarm berupa buzzer, uniknya alat ini yaitu untuk mematikan bunyi buzzer alarm harus menggunakan injakan atau getaran pada piezoelektrik yang diletakkan pada karpet sehingga orang yang akan mematikan bunyi alarm harus bangun dan menginjakkan kaki di karpet. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. RTC DS1307




c. LCD 16x2 + I2C




d. Sensor Getar PIEZOELEKTRIK + Amplifier






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h> 
#define DS3231_I2C_ADDRESS 0x68

LiquidCrystal_I2C lcd(0x3F, 16, 2);

int buzzer = 2;

int btset = 3;
int btup = A2;
int btdown = A3;
int btok = 5;
int mark = 0;

int btsetx;
int btupx;
int btdownx;
int btokx;
int jam;

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

// 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) );
}


void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,HIGH);
 
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
 
 
  Wire.begin();
  Serial.begin(9600);
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,53,8,6,5,10,18); 
}


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()
{
 
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
 
  lcd.setCursor(0,0);
  // send it to the serial monitor
  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);
    
}



void loop()
{
  displayTime();
  delay(1000);
   lcd.setCursor(0,1);
   lcd.print("ALRM= ");
   lcd.print(jam);
   lcd.print("        ");
   
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);
 
  if(btsetx == LOW){
  lcd.clear();
  delay(1000);
  setting();
  }
 
  if((hour == jam)&&(mark == 0)){
  digitalWrite(buzzer,LOW);
  }

 int dataadc = analogRead(A0);

   lcd.setCursor(9,1);
   lcd.print("ADC=");
   lcd.print(dataadc);
   lcd.print("        ");
 
  if(dataadc > 10){
  digitalWrite(buzzer,HIGH);
  mark = 1;
  }
 
  if(hour == jam + 1){
  mark = 0;
  }
 
}   


void setting(){
  digitalWrite(buzzer,HIGH);
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);
 
 lcd.setCursor(0,0);
 lcd.print("SET JAM: ");
 lcd.print(jam);
 lcd.print("         ");

 if(btupx == LOW){
 delay(200);
   jam++;
 }

 if(btdownx == LOW){
 delay(200);
   jam--;
 }

 if(jam < 0){
 jam = 23;
 }

 if(jam > 23){
 jam = 0;
 }

 if(btokx == LOW){
 delay(200);
 lcd.clear();
 return;
 }

setting();
}






f. VIDEO HASILNYA









No comments:

Post a Comment