Translate

Membuat Alat Pertamini / Pengisi Air (BBM) Otomatis Menggunakan Arduino dan Sensor water Flow Solenoid Valve dan RFID RC522

Membuat Alat Pertamini / Pengisi Air (BBM) Otomatis Menggunakan Arduino dan Sensor Water Flow + Solenoid Valve dan RFID Reader RC522


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang fungsinya seperti alat pada SPBU atau pertamini yaitu pengisi air atau BBM otomatis sesuai dengan input liter / mililiter sesuai angka yang telah diinput via keypad. yang membedakan alat ini dengan yang lainnya yaitu terdapat RFID untuk pembelian dan pembayaran air / BBMnya sehingga mirip seperti kartu E-Money yang harus diisi saldo dulu. untuk lebih jelasnya berikut adalah komponen dan programnya.



a. Arduino Mega




b. RFID Reader RC522




c. LCD 20x4 + I2C Module





d. Sensor Water Flow dan Solenoid Valve





e. Keypad 4x4




f. Relay Module






g. Program Arduino IDE

#include <SPI.h>
#include <Keypad.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 20, 4); //library i2c lcd

#define SS_PIN 53
#define RST_PIN 49

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int buzzerm = A0;
int buzzerp = A3;
int relay = 11;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;
long passwd = 0;
long isiku;
long kartu1;
long kartu2;
long kartu3;
long kartu4;
int id;
long beli;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5,4,3,10}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); 


byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;

volatile byte pulseCount;  

unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
int totalMilliLitres;

unsigned long oldTime;

void setup() 
{
  
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  
  pinMode(buzzerm,OUTPUT);
  pinMode(buzzerp,OUTPUT);
  digitalWrite(buzzerm,LOW);
  digitalWrite(buzzerp,LOW);
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");
//  Serial.println();

  delay(1000);

}


void loop() 
{

  lcd.setCursor(0,0); 
  lcd.print("Pilih Menu");
  lcd.setCursor(0,1); 
  lcd.print("A.Isi    B.Bayar");
  
customKey = customKeypad.getKey();

    if(customKey == 'B'){

    pulseCount        = 0;
    flowRate          = 0.0;
    flowMilliLitres   = 0;
    totalMilliLitres  = 0;
    oldTime           = 0;
  
    lcd.clear();
    lcd.setCursor(0,0); 
    lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear(); 
    isiscan();
    lcd.clear();
    beli = 0;
    bayar();
    digitalWrite(relay, LOW);
    mulaiisi();
    }

    if(customKey == 'C'){
    lcd.clear();
    lcd.setCursor(0,0); 
    lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear();  
    cek();
    }
    
    if(customKey == 'A'){
    lcd.clear();
    delay(1000); 
    passwd = 0;
    isi();
      lcd.setCursor(0,0); 
      lcd.print("Dekatkan Kartu");
    delay(3000);
    lcd.clear();
    isiscan();
    delay(1000);
    isiku = 0;
    scan();
    }  
    
}


void cek(){
  
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    //return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    //return;
  }
  //Show UID on serial monitor
  //lcd.setCursor(0,0); 
//  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
 //    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
 //    Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
//  Serial.println();
//  Serial.print("Message : ");
  content.toUpperCase();

  if (content.substring(1) == "99 AD B5 55") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);
     
      lcd.setCursor(0,0); 
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1); 
      lcd.print("Saldo=");
      lcd.print(kartu1);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

 if (content.substring(1) == "51 BB 69 1A") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,0); 
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1); 
      lcd.print("Saldo=");
      lcd.print(kartu2);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

   if (content.substring(1) == "A3 32 48 83") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);
       
      lcd.setCursor(0,0); 
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1); 
      lcd.print("Saldo=");
      lcd.print(kartu3);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

   if (content.substring(1) == "06 5D 01 FA") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,0); 
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1); 
      lcd.print("Saldo=");
      lcd.print(kartu4);
      lcd.print("       ");
      delay(3000);
      lcd.clear();
      return;
  }

  cek();  
  }


void isi(){
  
  lcd.setCursor(0,0); 
  lcd.print("Input Password");
  
customKey = customKeypad.getKey();

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

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


void isiscan(){

  lcd.setCursor(0,0); 
  lcd.print("Scan Kartu");
  
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
//  Serial.println("Put your card to the reader...");
  
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    //return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    //return;
  }
  //Show UID on serial monitor
  //lcd.setCursor(0,0); 
//  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
 //    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
 //    Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
//  Serial.println();
//  Serial.print("Message : ");
  content.toUpperCase();

  if (content.substring(1) == "51 BB 69 1A") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,1); 
      lcd.print(content.substring(1));
      delay(3000);
      id = 1;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

 if (content.substring(1) == "99 AD B5 55") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,1); 
      lcd.print(content.substring(1));
      delay(3000);
      id = 2;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

   if (content.substring(1) == "A3 32 48 83") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,1); 
      lcd.print(content.substring(1));
      delay(3000);
      id = 3;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

   if (content.substring(1) == "06 5D 01 FA") 
  {
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,HIGH);
       delay(200);
       digitalWrite(buzzerm,LOW);
       digitalWrite(buzzerp,LOW);

      lcd.setCursor(0,1); 
      lcd.print(content.substring(1));
      delay(3000);
      id = 4;
      lcd.clear();
      content.substring(1) = "";
      return;
  }

isiscan();  
}

void scan(){
  
  lcd.setCursor(0,0); 
  lcd.print("Isi Berapa mL?");
  
customKey = customKeypad.getKey();

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

    if((customKey == 'D')&&(id == 1)){
    lcd.clear();
    delay(2000); 
    kartu1 = isiku; 
    return;
    }

    if((customKey == 'D')&&(id == 2)){
    lcd.clear();
    delay(2000); 
    kartu2 = isiku; 
    return;
    }

    if((customKey == 'D')&&(id == 3)){
    lcd.clear();
    delay(2000); 
    kartu3 = isiku; 
    return;
    }

    if((customKey == 'D')&&(id == 4)){
    lcd.clear();
    delay(2000); 
    kartu4 = isiku; 
    return;
    }
    
 scan(); 
  }

void bayar(){

  lcd.setCursor(0,0); 
  lcd.print("Beli Berapa mL ?");
  
customKey = customKeypad.getKey();

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

    if((customKey == 'D')&&(id == 1)){
    lcd.clear();
    delay(2000); 
    kartu1 = kartu1 - beli;

    if(kartu1 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu1);  
    delay(1000);
    lcd.setCursor(0,0); 
    lcd.print("BERHASIL");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu1);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu1 < 0){
    kartu1 = kartu1 + beli;  
    lcd.setCursor(0,0); 
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu1);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 2)){
    lcd.clear();
    delay(2000); 
    kartu2 = kartu2 - beli;

    if(kartu2 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu2);  
    delay(1000);
    lcd.setCursor(0,0); 
    lcd.print("BERHASIL");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu2);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu2 < 0){
    kartu2 = kartu2 + beli;  
    lcd.setCursor(0,0); 
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu2);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 3)){
    lcd.clear();
    delay(2000); 
    kartu3 = kartu3 - beli;

    if(kartu3 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu3);
    delay(1000);
    lcd.setCursor(0,0); 
    lcd.print("BERHASIL");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu3);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu3 < 0){
    kartu3 = kartu3 + beli;  
    lcd.setCursor(0,0); 
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu3);
    delay(5000);
    lcd.clear();
    beli = 0;
    }

    }

    if((customKey == 'D')&&(id == 4)){
    lcd.clear();
    delay(2000); 
    kartu4 = kartu4 - beli;

    if(kartu4 >= 0){
    Serial.println(id);
    Serial.println(beli);
    Serial.println(kartu4);
    delay(1000);
    lcd.setCursor(0,0); 
    lcd.print("BERHASIL");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu4);
    delay(5000);
    lcd.clear();
    return;
    }

    if(kartu4 < 0){
    kartu4 = kartu4 + beli;  
    lcd.setCursor(0,0); 
    lcd.print("SALDO KURANG");
    lcd.setCursor(0,1); 
    lcd.print("SALDO=");
    lcd.print(kartu4);
    delay(5000);
    lcd.clear();
    beli = 0;
    }
    }
    
  bayar();
  }

void mulaiisi(){

lcd.setCursor(0,0); 
lcd.print("Beli ");
lcd.print(beli);
lcd.print(" mL   ");

delay(100);
  
if((millis() - oldTime) > 1000)    // Only process counters once per second
  { 

    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
       
    
    // Print the flow rate for this second in litres / minute
    //lcd.setCursor(0,3);
    //lcd.print("Flow rate: ");
    //lcd.print(int(flowRate));  // Print the integer part of the variable
    //lcd.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    
    //lcd.print(frac, DEC) ;      // Print the fractional part of the variable
    //lcd.print("L/min             ");
    // Print the number of litres flowed in this second
    
    lcd.setCursor(0,1);
    lcd.print("Spd Flow: ");             // Output separator
    lcd.print(flowMilliLitres);
    lcd.print(" mL/Sec   ");

    // Print the cumulative total of litres flowed since starting
    lcd.setCursor(0,2); 
    lcd.print("ISI: ");             // Output separator
    lcd.print(totalMilliLitres);
    lcd.print(" mL   "); 

    //lcd.setCursor(0,3); 
    //lcd.print("              "); 
    
    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  if(totalMilliLitres >= beli){
    lcd.clear();
    delay(1000);
    digitalWrite(relay, HIGH);
    return;
    }
  
  }

    
mulaiisi(); 
}
  
void pulseCounter()
{
  pulseCount++;
}






h. VIDEO HASILNYA








Alat Kendali Pompa Motor DC dan Monitor Suhu Ds18b20 VB 6 (Visual Basic 6.0) ARDUINO

Alat Kendali Pompa Motor DC dan Monitor Suhu Ds18b20 VB 6 (Visual Basic 6.0) ARDUINO


          Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah alat yang berfungsi untuk mengendalikan pompa motor dc dan monitor suhu menggunakan visual basic 6.0 dan Arduino. alat ini menggunakan sensor suhu DS18B20 dan juga sebagai kendali pompa menggunakan relay modul.. interface yang digunakan menggunakan VB 6 dan database Ms. Access. untuk lebih jelasnya berikut adalah program dan komponennya.




a. Arduino Mega




b. Relay Modul




c. LCD Keypad Shield




d. Sensor Suhu DS18B20




e. Driver Motor L298






f. Program Arduino IDE

#include<Wire.h>
#include<LiquidCrystal.h>
#include <OneWire.h>

LiquidCrystal lcd(15, 14, 19, 18, 17, 16);
OneWire  ds(8);

int dataadc;
int btset = 724;
int btsave = 483;
int btup = 136;
int btdown = 312;
int btok = 1;
int datain;
int rpmx;
int jam;
int menit;
float detiks;
int detik;

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

int suhu;
int rpm;
int timer;

int heater = 5;
int pompa = 2;
int motor1 = 6;
int motor2 = 7;


int timerku = 0;


void setup(){
lcd.begin(16,2);
lcd.clear();
lcd.noCursor();
pinMode(13,OUTPUT);
Serial.begin(9600);

pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);

pinMode(heater,OUTPUT);
pinMode(pompa,OUTPUT);
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);

digitalWrite(heater,HIGH);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);
digitalWrite(pompa,HIGH);

}


void loop(){

if (Serial.available() > 0)
{
datain = Serial.parseInt();


if(datain == 2){
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
analogWrite(9,rpmx);
}

if(datain == 3){
timerku = 1;
}


if(datain == 5){
Serial.println(suhu);
Serial.println(rpm);
Serial.println(timer);
}

}

else{

if(timerku == 0){
  lcd.setCursor(0,1);
  lcd.print("Set=");
  lcd.print(suhu);
  lcd.print("/");
  lcd.print(rpm);
  lcd.print("/");
  lcd.print(timer);
}

if(timerku == 1){
  detiks = detiks - 0.5;
  detik = detiks;

 if(detik < 1){
   detiks = 60;
   menit--;
 }

  lcd.setCursor(0,1);
  lcd.print(jam);
  lcd.print(":");
  lcd.print(menit);
  lcd.print(":");
  lcd.print(detik);
  lcd.print("            ");

if((menit < 0)&&(detik < 1)){
lcd.clear();
selesai();
}

}

  if ( !ds.search(addr)) {
    //Serial.println("No more addresses.");
    //Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  //Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    //Serial.write(' ');
    //Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      //Serial.println("CRC is not valid!");
      return;
  }
  //Serial.println();

   //the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      //Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      //Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      //Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      //Serial.println("Device is not a DS18x20 family device.");
      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
  // we might do a ds.depower() here, but the reset will take care of it.

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

  //Serial.print("  Data = ");
  //Serial.print(present, HEX);
  //Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    //Serial.print(data[i], HEX);
    //Serial.print(" ");
  }
  //Serial.print(" CRC=");
  //Serial.print(OneWire::crc8(data, 8), HEX);
  //Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    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
    //// default is 12 bit resolution, 750 ms conversion time
  }

celsius = (float)raw / 16.0;

//untuk lihat data suhu
//Serial.println(celsius);

dataadc = analogRead(A0);

if((celsius > suhu)&&(suhu > 0)) {
digitalWrite(heater,HIGH);
}

if((celsius < suhu)&&(suhu > 0)) {
digitalWrite(heater,LOW);
}

if(dataadc == btset){
delay(200);
lcd.clear();
suhu = 36;
rpm = 50;
timer = 10;

setting1();
setting2();
setting3();
}


lcd.setCursor(0,0);
lcd.print("Suhu= ");
lcd.print(celsius);
lcd.print(" C    ");

}

}

void setting1(){

dataadc = analogRead(A0);

if(dataadc == btup){
delay(200);
suhu++;
}

if(dataadc == btdown){
delay(200);
suhu--;
}

if(suhu < 36){
suhu = 36;
}

if(suhu > 38){
suhu = 38;
}

if(dataadc == btok){
delay(200);
lcd.clear();
return;
}

lcd.setCursor(0,0);
lcd.print("SETTING ");
//lcd.print(dataadc);
//lcd.print("    ");
lcd.setCursor(0,1);
lcd.print("Suhu = ");
lcd.print(suhu);
lcd.print(" C     ");
//lcd.print(dataadc);

setting1();
}

void setting2(){

dataadc = analogRead(A0);

if(dataadc == btup){
delay(200);
rpm = rpm + 25;
}

if(dataadc == btdown){
delay(200);
rpm = rpm - 25;
}

if(rpm < 50){
rpm = 50;
}

if(rpm > 100){
rpm = 100;
}

if(dataadc == btok){
delay(200);
lcd.clear();

if(rpm == 50){
rpmx = 70;
}

if(rpm == 75){
rpmx = 100;
}

if(rpm == 100){
rpmx = 200;
}

return;
}

lcd.setCursor(0,0);
lcd.print("SETTING ");
lcd.setCursor(0,1);
lcd.print("RPM = ");
lcd.print(rpm);
lcd.print("     ");

setting2();
}

void setting3(){

dataadc = analogRead(A0);

if(dataadc == btup){
delay(200);
timer = timer + 5;
}

if(dataadc == btdown){
delay(200);
timer = timer - 5;
}

if(timer < 5){
timer = 5;
}

if(timer > 60){
timer = 60;
}

if(dataadc == btok){
menit = timer;
delay(200);
lcd.clear();
return;
}

lcd.setCursor(0,0);
lcd.print("SETTING ");
lcd.setCursor(0,1);
lcd.print("TIMER = ");
lcd.print(timer);
lcd.print("     ");


setting3();
}




void selesai(){
rpmx = 0;

lcd.setCursor(0,0);
lcd.print("selesai..        ");

digitalWrite(10,LOW);
digitalWrite(11,LOW);
analogWrite(9,rpmx);

digitalWrite(heater,HIGH);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);

if (Serial.available() > 0)
{
datain = Serial.parseInt();

if(datain == 4){
digitalWrite(pompa,LOW);
}

if(datain == 6){
digitalWrite(pompa,HIGH);
}

}

selesai();
}





g. Program VB 6



1. Form1

Option Explicit
Dim arrdata()
Dim TotalBaca As Integer
Dim BMI As Single
Dim Keterangan As String
Const MAKSBACA = 18

Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim Param1 As ADODB.Parameter
Dim Rs1 As ADODB.Recordset

Private Sub berhenti_Click()
  start.Enabled = True
    berhenti.Enabled = False
    TimerBaca.Enabled = False
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Command3_Click()
MSComm2.Output = "2" + Chr(13)
End Sub

Private Sub Command4_Click()
MSComm2.Output = "3" + Chr(13)
End Sub

Private Sub Command5_Click()
MSComm2.Output = "4" + Chr(13)
End Sub

Private Sub Command6_Click()
Dim SQl As String
 
   Call dbConnect
 
    SQl = "INSERT INTO tbsuhu VALUES('" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "','" & Text2(0).Text & "','" & Text2(1).Text & "','" & Text2(2).Text & "')"
 
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic
 
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
 
End Sub

Private Sub Command7_Click()
MSComm2.Output = "5" + Chr(13)
End Sub

Private Sub Command8_Click()
MSComm2.Output = "6" + Chr(13)
End Sub

Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
    ComboCOM.AddItem (i)
Next i

End Sub

Private Sub MSComm2_OnComm()
Dim buffer As String
Dim temp As String
Dim pisah() As String
Dim i As Integer

If MSComm2.CommEvent = comEvReceive Then
    buffer = MSComm2.Input
    pisah = Split(buffer, Chr$(13))
On Error Resume Next
If buffer <> " " Then
With Text1
    .SelStart = Len(.Text)
    .SelText = buffer
End With
For i = 0 To 2
    If 0 < 3 Then
        Text2(i).Text = CStr(pisah(i))
        End If
        Next i
    Else
    buffer = " "
    End If
End If
End Sub

Private Sub start_Click()
Dim u As Integer

    On Error GoTo ada_eror
 
    MSComm2.CommPort = ComboCOM.Text
    MSComm2.Settings = "9600,N,8,1"
    MSComm2.RThreshold = 28
    MSComm2.InputLen = 28
    MSComm2.InputMode = comInputModeText
    MSComm2.PortOpen = True ' buka port
 
    ReDim arrdata(1 To MAKSBACA + 1)
    For u = 1 To MAKSBACA
        arrdata(u) = 0
    Next
    TotalBaca = 0
    start.Enabled = False
    berhenti.Enabled = True
    TimerBaca.Enabled = True
    Timer2.Enabled = True
    Timer3.Enabled = True
ada_eror:
 If ComboCOM.ListIndex < 1 Then
    MsgBox "COM berada di Nomor : " & Err.Number & vbCrLf & Err.Description, vbCritical + vbOKOnly, "ERROR"
    start.Enabled = True
    berhenti.Enabled = True
    ComboCOM.Text = "Pilih COM"
End If

End Sub

Private Sub Timer1_Timer()

End Sub

Private Sub Timer2_Timer()
Adodc1.Refresh
Dim ok As Integer
Dim mode As Integer


End Sub

Private Sub Timer3_Timer()
MSComm2_OnComm
End Sub

Private Sub TimerBaca_Timer()
Dim strInput As String
Dim strPotong As String
Dim singleInput As Single
Dim u As Integer
    strInput = MSComm2.Input
        strPotong = strInput
        If TotalBaca >= MAKSBACA Then
            TimerBaca.Enabled = False
            If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
            Call berhenti_Click
        End If

End Sub


2. Module

Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public SQl As String
Public i As Byte

Public Sub dbConnect()
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConn
Conn.Open
End Sub

Public Function strConn() As String
Set Conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Acer\Desktop\VB Interface SErial ARRAY 6\database\dbsuhu.mdb;Persist Security Info=False"

End Function




h. VIDEO HASLNYA










Membuat Alat Monitor Suhu dan Kelembaban Menggunakan Sensor DHT22 + BASCOM AVR

Membuat Alat Monitor Suhu dan Kelembaban Menggunakan Sensor DHT22 + BASCOM AVR


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitoring suhu dan kelembaban serta timer on off led. alat ini menggunakan sensor DHT22 dan program menggunakan Bascom AVR. alat ini bisa disetting batas suhu dan kelembabannya dengan menggunakan tombol. untuk lebih jelasnya berikut adalah komponen dan programnya.




a. Minimum System ATMega




b. Sensor DHT22




c. LCD 16x2






d. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 12000000

'--------------------------
Config Lcdpin = Pin , Rs = Portc.5 , E = Portc.4 , Db4 = Portc.3
Config Lcdpin = Pin , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0
Config Lcd = 16 * 2
Cursor Off
Cls

Declare Sub Get_th(t As Word , H As Word)

Config Serialin = Buffered , Size = 128
Config Serialout = Buffered , Size = 128

'czujnik podlaczony do PortD.6
Dht_put Alias Porta.0
Dht_get Alias Pina.0
Dht_io_set Alias Ddra.0

Cls
Cursor Off

Dim Crc As Byte                                             'zmienna do przechowywania bajtów parzystosci
Dim Mybyte As Byte                                          'zmienna do obliczania bitu parzystosci
Dim Sensor_data As String * 40                              'tutaj beda zapisywac sie dane z czujnika
Dim Count As Byte
Dim T As Word                                               'zmienna do przechowywania temperatury
Dim H As Word                                               'zmienna do przechowywania wilgotnosci
Dim S16 As String * 16                                      'zmienna do obliczania odebranych bitów
Dim Ti As Byte                                              'zmienna do przechowywania dziesietnej temperatury
Dim Hi As Byte                                              'zmienna do przechowywania dziesietnej wilgotnosci

Enable Interrupts

Dim Cacah As Integer

Dim Nilai As Integer
Dim Nilai2 As Integer
Dim Nilai3 As Integer
Dim Vx As Integer
Dim Mark As Integer
Dim Waktu As Integer

'led
Ddra.7 = 1
Ddra.6 = 1
Ddra.5 = 1

'buzzer
Ddra.4 = 1
Porta.4 = 1

'pushbutton
Ddrd.7 = 0
Ddrd.6 = 0
Ddrd.5 = 0
Ddrd.4 = 0

'Aktif Low Pushbutton
Portd.7 = 1
Portd.6 = 1
Portd.5 = 1
Portd.4 = 1

Pbset Alias Pind.7
Pbdown Alias Pind.6
Pbup Alias Pind.5
Pbok Alias Pind.4

Led1 Alias Porta.7
Led2 Alias Porta.6
Led3 Alias Porta.5

Buzzer Alias Porta.4

Led1 = 0
Led2 = 0
Led3 = 0

Utama:

Do

Led3 = 0

   Dht_io_set = 1
   Dht_put = 1
   Wait 1
   Call Get_th(t , H)

   Upperline
   Lcd "SUHU: " ; T ; " C " ; "/ " ; Nilai ; "     "
   Lowerline
   Lcd "HUMY: " ; H ; " % " ; "/ " ; Nilai2 ; "     "


If Pbset = 0 Then
Buzzer = 0
Waitms 100
Buzzer = 1
Waitms 100
Buzzer = 0
Waitms 100
Buzzer = 1

Cls
Wait 1
Goto Setting1
End If


If Nilai > 0 And T >= Nilai Then
Led1 = 0
End If

If Nilai > 0 And T < Nilai Then
Led1 = 1
End If

If Nilai2 > 0 And H >= Nilai2 Then
Led2 = 0
End If

If Nilai2 > 0 And H < Nilai2 Then
Led2 = 1
End If

If Mark = 1 Then
Incr Cacah
End If

If Waktu > 0 And Cacah = Waktu Then
Cacah = 0
Goto Motor
End If

Loop

Setting1:

Do

Upperline
Lcd "SET BATAS"

Lowerline
Lcd "Suhu= " ; Nilai ; " C    "


If Pbup = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Incr Nilai
End If

If Pbdown = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Decr Nilai
End If

If Nilai > 100 Then
Nilai = 0
End If

If Nilai < 0 Then
Nilai = 100
End If

If Pbok = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Cls
Wait 1
Goto Setting2
End If

Loop

Setting2:

Do

Upperline
Lcd "SET BATAS"

Lowerline
Lcd "Humy= " ; Nilai2 ; " %    "


If Pbup = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Incr Nilai2
End If

If Pbdown = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Decr Nilai2
End If

If Nilai2 > 100 Then
Nilai2 = 0
End If

If Nilai2 < 0 Then
Nilai2 = 100
End If


If Pbok = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Cls
Wait 1
Goto Setting3
End If

Loop

Setting3:

Do

Upperline
Lcd "SET BATAS"

Lowerline
Lcd "Waktu= " ; Nilai3 ; " jam    "


If Pbup = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Incr Nilai3
End If

If Pbdown = 0 Then
Buzzer = 0
Waitms 200
Buzzer = 1
Decr Nilai3
End If

If Nilai3 > 3 Then
Nilai3 = 3
End If

If Nilai3 < 0 Then
Nilai3 = 0
End If

If Pbok = 0 Then
Buzzer = 0
Waitms 100
Buzzer = 1
Waitms 100
Buzzer = 0
Waitms 100
Buzzer = 1

Cls
Wait 1

If Nilai3 = 1 Then
Waktu = 3600
'Waktu = 35
End If


If Nilai3 = 2 Then
Waktu = 7200
'Waktu = 40
End If

If Nilai3 = 3 Then
Waktu = 10800
'Waktu = 45
End If

Mark = 1
Goto Motor

End If

Loop


Motor:

Do

   Dht_io_set = 1
   Dht_put = 1
   Wait 1
   Call Get_th(t , H)

   Upperline
   Lcd "SUHU: " ; T ; " C " ; "/ " ; Nilai ; "     "
   Lowerline
   Lcd "HUMY: " ; H ; " % " ; "/ " ; Nilai2 ; "     "

If Pbset = 0 Then
Buzzer = 0
Waitms 100
Buzzer = 1
Waitms 100
Buzzer = 0
Waitms 100
Buzzer = 1

Cls
Wait 1
Goto Setting1
End If


If Nilai > 0 And T >= Nilai Then
Led1 = 0
End If

If Nilai > 0 And T < Nilai Then
Led1 = 1
End If

If Nilai2 > 0 And H >= Nilai2 Then
Led2 = 0
End If

If Nilai2 > 0 And H < Nilai2 Then
Led2 = 1
End If

Led3 = 1

Incr Cacah
Incr Vx

If Vx = 30 Then
Vx = 0
Goto Utama
End If

Loop


Sub Get_th(t As Word , H As Word)

 Count = 0
 Sensor_data = ""
 Dht_io_set = 1                                             'robimy wyjscie z PD.6
 Dht_put = 0                                                'ustawic magistrale w stan LOW
 Waitms 1                                                   'odczekac co najmniej 18ms

 Dht_put = 1                                                'zwolnic magistrale
 Waitus 20
 Dht_io_set = 0                                             'robimy wejscie z PD.6
 Waitus 40                                                  'odczekaj 40 ms
 If Dht_get = 1 Then                                        'jesli jest jeszcze jeden, ???? ?? ??? ?? ???????? 1
    H = 1                                                   'oznacza ze czujnik nie odpowiedzial
    Exit Sub                                                'konczymy podprogram
 End If

'jesli czujnik odpowiedzial i wyciagnal magistrale do ziemi kontynuujemy prace
  Waitus 80                                                 'czekamy jeszcze 80ms
  If Dht_get = 0 Then                                       'jesli na linii jest nadal 0
    H = 2                                                   'oznacza czujnik zwariowal
    Exit Sub                                                'konczymy podprogram
  End If

'jesli wszystko pójdzie dobrze i czujnik zareagowal prawidlowo, mozemy kontynuowac

  While Dht_get = 1 : Wend                                  'czekamy, az magistrala pokazuje 1

   Do                                                       'zaczynamy przyjmowac 40-bitowe dane
    While Dht_get = 0 : Wend                                'czekamy na ustawienie magistrali w stan 0
    Waitus 30                                               'po wystapieniu stamu 0 czekac 30 ms
     If Dht_get = 1 Then                                    'jesli na szynie 1
       Sensor_data = Sensor_data + "1"                      'zapisujemy do zmiennej ta ?????????? ? ?????????? ??? ???????
       While Dht_get = 1 : Wend                             'i czekamy az nadajnik wysle kolejny bit
       Else                                                 'w przeciwnym razie, jesli tam jest 0
       Sensor_data = Sensor_data + "0"                      'zapisujem je do zmiennej
    End If
    Incr Count                                              'zwiekszamy licznik
   Loop Until Count = 40                                    'Powtarzaj te czynnosc dopóki licznik osiagnie liczbe 40

   Dht_io_set = 1
   Dht_put = 1

'zaczynamy rozkladac otrzymane dane


   S16 = Left(sensor_data , 16)
   H = Binval(s16)
   H = H / 10
   Hi = H Mod 10

   S16 = Mid(sensor_data , 17 , 16)
   T = Binval(s16)
   T = T / 10
   Ti = T Mod 10

   S16 = Right(sensor_data , 8)
   Crc = Binval(s16)
   'test sumy kontrolnej

   Mybyte = T + H                                           'dodajemy wartosci temperatury i wilgotnosci
   If Mybyte <> Crc Then                                    'jesli suma kontrolna sie nie zgadza
      Lcd "error"                                           'Oznacza to, ze dane nie sa poprawne
   End If

End Sub






e. VIDEO HASILNYA