Вы находитесь на странице: 1из 7

 Instalasi Library arduino(DHT, LCDI2C,keypad)

 scaning I2C Alamat + serial monitor

#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Memindai...");
nDevices = 0;
for (address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0)
{
Serial.print("I2C terbaca pada alamat 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
}
}
if (nDevices == 0)
Serial.println("Tidak ada satupun alamat I2C yang ditemukan\n");
else
Serial.println("selesai\n");
delay(5000);
}
 LCD + dht 11 Kelembaban dan Suhu

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(ALAMAT_I2CNYA, 16, 2);

void setup()
{ dht.begin();
lcd.begin();
lcd.backlight();
}

void loop()
{
int humidity = dht.readHumidity();
float celcius = dht.readTemperature();
lcd.setCursor(0,0);
lcd.print("Hum :");
lcd.print(humidity);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.print(celcius);
lcd.print(char(223));
lcd.print("C");
delay(500);
}
 LCD I2C dan keypad

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

const byte ROWS = 4;


const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {3, 2, 1, 0};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS


);

void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Key Is : ");
}
void loop() {
char key = keypad.getKey();
if (key) {
lcd.setCursor(9, 0);
lcd.print(key);
}
}
 LCD + keypad Login Sederhana
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte state;
byte code;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {3, 2, 1, 0};
char data_pass[6] = "123456";

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS


);

void setup() {
lcd.begin();
lcd.backlight();
reset();
}
void reset()
{ lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sistem Keamanan");
lcd.setCursor(0, 1);
lcd.print("PIN :");
state = 0;
code = 0;
}
void gagal()
{ lcd.setCursor(0, 0);
lcd.print("Password Salah!");
delay(2000);
lcd.clear();
reset();
}

void sukses()
{ a:
lcd.setCursor(0, 0);
lcd.print("Login Sukses..!");
lcd.setCursor(0, 1);
lcd.print("* : Logout");
char key = keypad.getKey();
if (key != '*')
{
goto a;
}
else
{
reset();
}
}
void loop() {
char key = keypad.getKey();
if (key)
{ if (key != '#')
{
lcd.setCursor(state + 5, 1);
if (data_pass[state] == key)
{ code++;
}
else
{
code--;
}
lcd.print("*");
delay(100);
state++;
}
else
{ if (code == 6)
{
lcd.clear();
sukses();
}
else
{
lcd.clear();
gagal();
}
}
}
}

Вам также может понравиться