Pertamini Air Pembayaran Pakai Kode Token
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengisi air dengan menggunakan kode token, jadi alat ini seperti halnya pertamini yang mana bukan bensin yang dialirkan melainkan air sehingga client atau pembeli harus membeli kode token dulu seperti halnya listrik PLN yang menggunakan kode token. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Skema
b. Program Arduino IDE
#include <Wire.h>
#include <SPI.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2
int relay = 11;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
long passwd = 0;
long isiku;
long beli;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,8,9,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;
long totalMilliLitres;
long totalLitres;
unsigned long oldTime;
long dataku = 0;
unsigned long saldo;
int mark,mark1,mark2;
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);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
Serial.begin(9600); // Initiate a serial communication
}
void loop()
{
lcd.setCursor(0,1);
lcd.print("Token: ");
lcd.print(saldo);
lcd.print(" L ");
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;
totalLitres = totalMilliLitres / 1000;
frac = (flowRate - int(flowRate)) * 10;
// Print the cumulative total of litres flowed since starting
lcd.setCursor(0,0);
lcd.print("Pakai: "); // Output separator
lcd.print(totalLitres);
lcd.print(" L ");
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
if(totalLitres >= saldo){
digitalWrite(relay, HIGH); //off
saldo = 0;
}
if(totalLitres < saldo){
digitalWrite(relay, LOW); //on
}
}
customKey = customKeypad.getKey();
if(customKey == '*'){
lcd.clear();
delay(1000);
beli = 0;
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
totalLitres = 0;
oldTime = 0;
token();
}
delay(200);
}
void token(){
lcd.setCursor(0,0);
lcd.print("Kode Token");
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();
beli = 0;
}
if(customKey == '#'){
lcd.clear();
delay(1000);
if((beli == 12345)&&(mark == 0)){
saldo = 10;
mark = 1;
return;
}
if((beli == 12234)&&(mark1 == 0)){
saldo = 7;
mark1 = 1;
return;
}
if((beli == 54321)&&(mark2 == 0)){
saldo = 5;
mark2 = 1;
return;
}
beli = 0;
return;
}
token();
}
void pulseCounter()
{
pulseCount++;
}
c. VIDEO HASILNYA
No comments:
Post a Comment