Translate

Alat Hitung Butiran Input Keypad ARduino Sensor IR Proximity

Alat Hitung Butiran Input Keypad ARduino Sensor IR Proximity


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghitung butiran misal butiran obat sehingga tak perlu hitung manual. alat ini dibekaki dengan sensor proximity dan arduino nano dengan input keypad 4x4. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema 



2. Program Arduino IDE

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char customKey;
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] = {2,3,4,5};
byte colPins[COLS] = {6,7,8,9};
long angka;

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int in1 = 11;
int in2 = 12;
int counter;
int x;

void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  pinMode(10,INPUT);
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
}

void loop()
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

lcd.setCursor(0,0);
lcd.print("Input Butiran?");
lcd.setCursor(0,1);
lcd.print("Vol: ");  

  customKey = customKeypad.getKey();
  if(customKey >= '0' && customKey <= '9')
    {
      angka = angka * 10 + (customKey - '0');
      lcd.print(angka);
      lcd.print("  ");
    }

   if(customKey == 'A'){         
      lcd.clear();
      delay(1000);
      counter = 0;
      mulai(); 
    }

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

void mulai(){

lcd.setCursor(0,1);
lcd.print("Target: ");
lcd.print(angka);
lcd.print(" butir ");

analogWrite(in1,120);
analogWrite(in2,0);

x = digitalRead(10); 

if(x == 0){
counter++;  
}

if(counter >= angka){
analogWrite(in1,0);
analogWrite(in2,0);
delay(200);  
analogWrite(in1,0);
analogWrite(in2,130);
delay(300);
lcd.clear();
return;  
}

lcd.setCursor(0,0);
lcd.print("Vol: ");
lcd.print(counter);
lcd.print("  ");
    
customKey = customKeypad.getKey();

 if(customKey == 'B'){         
   lcd.clear();
   delay(1000);
   return;
 } 

delay(1);       
mulai();  
}



3. VIDEO HASILNYA


No comments:

Post a Comment