make sure you drag the serial port control icon from the toolbox onto your form
DESCRIPTION
Sure productsTRANSCRIPT
Make sure you drag the Serial Port control icon from the Toolbox onto your form. It should have the nameSerialPort1
'------------ START OF VB 2010 CODE -----------------' NOTE: I am using COM10 so you need to change the Visual Basic code to match your COM port
Imports System.IOImports System.IO.PortsImports System.Threading
Public Class Form1Shared _continue As BooleanShared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadSerialPort1.Close()SerialPort1.PortName = "com10" 'change com port to match your Arduino portSerialPort1.BaudRate = 9600SerialPort1.DataBits = 8SerialPort1.Parity = Parity.NoneSerialPort1.StopBits = StopBits.OneSerialPort1.Handshake = Handshake.NoneSerialPort1.Encoding = System.Text.Encoding.Default 'very important!End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickSerialPort1.Open()SerialPort1.Write("1")SerialPort1.Close()End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickSerialPort1.Open()SerialPort1.Write("0")SerialPort1.Close()End SubEnd 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 number of the LED pin
void setup() {Serial.begin(9600); // set serial speedpinMode(ledPin, OUTPUT); // set LED as outputdigitalWrite(ledPin, LOW); //turn off LED}
void loop(){while (Serial.available() == 0); // do nothing if nothing sentint val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number
if (val == 1) { // test for command 1 then turn on LEDSerial.println("LED on");digitalWrite(ledPin, HIGH); // turn on LED}else if (val == 0) // test for command 0 then turn off LED{Serial.println("LED OFF");digitalWrite(ledPin, LOW); // turn off LED}else // if not one of above command, do nothing{//val = val;}Serial.println(val);Serial.flush(); // clear serial port}
//------------- END OF ARDUINO SKETCH -----------------http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express