Microcontroller | Atmega328P |
Operating Voltage | 5V |
Input Voltage (recommended) | 7-12V |
Input Voltage (limit) | 6-20V |
Digital I/O Pins | 14 (of which 6 provide PWM output) |
PWM Digital I/O Pins | 6 |
Analog Input Pins | 6 |
DC Current per I/O Pin | 20mA |
DC Current for 3.3V Pin | 50Ma |
Flash Memory | 32KB of which 0.5KB used by bootloader |
SRAM | 2KB |
EEPROM | 1KB |
Clock Speed | 16MHz |
· MASTER
//MASTER
#include <Keypad.h>
#include <Password.h>
#include <LiquidCrystal.h>
// #include <SoftwareSerial.h>
// SoftwareSerial pengganti(2,13);
LiquidCrystal lcd(10, A1, A2, A3, A4, A5);
//PIR
int pir = 13;
int nilai_pir;
// int LED = 6;
//inisialisasi pin lm35
byte lm35 = A0;
int nilai;
int LED = 11;
int LEDm = 12;
Password password = Password( "1" ); // ubah password di sini
const byte baris = 4; // jumlah baris
const byte kolom = 4; // jumlah kolom
char keys[baris][kolom] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// inialisasi pin untuk keypad
byte kolomPin[kolom] = {5, 4, 3, 2};
byte barisPin[baris] = {9, 8, 7, 6};
// membuat objek untuk pembacaan keypad
Keypad keypad = Keypad( makeKeymap(keys), barisPin, kolomPin, baris, kolom );
// ****************** PROGRAM DEFAUT/SETTING AWAL ******************* //
void setup()
{
// inialisasi baud rate serial monitor
Serial.begin(19200);
// pengganti.begin(9600);
// deklarasi jumlah baris & kolom LCD
lcd.begin(16, 2);
// inialisasi status I/O pin
pinMode(LED, OUTPUT);
pinMode(lm35, INPUT);
pinMode(pir, INPUT);
// deklarasi awal status relay
digitalWrite(LED, LOW); // kondisi awal selenoid menutup
// deklarasi variabel keypad event
keypad.addEventListener(keypadEvent);
// menulis pada lcd
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SMART DOOR");
lcd.setCursor(0, 1);
lcd.print("GRUP 6 Up&Uc");
delay(1500);
}
// *************************** PROGRAM PERULANGAN TERUS MENERUS ************************** //
void loop()
{
digitalWrite(LED, LOW);
nilai_pir= digitalRead(pir);
if(nilai_pir = 1){
nilai = analogRead(lm35);
nilai = nilai/2.0479;
// Serial.println(nilai);
if(nilai>=20 && nilai<=36){
// menulis pada lcd
lcd.setCursor(0, 0);
lcd.print(nilai);
lcd.println(" C Anda Sehat");
lcd.setCursor(0, 1);
lcd.print("Masukkan Password");
// membaca keypad
keypad.getKey();
delay(10);
lcd.clear();
}
if(nilai>37){
digitalWrite(LEDm, HIGH);
lcd.setCursor(0, 0);
lcd.println(nilai);
lcd.print(" C Anda sakit");
lcd.setCursor(0, 1);
lcd.print("silahkan pulang");
delay(5000);
lcd.clear();
}
}
else{
// menulis pada lcd
lcd.setCursor(0, 0);
lcd.print("Sepi");
lcd.println(nilai);
lcd.setCursor(0, 1);
lcd.print("mana orang?");
delay(5000);
lcd.clear();
}
}
// ********************* PROGRAM TOMBOL UNTUK ENTER DAN RESET ******************* //
void keypadEvent(KeypadEvent eKey)
{
switch (keypad.getState())
{
case PRESSED:
Serial.print("Enter: ");
Serial.println(eKey);
delay(1);
// Serial.write(254);
switch (eKey) {
case '#': Login(); delay(1); break; // tombol A untuk login
case '*': password.reset(); delay(10); break; // tombol B untuk reset
default: password.append(eKey); delay(10);
}
}
}
// ********************** PROGRAM LOGIN ************************* //
void Login()
{
// jika password benar
if (password.evaluate())
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password Benar");
digitalWrite(LED, HIGH);
Serial.println('1');
delay(500);
Serial.println('9');
}
// jika password tidak benar atau salah
else
{
// menulis pada lcd
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Password Salah");
// relay tidak aktif, solenoid tetap menutup
digitalWrite(LED, LOW);
Serial.println("0");
delay(200);
}
}
· SLAVE
//SLAVE
#include <Servo.h>
#define sensor 5 // Pin Di gunakan untuk capactitive touch sensor
Servo myservo;
int pos;
int data = 0;
int LED = 6;
//BUTTON
const int buttonPin = 2; // deklarasi konstanta untuk button pada pin 2
int buttonState = 1; // deklarasi variabel untuk status button(ditekan atau tidak)
void setup()
{
Serial.begin(19200);
pinMode(LED, OUTPUT);
pinMode(sensor, INPUT_PULLUP);
pinMode(buttonPin,INPUT);
myservo.attach(9);
myservo.write(90);
;
}
void loop(){
digitalWrite(LED, LOW);
if (digitalRead(sensor) == HIGH) {
while(digitalRead(sensor) == HIGH){}
kunci();
}
if(digitalRead(buttonPin)==LOW){
Serial.println("Berhasil Buka Dari Dalam");
digitalWrite(LED, HIGH);
for (pos = 90; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15 ms for the servo to reach the position
}
delay(5000);
for (pos = 0; pos <= 90; pos += 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
}
if(digitalRead(buttonPin)==HIGH){
Serial.println(buttonPin);
}
else{
digitalWrite(LED, LOW);
}
}
void kunci()
{
if(Serial.available()>0){
data = Serial.read();
if(data=='1'){
Serial.println("Berhasil Buka Dari Luar");
digitalWrite(LED, HIGH);
for (pos = 90; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
delay(5000);
for (pos = 0; pos <= 90; pos += 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
}
}
else{
Serial.println('tidak ada password');
delay(1);
}
}
Tidak ada komentar:
Posting Komentar