0% found this document useful (0 votes)
22 views10 pages

Arduino and Visual Basic Serial Control

This document contains code for an Arduino program and a Visual Basic program that communicate with each other via a serial port. The Arduino code defines variables and functions for controlling stepper motor pins, reading serial input, and moving the motor right or left. The Visual Basic code defines a form with buttons to send motor movement commands via the serial port to the Arduino. A timer is used to periodically send the motor position back from the Arduino to the Visual Basic program.

Uploaded by

Hennesey Lourice
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

Arduino and Visual Basic Serial Control

This document contains code for an Arduino program and a Visual Basic program that communicate with each other via a serial port. The Arduino code defines variables and functions for controlling stepper motor pins, reading serial input, and moving the motor right or left. The Visual Basic code defines a form with buttons to send motor movement commands via the serial port to the Arduino. A timer is used to periodically send the motor position back from the Arduino to the Visual Basic program.

Uploaded by

Hennesey Lourice
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

A.

ARDUINO PROGRAM

String y;
int x, a, b, c, e;
int z;
boolean f = false;
boolean g = true;
void setup() {
[Link](9600);
pinMode (2, OUTPUT); //DIR
pinMode (3, OUTPUT); //STEP
pinMode (4, OUTPUT); //MS3
pinMode (5, OUTPUT); //MS2
pinMode (6, OUTPUT); //MS1
pinMode (7, OUTPUT); // ENABLE
pinMode(13, OUTPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
A:
if ( f == false) {
for (e = 0; e <= 650; e++) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if ( digitalRead(12) == 0)
{
f = true;
digitalWrite(13, HIGH);
goto A;
}
}
for (e = 0; e <= 1300; e++) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if ( digitalRead(12) == 0)
{
f = true;
digitalWrite(13, HIGH);
goto A;
}
}
for (e = 0; e <= 1950; e++) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if ( digitalRead(12) == 0)
{
f = true;
digitalWrite(13, HIGH);
goto A;
}
}
for (e = 0; e <= 2600; e++) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if ( digitalRead(12) == 0)
{
f = true;
digitalWrite(13, HIGH);
goto A;
}
}
}
}
void loop() {
if ([Link]() > 0) {
y = [Link]();
delay(100);
a = [Link]();
if (g == true) {
if (b < a) {
c = a - b;
right();
}
else if (b > a) {
c = b - a;
left();
}
b = a;
}
}
}
void right() {
g = false;
for (x = 1; x <= c; x++) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if (digitalRead(11) == 0) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(13, LOW);
z = 5;
[Link](z);
g = true;
return;
}
}
z = 5;
[Link](z);
g = true;
return;
}
void left() {
g = false;
for (x = c; x >= 1; x--) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, LOW);
delayMicroseconds(500);
if (digitalRead(12) == 0) {
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(3, HIGH);
delayMicroseconds(500);
digitalWrite(13, HIGH);
z = 5;
[Link](z);
g = true;
return;
}
}
z = 5;
[Link](z);
g = true;
return;
}
A. VISUAL BASIC PROGRAM

Public Class Form1 [Link] = True


Dim x As String x=0
Dim y As String [Link]()
Dim z As String = 0 [Link](x)
Private Sub Form1_Load(sender As [Link]()
[Link], e As [Link]) '[Link] = False
Handles [Link] '[Link] = False
Try '[Link] = False
[Link] = 9600 '[Link] = False
[Link] = 8
[Link] = Catch ex As Exception
[Link]
[Link] = End Try
[Link] [Link] = New Point(59, 35)
Dim ports As String() = End Sub
[Link]()
Dim port As String Private Sub Button2_Click(sender As
For Each port In ports [Link], e As [Link])
[Link] = port Handles [Link]
[Link] = port Try
Next port [Link] = True
Catch ex As Exception x = 650
End Try [Link]()
End Sub [Link](x)
[Link]()
Private Sub Button1_Click(sender As '[Link] = False
[Link], e As [Link]) '[Link] = False
Handles [Link] '[Link] = False
Try '[Link] = False
Catch ex As Exception [Link](x)
End Try [Link]()
[Link] = New Point(230, 35) '[Link] = False
'[Link] = False
End Sub '[Link] = False
'[Link] = False
Private Sub Button3_Click(sender As Catch ex As Exception
[Link], e As [Link]) End Try
Handles [Link] [Link] = New Point(587, 35)
Try End Sub
[Link] = True
x = 1300 Private Sub Button5_Click(sender As
[Link]() [Link], e As [Link])
[Link](x) Handles [Link]
[Link]() Try
'[Link] = False [Link] = True
'[Link] = False x = 2600
'[Link] = False [Link]()
'[Link] = False [Link](x)
Catch ex As Exception [Link]()
End Try '[Link] = False
[Link] = New Point(409, 35) '[Link] = False
End Sub '[Link] = False
'[Link] = False
Private Sub Button4_Click(sender As Catch ex As Exception
[Link], e As [Link]) End Try
Handles [Link] [Link] = New Point(772, 35)
Try End Sub
[Link] = True
x = 1950
[Link]()
Private Sub Timer1_Tick(sender As [Link] = False
[Link], e As [Link]) '[Link] = True
Handles [Link] '[Link] = True
Dim incoming As String '[Link] = True
Try '[Link] = True
[Link] = x '[Link] = True
incoming = End If
[Link]() Catch ex As Exception
z = incoming End Try
[Link] = incoming End Sub
If incoming = 5 Then End Class

You might also like