Skip to main content

Nyalakan Lampu Pakai Password, Keypad Arduino

Nyalakan Lampu Pakai Password, Keypad Arduino


Video berikut adalah cara bagaimana membuat password untuk menyalakan lampu, lock door, televisi, kipas, Kunci Pintu, dan lain lain.




Untuk code silahkan copy paste script dibawah ini:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); 
// Include Keypad library
#include <Keypad.h>

// Length of password + 1 for null character
#define Password_Length 8
// Character to hold password input
char Data[Password_Length];
// Password
char Master[Password_Length] = "123ABCD";

// Pin connected to lock relay input
int lockOutput = 13;

// Counter for character entries
byte data_count = 0;

// Character to hold key input
char customKey;

// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;

// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

// Connections to Arduino
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  // Setup LCD with backlight and initialize
  lcd.backlight();
  lcd.init();

  // Set lockOutput as an OUTPUT pin
  pinMode(lockOutput, OUTPUT);
// default bernilai LOW
  digitalWrite(lockOutput, HIGH);

}

void loop() {

  // Initialize LCD and print
  lcd.setCursor(0, 0);
  lcd.print("Masukan Password:");

  // Look for keypress
  customKey = customKeypad.getKey();
  if (customKey) {
    // Enter keypress into array and increment counter
    Data[data_count] = customKey;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;
  }

  // See if we have reached the password length
  if (data_count == Password_Length - 1) {
    lcd.clear();

    if (!strcmp(Data, Master)) {
      // Password is correct
      lcd.print("Password Benar");
      // Turn on relay for 5 seconds
      digitalWrite(lockOutput, LOW);
      delay(5000);
      digitalWrite(lockOutput, HIGH);
    }
    else {
      // Password is incorrect
      lcd.print("Salah Password");
      delay(5000);
    }

    // Clear data and LCD display
    lcd.clear();
    clearData();
  }
}

void clearData() {
  // Go through array and clear data
  while (data_count != 0) {
    Data[data_count--] = 0;
  }
  return;
}





Comments

Popular posts from this blog

Motor Servo dengan Sensor Ultrasonic

Coding: #include <Servo.h> #define trigPin 12 #define echoPin 11 Servo servo; int sound = 250; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); servo.attach(9); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 10) { Serial.println("the distance is less than 10"); servo.write(180); delay(1500); } else { servo.write(0); } if (distance > 60 || distance <= 0){ Serial.println("The distance is more than 60"); } else { Serial.print(distance); Serial.println(" cm"); } delay(500); }

Sensor Pendeteksi Warna - Sortir Barang Dengan Sensor Warna | TCS230

Video Kali ini kita akan membahas mengenai sensor warna. Menunjukkan bagaimana cara kerjanya, cara menghubungkannya, cara mengkalibrasinya, dan cara mengekstrak nilai RGB dari sensor. TCS230 (juga dikenal sebagai TCS3200) adalah sensor warna yang populer dan murah. Ini menghasilkan gelombang yang frekuensinya mencerminkan intensitas warna. Ini juga memiliki fitur interupsi yang dapat diprogram yang dapat Anda atur untuk memicu sebagai respons terhadap warna tertentu. Sensor ini akan berguna dalam merancang robot yang mengikuti warna, penyortir produk yang di tandai dengan sebuah warna khusus.  Tetapi sebelum Anda menggunakannya, Anda harus mengkalibrasinya. Sensor ini dapat di aplikasikan atau diterapkan pada industri-industri untuk penyortiran atau pemisahan suatu produk pada saat dikemas atau packing, sehingga proses penyortiran dapat lebih cepat dan efisien. Copy dan paste script dibawah ini: FILE 1: KALIBRASI SENSOR #define S0 4 #define S1 5 #define S2 6 #define S3 7 #define se...

Automatic Fish Feed, Pemberi Makan Ikan Otomatis Dengan Timer

Automatic Fish feeder adalah alat untuk memberi makan ikan secara otomatis dengan menggunakan timer. Kita dapat mengatur jadwal pemberian makan ikan berdasarkan waktu, misalkan memberi makan ikan 2 kali sehari, artinya alat akan secara otomatis akan terbuka setiap 12 Jam sekali atau 4 kali sehari, 6 jam sekali. Waktu ini dapat kita atur sesuai dengan keinginan kita. Berikut coding lengkapnya, silahkan di copas dibawah ini: #include <Servo.h> Servo motor; void setup() {   motor.attach(9); } void loop() {   motor.write(200);   delay(8000); /* sama dengan setiap 6 jam atau sehari 4 kali*/   motor.write(120);   delay(200); }