Translate

ARDUINO FREQUENCY COUNTER DAN SENSOR KAPASITIF

ARDUINO FREQUENCY COUNTER DAN SENSOR KAPASITIF


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat berbasis sensor kapasitif dan frequency counter. alat ini menggunakan mikrokontroller Arduino Uno dan IC NE555. alat ini dapat digunakan untuk berbagai macam fungsi. salah satunya yaitu monitor ketinggian air atau bisa juga untuk sensor sentuhan.  



a. Arduino Uno




b. Rangkaian Sensor Kapasitf IC NE555




c. LCD 16x2 + I2C






d. Program Arduino IDE

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

int Htime;              //integer for storing high time
int Ltime;                //integer for storing low time
float period;            // integer for storing total time of a cycle
float frequency;        //storing frequency
float kapasitansi;
float kapasitansi2;

void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(8,INPUT);
  Serial.begin(9600);
}

void loop()
{
  
    Htime=pulseIn(8,HIGH);      //read high time
    Ltime=pulseIn(8,LOW);        //read low time
    
    period = Htime+Ltime;
    kapasitansi = period / 34.650;
    
    frequency=1000000/period;    //getting frequency with Ttime is in Micro seconds

    lcd.setCursor(0,0);
    lcd.print("C= ");
    lcd.print(kapasitansi);
    lcd.print("      ");
    lcd.setCursor(0,1);
    lcd.print("F= ");
    lcd.print(frequency);
    lcd.print("      ");
    
    Serial.println(kapasitansi);
    
    delay(1000);
}





e. Program Interface VB 6.0


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

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()
Text1.Text = " "
Label1.Caption = " "

End Sub

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

 aHari = Array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu")

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 = 15
    MSComm2.InputLen = 15
    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
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()
 sHari = aHari(Abs(Weekday(Date) - 1))
 lbltanggal.Caption = "" & sHari & "," & Format(Date, "dd mmmm yyyy")
 lbljam.Caption = Format(Time, "hh:mm:ss")

Open "C:\Users\Acer\Desktop\monitor ketinggian air kapasitance\VB Interface SErial" & "\record.txt" For Append As #1
Print #1, "======================"
Print #1, " Data dalam satu menit "
Print #1, "======================"
Print #1, "Tanggal = "; lbltanggal.Caption
Print #1, "  Jam   = "; lbljam.Caption
Print #1, " NIlai  = "; Label1.Caption
Print #1,
Close #1

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
        Text1.Text = Text1.Text + strPotong + vbCrLf
        singleInput = Val(strPotong)
        Label1.Caption = singleInput
        If TotalBaca >= MAKSBACA Then
            TimerBaca.Enabled = False
            If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
            Call berhenti_Click
        End If
  
End Sub




f. VIDEO HASILNYA








No comments:

Post a Comment