Introduction: Visual Basic Arduino Interface

Source : https://theorycircuit.com/arduino-projects/visual-basic-arduino-interface/

Arduino board can communicate through serial monitor of Arduino IDE, but it provides text and numeric options only. When we think about Graphical Interface and control the Visual Basic is the best one come in mind. Visual studio provides different language program support, even the visual studio Arduino IDE also available on internet.

In this project I have used Microsoft Visual studio 2005, here the goal is to turn ON and turn OFF the Arduino onboard LED (D13) through one windows application.


Creating windows application through Visual basic provides best GUI (Graphical User Interface) and also it provides configurable Serial Port to control devices connected with computer.

Step 1: Prototype

Arduino board can communicate through serial monitor of Arduino IDE, How?

Step 2: Hardware Setup

Simply connect the Arduino board with computer and there is no other hardware connections required, because this project handles the onboard LED of Arduino.

Step 3: Visual Basic Program

To start the project you need visual basic software, Just create new project windows application in visual basic IDE and draw the required buttons and picture box for visual interface then name these components as given in properties.

* Button1 (text = LED ON) (Name = ButtonON)

* Button2 (text = LED OFF) (Name = ButtonOFF)

* Picturebox1 (Name = led)

* Picturebox2 (Name = ledon)

* Serial port (com11 //change as per your arduino port number)

Imports System.IO
Imports System.IO.Ports Imports System.Threading

Public Class Form1

Shared _continue As Boolean

Shared _serialPort As SerialPort

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.Close()

SerialPort1.PortName = "com11" 'check and change Arduino port

SerialPort1.BaudRate = 9600

SerialPort1.DataBits = 8

SerialPort1.Parity = Parity.None

SerialPort1.StopBits = StopBits.One

SerialPort1.Handshake = Handshake.None

SerialPort1.Encoding = System.Text.Encoding.Default

End Sub

Private Sub ButtonON_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonON.Click

led.Visible = False

ledon.Visible = True

SerialPort1.Open()

SerialPort1.Write("1")

SerialPort1.Close()

End Sub

Private Sub ButtonOFF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOFF.Click

led.Visible = True

ledon.Visible = False

SerialPort1.Open()

SerialPort1.Write("0")

SerialPort1.Close()

End Sub

End Class

Step 4: Arduino Code

After completing the Visual basic design don’t forget to upload the Arduino code on board.

void setup()
{

pinMode (13,OUTPUT);

Serial.begin(9600);

}

void loop()

{

int value;

if(Serial.available())

{

delay(50);

while(Serial.available() >0)

{

value=Serial.read();

if(value=='1'){digitalWrite(13,HIGH);}

else if (value=='0') {digitalWrite (13,LOW); }

}

}

}

Step 5: Ref.file