Using Visual Basic 2010 to Control Arduino Uno

Google+ Pinterest LinkedIn Tumblr +

I do know this has been carried out prior to now a couple of instances so here is yet another. This is a skeletal Visual Basic 2010 and Arduino Sketch that I combined collectively to check the PC to Arduino Uno connection through serial. It merely turns LED 13 on or off. 

The Visual Basic 2010 code assumes you’ve gotten Form1 with 2 buttons Button1 and Button2 and SerialPort1 controls. Button1 sends a 1 and Button2 sends a zero to the serial port COM10 (change this to match your PC to Arduino port setting)

See hooked up photograph of my easy kind design.

The Arduino Uno Sketch code merely waits and reads the serial port. If it see 1 it’ll flip PIN 13 on and if it sees zero it’ll flip PIN 13 off. If you’ve gotten an LED on PIN 13, you possibly can flip it on and off. On the Arduino Uno, PIN 13 is hooked up to a an on-board LED.

I used COM10 as a serial port however you possibly can (and should) change it to match your Arduino serial port.

The goal of this code is to simplify clarification of how one can join VB to Arduino. You can add error processing and extra intelligence based mostly in your explicit wants.  

Make certain you drag the Serial Port management icon from the Toolbox onto your kind. It ought to have the identify SerialPort1

WARNING: On my PC I needed to shut the Arduino IDE Serial Monitor window whereas runing the VB program, else I run into all types of error message about COM port entry denied and this system will fail.

You can obtain Visual Basic Express 2010 free of charge from Microsoft
http://www.microsoft.com/visualstudio/en-us/merchandise/2010-editions/visual-basic-express

‘———— START OF VB 2010 CODE —————–
‘ NOTE: I’m utilizing COM10 so that you must change the Visual Basic code to match your COM port

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.PortIdentify = “com10” ‘change com port to match your Arduino port
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = eight
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default ‘crucial!
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.Write(“1”)
SerialPort1.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Open()
SerialPort1.Write(“zero”)
SerialPort1.Close()
End Sub
End Class

‘———— END OF VB 2010 CODE —————–

//————- START OF ARDUINO SKETCH —————–
//
// Mixed by: Hazim Bitar
// Based on: Science Guy 14 youTube tutorial http://youtu.be/g0pSfyXOXj8

int ledPin = 13; // the variety of the LED pin

void setup()

void loop()

//————- END OF ARDUINO SKETCH —————–
 

Read more

Share.

Leave a Reply

%d bloggers like this: