Introduction: Arduino Rgb Controller From Vb.net

Picture of Arduino Rgb Controller From Vb.net

Hi, this is my first instractables, today i'll show you how to make an rgb controller with an arduino UNO R3, controlled by an application made in vb.net

With this project you can simply control your led strip and make what colour you like

excuse me for my english, i hope you like my instructable

Step 1: Parts and Material

Picture of Parts and Material

These are the materials:

  • 1 arduino uno
  • 1 usb for arduino (programming or connection)
  • 1 bluetooth module (optional but make this project wireless)
  • Arduino IDE
  • Visual studio

Step 2: Arduino Code

Picture of Arduino Code

The arduino code is very simple but powerfull

code:

int ledrPin = 9;
int ledgPin = 10;
int ledbPin = 11;
void setup() {
  Serial.begin(9600);
  pinMode(ledrPin, OUTPUT);
  pinMode(ledgPin, OUTPUT);
  pinMode(ledbPin, OUTPUT);
}
void loop() {
  if (Serial.available() > 0) {
    int r = Serial.parseInt();
    int g = Serial.parseInt();
    int b = Serial.parseInt();
 

    analogWrite(ledrPin, r);
    analogWrite(ledgPin, g);
    analogWrite(ledbPin, b);
 }
}<br>

Copy and paste this code into the arduino ide

now you have to upload it to your board

Step 3: Vb.net Code

Picture of Vb.net Code

You have to open visual studio or visual basic

  1. Create a new project
  2. name it like "rgb controller"

Once the form is created drag and drop this control to the form:

  • 1 label and set the text to: "Select the COM port"
  • 1 combobox
  • 1 button and name it: "refresh"
  • 3 trackbar (set minimum value to 0 and maximum value to 255)
  • 1 label at the bottom and set the text to: "Rgb: 255,255,255"
  • 1 picturebox (set the backcolor to white, to see what colour we have select)
  • 1 timer


Now we have to write the code for the rgb controller

before all write:

Imports System.IO.Ports


under Public Class Form1 write:

Dim connected As Boolean = False   Dim r As Integer
Dim port As New SerialPort
Dim r As Integer = 255<br>Dim g As Integer = 255
Dim b As Integer = 255
Dim rgb As String = TrackBar1.Maximum - TrackBar1.Value + TrackBar1.Minimum & "," & TrackBar2.Maximum - TrackBar2.Value + TrackBar2.Minimum & "," & TrackBar3.Maximum - TrackBar3.Value + TrackBar3.Minimum & "M"


create a new function called COMport to search all the serial port avaible and add to the combobox

Function COMport()<br>        ComboBox1.Items.Clear()
        ComboBox1.Items.AddRange(SerialPort.GetPortNames)
    End Function


in the form1.load call COMport()

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load<br>        COMport()
    End Sub


Double click on the refresh button and add the same call COMport()

Double click on the combobox and add this code to set the port option

Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        connected = True
        port.Close()
        port.PortName = ComboBox1.SelectedItem.ToString
        port.BaudRate = 9600
        port.DataBits = 8
        port.Parity = Parity.None
        port.StopBits = StopBits.One
        port.Handshake = Handshake.None
        port.Encoding = System.Text.Encoding.Default
    End Sub


Now set the timer to enabled with an interval of 1 and add this code to the timer tick event

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        rgb = TrackBar1.Maximum - TrackBar1.Value + TrackBar1.Minimum & "," & TrackBar2.Maximum - TrackBar2.Value + TrackBar2.Minimum & "," & TrackBar3.Maximum - TrackBar3.Value + TrackBar3.Minimum & "M"
        Label2.Text = "Rgb: " & r & "," & g & "," & b
        PictureBox1.BackColor = Color.FromArgb(r, g, b)
        If connected = True Then
           If port.IsOpen Then
                Try
                    port.Write(rgb)
                    port.Close()
                Catch ex As Exception
                End Try
         Else
                Try
                    port.Open()
                    port.Write(rgb)
                    port.Close()
                Catch ex As Exception
                End Try
            End If
        End If
    End Sub<br>


Now there is the part of the code for change the code through the three trackbar

Double click on the first trackbar and here is the code

r = TrackBar1.Value


The second trackbar code

g = TrackBar2.Value


the third trackbar code

b = TrackBar3.Value

Step 4: The Connection

Picture of The Connection

If you connect only 1 led, it only need arduino, wire, resistor and the led, but if you want to connect an rgb strip, you have to use an amplifier for strip like this

the connection is:

  • pin 9 to resistor to - red
  • pin 10 to resistor to - green
  • pin 11 to resistor to - blue
  • vcc to + led

It's time to compile and test the app
i've only tested the connection through usb, before you choose the serial port, you have to connect arduino to usb and connect the program through the arduino COM

Step 5: Conclusion

Picture of Conclusion

This is the program i use with my custom animated theme and more option like effect, on, off...

if you have a basic programming skill, you can make this and more function...

i hope you enjoy

Comments

NusbioM made it! (author)2016-12-08

You can learn how to go above 115200 baud (11Kb/S) from Windows and .NET to an Arduino with the following post

http://madeintheusb.blogspot.com/2016/07/faster-serial-port-communication-from.html

h0uri (author)2015-04-17

cool .. been looking to control leds from pc ..

Miky94x (author)h0uri2015-04-17

Thanks :)

seamster (author)2015-03-25

Nicely done. Thanks for sharing this!

Miky94x (author)seamster2015-03-28

Thanks :)

About This Instructable

3,297views

20favorites

License:

More by Miky94x:Diy rgb led MailboxArduino Rgb controller from Vb.net
Add instructable to: