Video Demo
Skema rangkaian
List Program (Arduino)// Program Deteksi getar dengan Piezoelectric // Oleh : Aan Darmawan // valfa.blogspot.com // maret 2011 /* Keterangan skema: * Sambungkan Output Piezo ke pin A0 (Analog input pin 0) Arduino * Pin 8 output ke relay , jika nilai getaran mencapai 800, Relay ON */ // deklarasi variabel int mgetar; int getarPin = 0; void setup() { pinMode(8,OUTPUT); // aktifkan serial port Serial.begin(9600); } void loop() { // baca getaran dari A0 mgetar =analogRead(getarPin); //kirim ke serial Serial.println(mgetar); if(mgetar>=800) //jika getaran cukup keras { digitalWrite(8,HIGH); // aktifkan relay delay(2000); // delay 2 detik } else digitalWrite(8,LOW); delay(30); // berhenti beberapa milidetik }
List Program Visual Basic 6
Public x1, y1, x2, y2 As Integer Private Sub Command1_Click() If Command1.Caption = "START" Then MSComm1.PortOpen = True Timer1.Enabled = True Command1.Caption = "STOP" Else MSComm1.PortOpen = False Timer1.Enabled = False Command1.Caption = "START" End If End Sub Private Sub Form_Load() Timer1.Enabled = False
Timer1.Interval = 30 x1 = 2 y1 = 450 x2 = 2 y2 = 450 End Sub Private Sub Form_Paint() Form1.DrawWidth = 2 Form1.PSet (x1, y1), RGB(255, 0, 0) Form1.Line (1, 70)-(1, 452), RGB(255, 0, 0) Form1.Line (1, 452)-(620, 452), RGB(255, 0, 0) For i = 6 To 616 Step 10 Form1.Line (i, 450)-(i, 455), RGB(255, 0, 0) Next i For i = 452 To 72 Step -10 Form1.Line (0, i)-(5, i), RGB(255, 0, 0) Next i Form1.PSet (x1, y1), RGB(0, 0, 255) End Sub Private Sub Timer1_Timer() hasil = MSComm1.Input If Len(hasil) > 0 Then n = Val(hasil) If n > 50 Then n = n / 2.273 Else If n > 5 Then n = n * 2 Text1.Text = n y2 = 450 - n If y2 <= 186 Then y2 = 186 Form1.Line (x1, y1)-(x2, y2), RGB(255, 0, 0) Else Form1.Line (x1, y1)-(x2, y2), RGB(0, 0, 255) End If x1 = x2 y1 = y2 x2 = x2 + 1 If x2 >= 620 Then x1 = 2 x2 = 2 Form1.Cls Form1.PSet (x1, y1), RGB(255, 0, 0) Form1.Line (1, 70)-(1, 452), RGB(255, 0, 0) Form1.Line (1, 452)-(620, 452), RGB(255, 0, 0) For i = 6 To 616 Step 10 Form1.Line (i, 450)-(i, 455), RGB(255, 0, 0) Next i For i = 452 To 72 Step -10 Form1.Line (0, i)-(5, i), RGB(255, 0, 0) Next i Form1.PSet (x1, y1), RGB(0, 0, 255) End If End If End Sub