Translate

Arduino Smart Key Pengaman Pintu / Lemari Menggunakan Password + EEPROM

Arduino Smart Key Pengaman Pintu / Lemari Menggunakan Password + EEPROM


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk pengaman pintu atau lemari dengan fitur yaitu password dan eeprom. alat ini bisa jadi solusi untuk menjadikan rumah anda menjadi smart home atau smart key karena tidak perlu menggunakan kunci konvensional untuk buka tutup pintu melainkan hanya menggunakan password untuk buka tutup pintunya dengan solenoid door lock. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Uno




b. Lcd 16x2 + I2C




c. Keypad 4x4




d. Relay Modul






e. Program Arduino IDE

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
#include <EEPROM.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char customKey;
const byte ROWS = 4;
const byte COLS = 4;
int nilai;
int passwd;
int relay = 12;
int bt;
int buzzer = A0;

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

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);


void setup() {
  // put your setup code here, to run once:
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(relay,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(A3,INPUT_PULLUP);
  digitalWrite(relay,HIGH);
  digitalWrite(buzzer,LOW);
  passwd = EEPROM.read(0);
}

void loop() {

  bt = digitalRead(A3);

  if(bt == 0){
     digitalWrite(relay,LOW);     
     delay(3000);
     digitalWrite(relay,HIGH);
    }
  
 lcd.setCursor(0,0);
 lcd.print("Password");
       
 customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
    {
      nilai = nilai * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(nilai);
    }

 if (customKey == 'A'){
  lcd.clear();
  delay(1000);
  nilai = 0;
  passwd = 0;
  savepasswd();
  }

 if (customKey == 'C'){
  lcd.clear();
  delay(1000);
  nilai = 0;
  }  

 if (customKey == 'D'){
  lcd.clear();
  delay(1000);
  
  if(nilai == passwd){
     lcd.setCursor(0,0);
     lcd.print("Pintu Terbuka");
     lcd.setCursor(0,1);
     lcd.print("Passwd Benar");
     digitalWrite(relay,LOW);     
     delay(3000);
     digitalWrite(relay,HIGH);
     lcd.clear();
     nilai = 0;
    }
    
 else{
     lcd.setCursor(0,0);
     lcd.print("Pintu Tertutup");
     lcd.setCursor(0,1);
     lcd.print("Passwd Salah");
     digitalWrite(relay,HIGH);
     digitalWrite(buzzer,HIGH);     
     delay(3000);
     digitalWrite(buzzer,LOW);
     lcd.clear();
     nilai = 0;
   }
    
  }  
       
}

void savepasswd(){
lcd.setCursor(0,0);
lcd.print("Set Passwd");
       
 customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
    {
      passwd = passwd * 10 + (customKey - '0');  
      lcd.setCursor(0,1);
      lcd.print(passwd);
    }
      
 if (customKey == 'B'){
  lcd.clear();
  delay(1000);
  EEPROM.write(0, passwd);
  return;
  } 

 if (customKey == 'C'){
  lcd.clear();
  delay(1000);
  passwd = 0;
  }  

savepasswd();  
}





f. VIDEO HASILNYA













Arduino Timer Count Down Relay + EEPROM

Arduino Timer Count Down Relay + EEPROM


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk timer count down sebagai waktu untuk kendali on/off relay. fungsi utama dari alat ini yaitu untuk mengatur berapa lama waktu relay ON dan berapa lama waktu relay OFF. alat ini dilengkapi dengan fitur EEPROM sebagai backup data saat power dimatikan sehingga nilai setting masih tersimpan. untuk lebih jelasnya berikut adalah program dan daftar komponennya. 



a. Arduino




b. Relay Modul




c. Lcd + I2C




d. Rotary Encoder






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define outputA 2
#define outputB 3

float timertcm = 1.5;
int timertcmdetik = 5;
int timertcmmenit = 1;
int timertdm = 1;
int timertdmdetik;
int timertdmmenit = 1;
int savetdmdetik;
int savetdmmenit;
int savetcmdetik;
int savetcmmenit;

float counter = 0;
int aState;
int aLastState;
int btrotary = 11;  //pin bt rotary
int x;
int relay = 10;  //pin relay
int tanda;
int cacah;
int waktu;
int bttrigger = 12;  //pin trigger
int y;
int mark;

int addr1 = 0;
int addr2 = 1;
int addr3 = 2;
int addr4 = 3;


void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor();

   pinMode(outputA,INPUT);
   pinMode(outputB,INPUT);
   pinMode(btrotary,INPUT_PULLUP);
   pinMode(bttrigger,INPUT_PULLUP);
   pinMode(relay,OUTPUT);
 
   Serial.begin(9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA); 
savetdmdetik = EEPROM.read(addr1);
savetcmdetik = EEPROM.read(addr2);
savetdmmenit = EEPROM.read(addr3);
savetcmmenit = EEPROM.read(addr4);

}


void loop() {

  lcd.setCursor(0,0);
  lcd.print("TCM:");
  lcd.print(savetcmmenit);
  lcd.print(".");
  lcd.print(savetcmdetik);
  lcd.print(" TDM:");
  lcd.print(savetdmmenit);

  lcd.setCursor(0,1);
  lcd.print("ON");
  lcd.print("00");
  lcd.print(":");
  lcd.print("00");
  lcd.print(" OF");
  lcd.print("00");
  lcd.print(":");
  lcd.print("00");
  lcd.print("   ");
 
y = digitalRead(bttrigger);

if(y == 0){
  timertdmdetik = savetdmdetik;
  timertcmdetik = savetcmdetik;
  timertdmmenit = savetdmmenit;
  timertcmmenit = savetcmmenit;

  mulaitdm();
  mulaitcm();
  digitalWrite(relay,LOW);
  }


x = digitalRead(btrotary);

if((x == 1)&&(mark = 1)){
  delay(200);
  digitalWrite(relay,LOW);
  mark = 0;
  }
 
if((x == 0)&&(mark == 0)){
  delay(200);
  digitalWrite(relay,HIGH);
  tanda = 1;
  cacah++;
  mark = 1;
  }
 
if(tanda == 1){
  waktu++;
  }

if(waktu > 10){
 tanda = 0;
 cacah = 0;
 waktu = 0;
 tanda = 0;


if((waktu <= 10)&&(cacah >= 3)){
lcd.clear();
delay(2000);
setting1();
setting2();
savetdmdetik = timertdmdetik;
savetcmdetik = timertcmdetik;
savetdmmenit = timertdmmenit;
savetcmmenit = timertcmmenit;

EEPROM.write(addr1, savetdmdetik);
EEPROM.write(addr2, savetcmdetik);
EEPROM.write(addr3, savetdmmenit);
EEPROM.write(addr4, savetcmmenit);

x = 1;
cacah = 0;
}
   
}

void setting1(){

digitalWrite(relay,LOW);

x = digitalRead(btrotary);

aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){   
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) {
       timertcmdetik = timertcmdetik + 1;
     } else {
       timertcmdetik = timertcmdetik - 1;
     }

     if(timertcmdetik > 59){
      timertcmdetik = 0;
      timertcmmenit++;
      }

      if(timertcmdetik <= 0){
      timertcmmenit--;
      timertcmdetik = 59;
      }

      if(timertcmmenit <= 0){
      timertcmmenit = 0;
      }
 
   lcd.setCursor(0,0);
   lcd.print("SETTING TCM");
   lcd.setCursor(0,1);
   lcd.print(timertcmmenit);
   lcd.print(".");
   lcd.print(timertcmdetik);
   lcd.print("   ");
 
 } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 
if(x == 0){
  lcd.clear();
  delay(2000);
  return;
  }

setting1(); 
}

void setting2(){
 
x = digitalRead(btrotary);

aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){   
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) {
       timertdmmenit = timertdmmenit + 1;
     } else {
       timertdmmenit = timertdmmenit - 1;
     }
   
   lcd.setCursor(0,0);
   lcd.print("SETTING TDM");
   lcd.setCursor(0,1);
   lcd.print(timertdmmenit);
   lcd.print("        ");
 
 } 
   aLastState = aState; // Updates the previous state of the outputA with the current state

if(timertdmmenit < 1){
  timertdmmenit = 1;
}
 
if(x == 0){
  lcd.clear();
  delay(2000);
  return;
  }

setting2(); 
}

void mulaitdm(){

y = digitalRead(bttrigger);

if(y == 1){
  return;
  }
 
  digitalWrite(relay,LOW);
 
  lcd.setCursor(0,0);
  lcd.print("TCM:");
  lcd.print(savetcmmenit);
  lcd.print(".");
  lcd.print(savetcmdetik);
  lcd.print(" TDM:");
  lcd.print(savetdmmenit);

  lcd.setCursor(0,1);
  lcd.print("ON");
  lcd.print(timertcmmenit);
  lcd.print(":");
  lcd.print(timertcmdetik);
  lcd.print(" OF");
  lcd.print(timertdmmenit);
  lcd.print(":");
  lcd.print(timertdmdetik);
  lcd.print("   ");
 
  timertdmdetik --;
  delay(1000); 

if(timertdmdetik < 0){
  timertdmdetik = 59;
  timertdmmenit--;
  }

if(timertdmmenit < 0){
  timertdmmenit = 0;
  } 

if((timertdmdetik == 0)&&(timertdmmenit == 0)) 
{
  return;
}

 
mulaitdm(); 
}

void mulaitcm(){

  y = digitalRead(bttrigger);

if(y == 1){
  return;
  }
 
  digitalWrite(relay,HIGH);
 
  lcd.setCursor(0,0);
  lcd.print("TCM:");
  lcd.print(savetcmmenit);
  lcd.print(".");
  lcd.print(savetcmdetik);
  lcd.print(" TDM:");
  lcd.print(savetdmmenit);

  lcd.setCursor(0,1);
  lcd.print("ON");
  lcd.print(timertcmmenit);
  lcd.print(":");
  lcd.print(timertcmdetik);
  lcd.print(" OF");
  lcd.print(timertdmmenit);
  lcd.print(":");
  lcd.print(timertdmdetik);
  lcd.print("   ");
 
  timertcmdetik --;
  delay(1000); 

if(timertcmmenit < 0){
  timertcmmenit = 0;
  }
 
 
if(timertcmdetik < 0){
  timertcmdetik = 59;
  timertcmmenit--;
  }

if((timertcmdetik == 0)&&(timertcmmenit == 0)) 
{
  return;
}

 
mulaitcm(); 
}





f. VIDEO HASILNYA








WEMOS D1 Monitoring Suhu dan Kelembaban via Internet / IOT Server Thingspeak

WEMOS D1 Monitoring Suhu dan Kelembaban Sensor DHT11 via Internet / IOT Server Thingspeak

             
               Pada kesempatan kali ini saya akan menjelaskan mengenai bagamana cara membuat sebuah alat dengan menggunakan Wemos D1 untuk monitor suhu dan kelembaban menggunakan sensor DHT11 via internet dengan servernya yaitu Thingspeak. keunggulan dari alat ini yaitu bisa monitoring jarak jauh tanpa kabel karena berbasis IOT. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Wemos D1




b. Sensor DHT11






c. Program Arduino IDE

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <DHT.h>

#define DHTPIN 0   //nodemcu pin D3

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

String apiKey = "AABBCCDDEEFFGGHHIIJJ";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "Hotspot Hpku";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

WiFiClient client;

void setup()
{
 
       Serial.begin(115200);
       delay(10);

       Serial.println("Connecting to ");
       Serial.println(ssid);

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


      while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");

      dht.begin();
     
}



void loop()
{

  int h = dht.readHumidity();
  int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
 

                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      { 
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + t + "&field2=" + h + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                           
                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" humidity: ");
                             Serial.print(h);
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

          Serial.println("Waiting...");
 
  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(10000);
}




d. VIDEO HASILNYA









ARDUINO PID CONTROL SUHU SENSOR DS18B20 DAN PELTIER

ARDUINO PID CONTROL SUHU SENSOR DS18B20 DAN PELTIER


               Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan prinsip PID untuk stabilsasi suhu pada heater. Alat ini menggunakan sensor suhu ds18b20 dan pemanas menggunakan peltier. driver yang digunakan untuk peltier adalah transistor TIP3055, jika ingin menggunakan pemanas sumber AC maka bisa diganti dengan TRIAC atau sejenisnya. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Nano




b. Heater Peltier




c. LCD 16x2 dan I2C






d. Sensor Ds18b20






e. Program Arduino IDE

#include "Wire.h"
#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

OneWire  ds(12);  // on pin 10 (a 4.7K resistor is necessary)

float kp = 1.08;
float ki = 1.17;
float kd = 1.15;

float p,ix,d,suhu,pid;
float error,errorx,sumerr;

float sp;   
float spx = 50;  //set point
int pinpwm = 11;

 byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;


void setup() {

  pinMode(pinpwm,OUTPUT);
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
}

void loop() {

  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }

  for( i = 0; i < 8; i++) {

  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      return;
  }

  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not

  present = ds.reset();
  ds.select(addr);  
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms

  }
  
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  suhu = celsius;
  
  
  analogWrite(pinpwm,pid);
  
  sp = spx + 30;  //atur range overlap kalibrasi
  
  error = sp - suhu;
  p = error * kp;
  sumerr = error + errorx; 
  ix = ki * sumerr; 
  d = kd * (error - errorx);
  pid = p + ix + d;
//pid = 255.0 - pid; 

//  if(pid < 1){
//  pid = 0;
//  }
    
 lcd.setCursor(0,0);
 lcd.print("Suhu=");
 lcd.print(suhu);
 lcd.print("/");
 lcd.print(spx);
 lcd.print("   ");

 lcd.setCursor(0,1);
 lcd.print("PID=");
 lcd.print(pid);
 lcd.print("     ");

Serial.println("suhu= ");     
Serial.println(suhu);
Serial.println("pid= ");     
Serial.println(pid);

delay(1000);

errorx = error;

}





f. VIDEO HASILNYA










WEMOS D1 MONITOR SUHU ONLINE / INTERNET SENSOR LM35 SERVER THINKSPEAK (IOT PROJECT)

WEMOS D1 MONITOR SUHU ONLINE / INTERNET SENSOR LM35 SERVER THINGSPEAK (IOT PROJECT)


           Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah alat yang dapat difungsikan sebagai alat monitor suhu secara online atau menggunakan intenet. alat ini menggunakan WEMOS D1 namun jika diganti dengan Nodemcu juga bisa. alat ini memiliki keuntungan yaitu jarak yang jauh karena berbasis internet. alat ini menggunakan server THINGSPEAK. untuk lebih jelasnya berikut adalah daftar komponen dan programnya.



a. Wemos D1




b. Sensor suhu LM35




c. LCD 16x2 + i2c






d. Program Arduino IDE

#include <ESP8266WiFi.h>
#include "Wire.h"
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

String apiKey = "3KAB1MLFRXT7VU3W";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "Hotspotku";     // replace with your wifi ssid and wpa2 key
const char *pass =  "1234567";
const char* server = "api.thingspeak.com";


int adcsensor;
float suhu;

WiFiClient client;

void setup() {

  WiFi.begin(ssid, pass);
  
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
  
}


void loop(){

adcsensor = analogRead(A0);
suhu = adcsensor * (4.84 /1023.0) * 100;

 lcd.setCursor(0,0);
 lcd.print("Suhu= ");
 lcd.print(suhu);
 lcd.print(" c     ");
  

              if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(suhu);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + suhu + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");                             
                                        
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);

                             Serial.print("suhu= ");
                             Serial.println(suhu);
                             delay(10000);
                        }
                         
                        client.stop();

}





e. VIDEO HASILNYA