Translate

Alat Absensi Penjaga Malam / Satpam / Security

Alat Absensi Penjaga Malam / Satpam / Security


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk absensi petugas jaga malam atau satpam. alat ini menggunakan 3 buah tombol yang digunakan untuk check point area ketika area yang terdapat tombol itu telah di cek. adapun alasannya yaitu agar security atau petugas jaga bekerja sesuai waktu yang diberikan. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Nano




b. RTC modul






c. Program Arduino IDE

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

int btsetx;
int btupx;
int btdownx;
int btokx;
int jam;
int button = 2;
int bt1 = 4;
int bt2 = 5;
int buzzer = 3;
int tstart = 21;
int tfinish = 5;
int waktu = 59;
int counter;
int simpan;
int mark;
int bt1x;
int bt2x;
int area;

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();
  simpan = EEPROM.read(0);
  
  pinMode(button,INPUT_PULLUP);
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,HIGH);
  
  Wire.begin();
  Serial.begin(9600);
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(50,59,20,4,30,7,20);
}

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();
  
  int buttonx = digitalRead(button);
  bt1x = digitalRead(bt1);
  bt2x = digitalRead(bt2);
  
  lcd.setCursor(9,0);
  lcd.print(area);
  
  lcd.setCursor(0,1);
  lcd.print(tstart);
  lcd.print("/"); 
  lcd.print(tfinish);
  lcd.print("/"); 
  lcd.print(simpan);
  lcd.print("/");
  lcd.print(counter);
  lcd.print("     ");
  
  lcd.setCursor(12,1); 
  lcd.print(dayOfWeek);
  lcd.print("/");
  lcd.print(dayOfMonth);
  lcd.print(" ");
  
  if((hour >= tstart)&&(hour <= 23)&&(counter <= waktu)&&(hour != jam)&&(mark == 0)){
  lcd.setCursor(11,0);
  lcd.print("START");  
  mark = 1;
  }
  
  if((hour >= 0)&&(hour <= tfinish)&&(counter <= waktu)&&(hour != jam)&&(mark == 0)){
  lcd.setCursor(11,0);
  lcd.print("START");  
  mark = 1;
  }
  
  if((mark == 1)&&(counter < waktu)){
  counter++;
  }
  
  
  if((bt1x == 0)&&(counter < waktu)&&(mark == 1)&&(area == 0)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);  
  area = 1;
  }
  
  if((bt2x == 0)&&(counter < waktu)&&(mark == 1)&&(area == 1)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);  
  area = 2;
  }
  
  if((bt1x == 0)&&(bt2x == 0)){
  simpan = 0;
  EEPROM.write(0, simpan);
  }
  
  if((buttonx == 0)&&(counter < waktu)&&(mark == 1)&&(area == 2)){
  digitalWrite(buzzer,LOW);
  delay(500);
  digitalWrite(buzzer,HIGH);
  simpan++;
  EEPROM.write(0, simpan);
  lcd.setCursor(11,0);
  lcd.print("OFF  "); 
  counter = 0;
  mark = 0;
  area = 0;
  }
  
  if(counter == waktu){
  lcd.setCursor(11,0);
  lcd.print("OFF  "); 
  counter = 0;
  mark = 0;
  area = 0;
  }
  
  jam = hour;
  
  if((dayOfMonth == 1)&&(hour == 0)&&(minute == 0)&&(second == 0)){
  simpan = 0;
  EEPROM.write(0, simpan);
  }
  
  delay(1000);




d. VIDEO HASILNYA








No comments:

Post a Comment