Sunday, 27 September 2015

Control Arduino Using Visual Basic 2008


Visual Basic 2008 With Arduino

Sebarang pertanyaan/pembelian/bantuan boleh dm saya dia twitter eh:

i recommend watch this video on youtube for better quality
https://www.youtube.com/watch?v=OBJdnFVBfvY





Arduino Code



String incoming;
int led = 8;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop()
{

  if(Serial.available() > 0)
  {
    incoming = Serial.readString();  //<<---this is the most important
    if(incoming == "TURN ON")
    {
      digitalWrite(led, HIGH);
    }
    else if(incoming == "TURN OFF")
    {
      digitalWrite(led, LOW);
    }
  }
}



Code Explaination

String incoming;
-string that vb send to arduino.

int led = 8;
-tell arduino i attach led on pin 8

Serial.begin(9600);
-Baud rate.

pinMode(led, OUTPUT);
-set led as output

if(Serial.available() > 0)
-when serial is available. If Arduino read any byte

incoming = Serial.readString();
-read serial in string.

if(incoming == "TURN ON")
-if incoming string that arduino read is "TURN ON"

digitalWrite(led, HIGH);
-Arduino will turn on led on pin8




Download link

Arduino Code:
VB 2008 Code:

No comments:

Post a Comment