Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (2)

Powered by Vanilla. Made with Bootstrap.
Arduino [Control LEDs]
  • Sh3llc0d3
    Posts: 1,910
    As the programming for the Arduino is C/C++ based I'll put this here... although beware, this does contain vb.net ;) Anyway this was another random 'mini-project' for the arduino I did.

    The Idea behind this program is to allow a program (in vb.net) to control (via serial port) the LEDs on the arduino breadboard.

    Simple setup - 4 leds, 4 resistors, 5 cables (4 (LED->Pins) and 1 for the ground)

    Arduino program:
    int redPinOne = 12;
    int redPinTwo = 13;
    int greenPinTwo = 11;
    int greenPinOne = 10;
    int readValue;

    void setup()
    {
    pinMode(redPinOne, OUTPUT);
    pinMode(redPinTwo, OUTPUT);
    pinMode(greenPinOne, OUTPUT);
    pinMode(greenPinTwo, OUTPUT);
    Serial.begin(9600);
    }

    void loop()
    {
    if(Serial.available())
    {
    readValue = Serial.read();
    if(readValue == '1') // LED ON
    {
    digitalWrite(greenPinOne, HIGH);
    }
    if(readValue == '2') // LED ON
    {
    digitalWrite(greenPinOne, LOW);
    }
    if(readValue == '3') // LED ON
    {
    digitalWrite(greenPinTwo, HIGH);
    }
    if(readValue == '4') // LED ON
    {
    digitalWrite(greenPinTwo, LOW);
    }
    if(readValue == '5') // LED ON
    {
    digitalWrite(redPinOne, HIGH);
    }
    if(readValue == '6') // LED ON
    {
    digitalWrite(redPinOne, LOW);
    }
    if(readValue == '7') // LED ON
    {
    digitalWrite(redPinTwo, HIGH);
    }
    if(readValue == '8') // LED ON
    {
    digitalWrite(redPinTwo, LOW);
    }
    }
    }


    Controller (VB.Net):

    [spoiler=screenshots]
    http://i.imgur.com/2V0LL.png
    http://i.imgur.com/lZJT2.png
    http://i.imgur.com/dXvgs.png
    [/spoiler]

    [spoiler=Video]
    [align=center][video=youtube]


    Your Baud rate and com port may be different. If your not sure check the baud rate you coded and the com port will be visible on the tools menu of the arduino IDE.

    Imports System.IO.Ports

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If SerialPort1.IsOpen() = True Then
    SerialPort1.Close()
    End If

    ledGrOne.Text = \"Green LED #1 ON\"
    ledGrTwo.Text = \"Green LED #2 ON\"
    ledReOne.Text = \"Red LED #1 ON\"
    ledReTwo.Text = \"Red LED #2 ON\"
    End Sub

    Private Sub ledGrOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ledGrOne.Click
    If ledGrOne.Text = \"Green LED #1 ON\" Then
    SerialPort1.Write(\"1\")
    ledGrOne.Text = \"Green LED #1 OFF\"
    Else
    SerialPort1.Write(\"2\")
    ledGrOne.Text = \"Green LED #1 ON\"
    End If
    End Sub

    Private Sub ledGrTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ledGrTwo.Click
    If ledGrTwo.Text = \"Green LED #2 ON\" Then
    SerialPort1.Write(\"3\")
    ledGrTwo.Text = \"Green LED #2 OFF\"
    Else
    SerialPort1.Write(\"4\")
    ledGrTwo.Text = \"Green LED #2 ON\"
    End If
    End Sub

    Private Sub ledReOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ledReOne.Click
    If ledReOne.Text = \"Red LED #1 ON\" Then
    SerialPort1.Write(\"5\")
    ledReOne.Text = \"Red LED #1 OFF\"
    Else
    SerialPort1.Write(\"6\")
    ledReOne.Text = \"Red LED #1 ON\"
    End If
    End Sub

    Private Sub ledReTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ledReTwo.Click
    If ledReTwo.Text = \"Red LED #2 ON\" Then
    SerialPort1.Write(\"7\")
    ledReTwo.Text = \"Red LED #2 OFF\"
    Else
    SerialPort1.Write(\"8\")
    ledReTwo.Text = \"Red LED #2 ON\"
    End If
    End Sub

    Private Sub InitSerial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InitSerial.Click
    SerialPort1.PortName = TextBox2.Text
    SerialPort1.BaudRate = Val(TextBox1.Text)
    SerialPort1.Open()
    InitSerial.Enabled = False
    End Sub
    End Class
  • Hello,
    can you share the source code of this project in Visual basic 6.0?
    i'm a newb in arduino and visual basic...kindly please help me...
    i want to control 8 LEDs or more using arduino and VB6. and for future project changing LEDs to motors and relays.
    Thanks!
  • Please help me with the source codes in VB6.
    here's my email: rey.mar143@yahoo.com
    Thanks!
  • Sh3llc0d3
    Posts: 1,910
    @reymar143, unfortunately my visual basic .Net now is a far stretch from what it was as I've moved onto other languages. I wouldn't know where to begin with VB6 and wouldn't have known back when I did the code above. So unfortunately I can't help, however I'm sure there will be a VB6 coder around here that may be able to help.