You are on page 1of 6

#include <LCD_I2C.

h>
LCD_I2C lcd(0x27);
#include <Keypad.h>
#include "CTBot.h"
CTBot myBot;
int buzer=13;
int tb=33;
String ssid = "Kita"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "00000011"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "6295181138:AAEUr1XIt2kZ2N_Ago7Usnfszpp8clt7_Ko";
#define RELAY_PIN 12
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'A', 'B', 'C', 'D'},
{'3', '6', '9', '#'},
{'2', '5', '8', '0'},
{'1', '4', '7', '*'}
};
//byte pin_rows[ROW_NUM] = {5, 18, 19, 23}; // GIOP19, GIOP18, GIOP5, GIOP17
connect to the row pins
//byte pin_column[COLUMN_NUM] = {4, 2, 15, 14}; // GIOP16, GIOP4, GIOP0, GIOP2
connect to the column pins
byte pin_rows[ROW_NUM] = {23, 19, 18, 5}; // GIOP19, GIOP18, GIOP5, GIOP17
connect to the row pins
byte pin_column[COLUMN_NUM] = {14,15, 32, 4}; // GIOP16, GIOP4, GIOP0, GIOP2
connect to the column pins
String reply;
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM,
COLUMN_NUM );
const String password_1 = "0156CA"; // change your password here
const String password_2 = "5642CD"; // change your password here
const String password_3 = "545423"; // change your password here
String input_password;
int posisi=0;
void setup() {
pinMode(tb,INPUT_PULLUP);
Serial.begin(115200);
myBot.wifiConnect(ssid, pass);
pinMode(buzer,OUTPUT);
// set the telegram bot token
myBot.setTelegramToken(token);
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");

input_password.reserve(32); // maximum input characters is 32


pinMode(RELAY_PIN, OUTPUT);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("KeypadPassword");
lcd.setCursor(0,1);
lcd.print("Telegram");
delay(2000);
lcd.clear();
}

void loop() {
boolean ba=digitalRead(tb);
if(!ba){
Serial.println("ditekan");
digitalWrite(RELAY_PIN,HIGH);
delay(5000);
digitalWrite(RELAY_PIN,LOW);
}
TBMessage msg;
if (CTBotMessageText == myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("BUKA")) { // if the received message is "LIGHT
ON"...
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pintu Dibuka!");
delay(1000);
digitalWrite(RELAY_PIN, HIGH); // turn on the LED (inverted logic!)

myBot.sendMessage(915235770, "Pintu dibuka"); // notify the sender


lcd.clear();
}
else if (msg.text.equalsIgnoreCase("TUTUP")) { // if the received message is
"LIGHT ON"...
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Pintu Ditutup!");
delay(1000);
digitalWrite(RELAY_PIN, LOW); // turn on the LED (inverted logic!)

myBot.sendMessage(915235770, "Pintu ditutup"); // notify the sender


lcd.clear();
}
}
lcd.setCursor(0,0);
lcd.print("Input Password :");

char key = keypad.getKey();

if (key) {

Serial.println(key);
if (key == '*') {
input_password = ""; // reset the input password
lcd.clear();
posisi=0;
} else if (key == '#') {
if (input_password == password_1 || input_password == password_2 || input_password
== password_3) {
Serial.println("Valid Password => unlock the door");
reply="Pintu dibuka";
digitalWrite(buzer,HIGH);
delay(100);
digitalWrite(buzer,LOW);
delay(100);
digitalWrite(buzer,HIGH);
delay(100);
digitalWrite(buzer,LOW);
delay(100);
digitalWrite(buzer,HIGH);
delay(100);
digitalWrite(buzer,LOW);
delay(100);
myBot.sendMessage(915235770, reply);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Password Benar!");

delay(3000);
lcd.setCursor(0,1);
lcd.print("Pintu Dibuka!");
digitalWrite(RELAY_PIN, HIGH); // unlock the door for 20 seconds
delay(20000);
lcd.setCursor(0,1);
lcd.print("Pintu Ditutup!");
delay(2000);
digitalWrite(RELAY_PIN, LOW); // lock the door'
delay(2000);
lcd.clear();
posisi=0;
} else {
digitalWrite(buzer,HIGH);
reply="Password salah";
myBot.sendMessage(915235770, reply);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Password Salah!");
delay(3000);
delay(10);
digitalWrite(buzer,LOW);
lcd.setCursor(0,1);
lcd.print("Ulangi Lagi!");
Serial.println("Invalid Password => Try again");
delay(3000);
lcd.clear();
posisi=0;
}

input_password = ""; // reset the input password


posisi=0;
} else {
digitalWrite(buzer,HIGH);
delay(10);
digitalWrite(buzer,LOW);
lcd.setCursor(posisi,1);
lcd.print("*");
input_password += key; // append new character to input password string
}
posisi+=1;
}
}

You might also like