Translate

Membuat Alat Prabayar Air Isi Ulang Otomatis Berbasis RFID RC-522 Water Flow Sensor

Membuat Alat Prabayar Air Isi Ulang Otomatis Berbasis RFID RC-522 Water Flow Sensor


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat untuk topup air isi ulang menggunakan RFID, jadi seperti halnya pulsa sms yang menggunakan kartu untuk pengisian kuotanya. Alat dilengkapi dengan sensor water flow untuk menghitung debit air yang terpakai jika debit air yang mengalir sudah sama seperti kuota yang dibeli maka solenoid valve akan menutup namun jika masih ada saldo atau kuotanya maka solenoid akan hidup yang artinya air bisa mengalir. untuk lebih jelasnya berikut adalah skema dan hasilnya. 




a. Arduino Uno




b. RFID RC522




c. LCD 16x2 + I2C




d. Modul Relay 1 Channel




e. Solenoid Valve






f. Program Arduino Ide

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

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int buzzer = 3;
int relay = 4;

int putaran = 0;

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;
float totalMilliLitres;

unsigned long oldTime;

 int sisa;
 int saldo;
int aa;
int bb;
int cc;

byte sensorInterrupt1 = 1;  // 1 = digital pin 3
byte sensorPin1       = 2;

float calibrationFactor1 = 4.5;

volatile byte pulseCount1;

unsigned int frac1;
float flowRate1;
unsigned int flowMilliLitres1;
float totalMilliLitres1;

unsigned long oldTime1;

void setup()
{
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW);
  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);
 
  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("Dekatkan 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) == "B3 96 7A 89")&&(aa == 0))
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("ISI 1000 lt     ");
      delay(3000);
      lcd.clear();
      saldo = 1000;
      aa = 1;
      mulai();
  }

 if ((content.substring(1) == "86 B2 99 21")&&(bb == 0))
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("ISI 3000 lt     ");
      delay(3000);
      lcd.clear();
      saldo = 3000;
      bb = 1;
      mulai();
  }

   if ((content.substring(1) == "C7 25 B3 73")&&(cc == 0))
  {
     digitalWrite(buzzer,HIGH);
     delay(200);
     digitalWrite(buzzer,LOW);

      lcd.setCursor(0,0);
      lcd.print("ID=");
      lcd.print(content.substring(1));
      lcd.setCursor(0,1);
      lcd.print("ISI 5000 lt     ");
      delay(3000);
      lcd.clear();
      saldo = 5000;
      cc = 1;
      mulai();
  }

 
}


void mulai(){
 
    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
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate));  // Print the integer part of the variable
    Serial.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (flowRate - int(flowRate)) * 10;
    Serial.print(frac, DEC) ;      // Print the fractional part of the variable
    Serial.print("L/min");
    // Print the number of litres flowed in this second
    Serial.print("  Current Liquid Flowing: ");             // Output separator
    Serial.print(flowMilliLitres);
    Serial.print("mL/Sec");

    saldo = saldo - flowMilliLitres;

    if(saldo < 0){
      saldo = 0;
      }
     
    lcd.setCursor(0,0);
    lcd.print("Flow=");
    lcd.print(flowMilliLitres);
    lcd.print("mL/Sec        ");   
    lcd.setCursor(0,1);
    lcd.print("Sisa=");
    lcd.print(saldo);
    lcd.print("mL/Sec        ");

    // Print the cumulative total of litres flowed since starting
    Serial.print("  Output Liquid Quantity: ");             // Output separator
    Serial.print(totalMilliLitres);
    Serial.println("mL");

    // 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);

delay(100);


if(saldo > 0){
  digitalWrite(relay,LOW);
  }

if(saldo == 0){
  digitalWrite(relay,HIGH);
  lcd.clear();
  lcd.setCursor(0,0);    
  lcd.print("KUOTA HABIS              "); 
  delay(3000);
  return;
}


  mulai();
}


void pulseCounter()
{
  pulseCount++;
}




g. VIDEO HASILNYA








No comments:

Post a Comment