Kawalan Servo, LED, Buzzer dengan aplikasi vb6.
(A) Keperluan Peralatan dan Perisian :-
- 1 unit Arduino Uno
- 1 unit Led
- 6 wayar jumper
- 1 unit Buzzer
- 1 unit Servo
- Perisian Microsoft VB6
- Perisian Arduino IDE
(B) Dilampirkan aturcara Arduino IDE :-
#define echoPin 7 // Echo Pin
#include
Servo myservo;
int pos=0;
int led = 13;
int peizoPin = 8;
String incoming;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);// Penggunaan LED
pinMode(echoPin, INPUT);// Penggunaan Servo
myservo.attach(9);
}
void loop()
{
if(Serial.available() > 0)
{
incoming = Serial.readString();
if(incoming == "Led ON")
{
// turn LED on:
digitalWrite(led, HIGH);
{myservo.write(140);
}
Serial.println("LED is ON....");
tone(peizoPin,2000);
delay(200);
tone(peizoPin,1000);
delay(200);
noTone(peizoPin);
}
else if(incoming == "Led OFF")
{
// turn LED off:
digitalWrite(led, LOW);
Serial.println("LED turning OFF.......");
tone(peizoPin,1000);
{myservo.write(4);}
delay(200);
noTone(peizoPin);
}
}
}
(C)Antaramuka Kawalan Projek :-
(i) VB6.
(ii) Rekabentuk pemasangan (breadboard).
(D) Kod aturcara Microsoft VB6 seperti berikut :-
Dim onn As String, off As String
Private Sub cmdconnect_Click()
ArduinoUno.RThreshold = 3
ArduinoUno.Settings = "9600,n,8,1"
ArduinoUno.PortOpen = True
ArduinoUno.DTREnable = False
Text1.Text = ""
Shape1.FillColor = vbRed
cmdconnect.Caption = "Port Opened!"
cmdconnect.Enabled = False
cmdon.Enabled = True
cmdexit.Enabled = True
cmdoff.Enabled = False
End Sub
Private Sub cmdexit_Click()
off = "Led OFF"
ArduinoUno.Output = off
'ArduinoUno.PortOpen = False
End
End Sub
Private Sub cmdoff_Click()
off = "Led OFF"
ArduinoUno.Output = off
Shape1.FillColor = vbRed
ReceivedData 'call function retrieve data from arduino
cmdon.Enabled = True
cmdoff.Enabled = False
End Sub
Private Sub cmdon_Click()
onn = "Led ON"
ArduinoUno.Output = onn
Shape1.FillColor = vbGreen
ReceivedData 'call function retrieve data from arduino
cmdon.Enabled = False
cmdoff.Enabled = True
End Sub
Sub RetrieveDataOLD()
Dim strInput As String
Text1.Text = ""
strInput = Text1.Text
With ArduinoUno
'test for incoming event
Select Case .CommEvent
Case comEvReceive
'display incoming event data to displaying textbox
strInput = .Input
Dim str As Variant
str = Split(strInput, "|")
Text1.SelText = str(0)
End Select
End With
tmrReceivedData.Enabled = False
End Sub
Private Sub Command1_Click()
tmrReceivedData.Enabled = True
RetrieveDataOLD
End Sub
Sub ReceivedData()
tmrReceivedData_Timer
End Sub
Sub tmrReceivedData_Timer()
tmrReceivedData.Enabled = True
RetrieveDataOLD
End Sub
*Sebarang cadangan atau penambahbaikan boleh berhubung dengan email ini multipeace@gmail.com