Translate

Membuat Alat Monitor Kelembaban Tanah (soil Moisture) dan kendali Pompa via WIFI ethernet shield ARDUINO

Membuat Alat Monitor Kelembaban Tanah (soil Moisture) dan kendali Pompa via WIFI ethernet shield ARDUINO


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor kelembaban tanah atau intensitas air didalam tanah sehingga bisa diketahui apakah tanah tersebut subur ataukah tidak, alat ini menggunakan sensor soil moisture dan bisa dikendalikan manual menggunakan wifi. terdapat pompa yang akan menyala saat terdeteksi tanah tersebut kering. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino dan Ethernet Shield

   


b. Router 




c. Sensor Soil Moisture




d. relay Modul






e. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library

LiquidCrystal_I2C lcd(0x27, 16, 2);

String txData="";
int mark = 0;
int counter;

int dryValue = 1023;
int wetValue = 0;
int friendlyDryValue = 0;
int friendlyWetValue = 100;



byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);

EthernetServer server(80);
String readString;
int buzzerp = 7;
int buzzerm = 9;
int vin;
int relay = 2;
float tegangan;
int x = 1;
int rawValue;

void setup() {
pinMode(buzzerp,OUTPUT);
pinMode(buzzerm,OUTPUT);
pinMode(relay,OUTPUT);
digitalWrite(buzzerp,LOW);
digitalWrite(buzzerm,LOW);
lcd.begin();
lcd.clear();
lcd.noCursor();

  Serial.begin(9600);
   while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());


  Serial.begin(9600);
   while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

}

void loop()
{

 rawValue = analogRead(A3);           

 int tegangan = map(rawValue, dryValue, wetValue, friendlyDryValue, friendlyWetValue);

  lcd.setCursor(0, 0);
  lcd.print("S= ");
  lcd.print(tegangan);
  lcd.print(" %      ");
 
  if(x == 1){
  lcd.setCursor(0, 1);
  lcd.print("MANUAL    ");
  }
  if(x == 2){
  lcd.setCursor(0, 1);
  lcd.print("OTOMATIS ");
  }
  if((tegangan > 0)&&(x == 2)){
  digitalWrite(relay,LOW);
  digitalWrite(buzzerp,HIGH);
  digitalWrite(buzzerm,LOW);
  }
  if((tegangan <= 0)&&(x == 2)){
  digitalWrite(relay,HIGH);
  digitalWrite(buzzerp,LOW);
  digitalWrite(buzzerm,LOW);
  }
 
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
     if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 1");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Soil Moisture </title> ");    
          client.println("<body bgcolor = #000000>");    
          client.println("<center>");
            client.println("<font color = yellow><center><h1>Soil Moisture Monitor</h1></center><br></font>");
            client.println("<font color = #FFFFFF>");
           
              if(x == 1){
                client.println("<center>");
                client.println("<h2>");
                client.println("MANUAL");
                client.println("</h2>");
                client.println("</center>");
                client.println("<br>");
              }
               if(x == 2){
                client.println("<center>");
                client.println("<h2>");
                client.println("OTOMATIS");
                client.println("</h2>");
                client.println("</center>");
                client.println("<br>");
              }
           
            client.println("<h2>");
            client.println("S= ");
            client.print(tegangan);
            client.println(" % ");
            client.println("<br>");                
            client.println("</h2>");    
            client.println("<a href = \"/?lighton\"\"><input type = 'button' value = ' POMPA ON' ></a>");
          client.println("<a href = \"/?lightoff\"\"><input type = 'button' value = 'POMPA OFF' ></a> "); 
               client.println("<a href = \"/?lighton1\"\"><input type = 'button' value = ' MANUAL' ></a>");
          client.println("<a href = \"/?lightoff1\"\"><input type = 'button' value = 'OTOMATIS' ></a> ");
          client.println("</font>");
          client.println("</center>");
          client.println("</body>");
          client.println("</html>");
           
          break;      
        }   
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
    Serial.println("client disonnected");
  }

  if((readString.indexOf("?lighton") >0)&&(x == 1))
          {
            digitalWrite(relay,LOW);  
          }
          else{
          if((readString.indexOf("?lightoff") >0)&&(x == 1))
          {

            digitalWrite(relay,HIGH);
          }
          }

if(readString.indexOf("?lighton1") >0)
          {
            x = 1;
          }
          else{
          if(readString.indexOf("?lightoff1") >0)
          {
            x = 2;
          }
          }
         readString="";

delay(200);

}





f. VIDEO HASILNYA










Membuat Alat Monitor Suhu dan Kelembaban Menggunakan DHT11 dan Arduino Datalogger VB 6 dan database MS ACCESS

Membuat Alat Monitor Suhu dan Kelembaban Menggunakan DHT11 dan Arduino Datalogger VB 6 dan database MS ACCESS


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitor suhu dan kelembaban dengan disertai datalogger yang berupa interface VB 6 dan database menggunakan ms. access, alat ini menggunakan output relay sebagai aktuatornya untuk kendali kipas, untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. Sensor DHT11




c. Lcd 16x2 I2C




d. Modul Relay






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h> 
#include "DHT.h"
LiquidCrystal_I2C lcd(0x3F, 16, 2);

int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5; //full speed
int t1;
int h1;
int t2;
int h2;

int ledm1 = 8;
int ledb1 = 9;
int ledm2 = 10;
int ledk2 = 11;
int ledh2 = 12;
int ledb2 = 13;
int tombol = A0;
int mark;
int mode;
int tombolx;

void setup() {
  Serial.begin(9600); 
  pinMode(ledm1,OUTPUT);
  pinMode(ledb1,OUTPUT);
  pinMode(ledm2,OUTPUT);
  pinMode(ledk2,OUTPUT);
  pinMode(ledh2,OUTPUT);
  pinMode(ledb2,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);
  
  pinMode(relay1,OUTPUT);
  pinMode(relay2,OUTPUT);
  pinMode(relay3,OUTPUT);
  pinMode(relay4,OUTPUT);
 
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
 
  lcd.begin();
  lcd.noCursor();
  lcd.clear();
 
}

void loop() {
 tombolx = digitalRead(tombol);
if((tombolx == 0)&&(mark == 0)){
mode = 1;
tombolx = 1;
mark = 1;
}     

satu();

 tombolx = digitalRead(tombol);
if((tombolx == 0)&&(mark == 1)){
mode = 2;
tombolx = 1;
mark = 0;
}

dua();
lcd.setCursor(0,0);
lcd.print("H/T1:");
lcd.print(h1);
lcd.print("/");
lcd.print(t1);

lcd.setCursor(0,1);
lcd.print("H/T2:");
lcd.print(h2);
lcd.print("/");
lcd.print(t2);

Serial.println(t1);
Serial.println(h1);
Serial.println(t2);
Serial.println(h2);
Serial.println(mode);


if (mode == 1){
lcd.setCursor(11,0);
lcd.print("SMPN");



if(h1 > 62){
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,LOW); 
digitalWrite(ledb1,LOW); 
digitalWrite(ledm2,HIGH); 
digitalWrite(ledk2,LOW); 
digitalWrite(ledh2,LOW); 
digitalWrite(ledb2,LOW); 
}

if((h1 > 60)&&(h1 < 62)){
  digitalWrite(relay1,LOW);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,LOW); 
digitalWrite(ledb1,LOW); 
digitalWrite(ledm2,LOW); 
digitalWrite(ledk2,LOW); 
digitalWrite(ledh2,LOW); 
digitalWrite(ledb2,HIGH);
}

if((h1 > 55)&&(h1 < 60)){
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,LOW);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,LOW); 
digitalWrite(ledb1,LOW); 
digitalWrite(ledm2,LOW); 
digitalWrite(ledk2,LOW); 
digitalWrite(ledh2,HIGH); 
digitalWrite(ledb2,LOW);
}

if(h1 < 55){
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,LOW);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,LOW); 
digitalWrite(ledb1,LOW); 
digitalWrite(ledm2,LOW); 
digitalWrite(ledk2,HIGH); 
digitalWrite(ledh2,LOW); 
digitalWrite(ledb2,LOW); 
}
}



if (mode == 2){
lcd.setCursor(11,0);
lcd.print("KRNG");


if(h1 >= 70){
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,HIGH); 
digitalWrite(ledb1,LOW); 
digitalWrite(ledm2,LOW); 
digitalWrite(ledk2,LOW); 
digitalWrite(ledh2,LOW); 
digitalWrite(ledb2,LOW); 
}
if(h1 < 70){
  digitalWrite(relay1,HIGH);
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
digitalWrite(ledm1,LOW); 
digitalWrite(ledb1,HIGH); 
digitalWrite(ledm2,LOW); 
digitalWrite(ledk2,LOW); 
digitalWrite(ledh2,LOW); 
digitalWrite(ledb2,LOW); 
}

}



}


void satu(){
  #define DHTPIN 6
  #define DHTTYPE DHT11  
  DHT dht(DHTPIN, DHTTYPE);
  dht.begin();
  delay(1000);

   h1 = dht.readHumidity();
   t1 = dht.readTemperature();

}


void dua(){
  #define DHTPIN 7
  #define DHTTYPE DHT11  
  DHT dht(DHTPIN, DHTTYPE);
  dht.begin();
  delay(1000);

   h2 = dht.readHumidity();
   t2 = dht.readTemperature();

}






 f. Program Interface VB 6 


  
1. 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\yanuar\Desktop\vbku\database\dbsuhu.mdb;Persist Security Info=False"

End Function



2. Form

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

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 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 4
    If 0 < 5 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 = 17
    MSComm2.InputLen = 17
    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
    Timer1.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()
Dim SQl As String
   
   Call dbConnect
   
    SQl = "INSERT INTO tbsuhu VALUES('" & Text2(1).Text & "','" & Text2(3).Text & "','" & Text2(0).Text & "','" & Text2(2).Text & "','" & Text4.Text & "','" & Label4.Caption & "')"
   
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic

End Sub

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

ok = Val(Text2(1).Text)
mode = Val(Text2(4).Text)

If mode = 1 Then
Text5.Text = "SIMPAN"
End If

If mode = 2 Then
Text5.Text = "KERING"
End If


If ok > 63 And mode = 1 Then
Text4.Text = "OFF"
End If
If ok <= 63 And mode = 1 Then
Text4.Text = "ON"
End If

If ok > 70 And mode = 2 Then
Text4.Text = "OFF"
End If
If ok <= 70 And mode = 2 Then
Text4.Text = "ON"
End If

End Sub

Private Sub Timer3_Timer()
MSComm2_OnComm
End Sub

Private Sub Timer4_Timer()
 Label4.Caption = Format(Time, "hh:mm:ss")
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





g. VIDEO HASILNYA










Membuat Alat Deteksi Kecepatan Menggunakan Sensor Ultrasonic HC-SRF04 dan PIR ARDUINO Komunikasi wireless NRF24L01

Membuat Alat Deteksi Kecepatan Menggunakan Sensor Ultrasonic HC-SRF04 dan PIR ARDUINO Komunikasi wireless NRF24L01


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sensor ultrasonik sebagai deteksi kecepatan laju benda bergerak, jadi alat ini dilengkapi juga dengan sensor PIR yang berfungsi untuk mendeteksi apakah yang bergerak manusia atau bukan, jika manusia maka akan dimulai counter untuk deteksi kecepatannya namun jika tidak maka tidak akan dilakukan counter, ada dua sensor jarak difungsikan untuk awal counter dan akhir counter, setelah nilai counter didapat maka dikirimkan ke receiver menggunakan modul wireless NRF24L01. untuk lebih jelasnya berikut adalah skema dan programnya.



 a. Arduino Uno




b. Sensor Jarak HC-SRF04




c. LCD 16x2 I2C




d. Sensor PIR 




e. Modul NRF24L01






f. Program Arduino Uno

1. Master

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define trigPin1 2
#define echoPin1 3
#define trigPin2 4
#define echoPin2 5

  long duration1, distance1;
  long duration2, distance2;
  int dataadc, counter, mark;

RF24 radio(9, 10); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  digitalWrite(13,LOW);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  }

 void loop() {

  dataadc = analogRead(A0);

  digitalWrite(trigPin1, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin1, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;
  Serial.print(distance1);
  Serial.print (" cm   ");

  digitalWrite(trigPin2, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin2, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
  Serial.print(distance2);
  Serial.print(" cm   ");
  Serial.println(dataadc);
  delay(200);

  if((distance1 < 10)&&(dataadc > 1000)){
  mark = 1;
  }
 
  if((distance2 < 10)&&(dataadc > 1000)){
  mark = 0;
  Serial.print(" speed= ");
  Serial.println(counter);
  /*
  if(counter <= 10){
  const char text[] = "kec > 13 m/s";
  radio.write(&text, sizeof(text));
  delay(1000);
  }
  */
  if((counter > 10)&&(counter <= 30)){
  const char text[] = "Ada Penyu";
  radio.write(&text, sizeof(text));
  delay(1000);
  }
  /*
  if(counter > 30){
  const char text[] = "kec < 6 m/s";
  radio.write(&text, sizeof(text));
  delay(1000);
  }
  */
  counter = 0;
  }
 
  if(mark == 1){
  counter++;
  }

}
 



2. Slave

#include <Wire.h>  // i2C Conection Library
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

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

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";

int buzp = 4;
int buzm = 7;


void setup(){
  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  pinMode(buzp,OUTPUT);
  pinMode(buzm,OUTPUT);
   digitalWrite(buzp,LOW);
    digitalWrite(buzm,LOW);
 
}


void loop(){
    lcd.setCursor(0,0);
    lcd.print("TEST ARDUINO");
   
    if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    //Serial.println(text);
    lcd.setCursor(0,1);
    lcd.print(text);
   
    digitalWrite(buzp,HIGH);
    digitalWrite(buzm,LOW);
   
  }

}





g. VIDEO HASILNYA








Membuat kalkulator Digital (Digital Kalkulator) Menggunakan ARDUINO dan KEYPAD Matrix 4x4

Membuat kalkulator Digital (Digital Kalkulator) Menggunakan ARDUINO dan KEYPAD Matrix 4x4


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk menghitung baik itu menjumlah, mengurangi dan perhitungan yang lainnya seperti perkalian dan pembagian, alat ini menggunakan mikrokontroller Arduino dan input keypad matrix 4x4, untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. Keypad Matrix 4x4




c. LCD 16x2 I2C






d. Program Arduino IDE

#include "Wire.h"
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);

long first = 0;
long second = 0;
double total = 0;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'/', 'C', '-', '+'},
{'=', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
};

byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

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


void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
 
}

void loop()
{
 
   digitalWrite(10,HIGH);
   digitalWrite(10,HIGH);
   digitalWrite(10,HIGH);
   digitalWrite(10,HIGH);
  
  customKey = customKeypad.getKey();
  switch(customKey)
  {
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,0);
    first = first * 10 + (customKey - '0');
    lcd.print(first);
    break;

  case '+':
    first = (total != 0 ? total : first);
    lcd.setCursor(3,0);
    lcd.print("+");
    second = SecondNumber(); // get the collected the second number
    total = first + second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0; // reset values back to zero for next use
    break;

  case '-':
    first = (total != 0 ? total : first);
    lcd.setCursor(3,0);
    lcd.print("-");
    second = SecondNumber();
    total = first - second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0;
    break;

  case '*':
    first = (total != 0 ? total : first);
    lcd.setCursor(3,0);
    lcd.print("*");
    second = SecondNumber();
    total = first * second;
    lcd.setCursor(0,3);
    lcd.print(total);
    first = 0, second = 0;
    break;

  case '/':
    first = (total != 0 ? total : first);
    lcd.setCursor(3,0);
    lcd.print("/");
    second = SecondNumber();
    lcd.setCursor(0,3);

    second == 0 ? lcd.print("Invalid") : total = (float)first / (float)second;

    lcd.print(total);
    first = 0, second = 0;
    break;

  case 'C':
    total = 0;
    lcd.clear();
    break;
  }
}

long SecondNumber()
{
  while( 1 )
  {
    customKey = customKeypad.getKey();
    if(customKey >= '0' && customKey <= '9')
    {
      second = second * 10 + (customKey - '0');
      lcd.setCursor(5,0);
      lcd.print(second);
    }

    if(customKey == '=') break;  //return second;
  }
 return second;
}






 e. VIDEO HASILNYA