Arduino tutorial: How to turn on/off 8 LED using visual basic 6

I will share my experience about how to turn on and off 8 leds through the widget made using visual basic 6. I am using visual basic 6 because the file is not large and light program execution.

How its work ?

8 pieces led Arduino connected to a digital channel from D2 .. D9. Each LED in series with a resistor about 120Ohm is connected to GND. Thus each led will turn of  in a logic 1.

Arduino program

On the Arduino board, was created a program to accept the character as a command to turn off and turn on each LED. Command of the character of 1,2,3,4,5,6,7,8, used to turn on or turn off each LED on arduino board as toggle function. Other characters as  command of “*” character serves to turn on all LED. The character “-” to order all led to turn off.

Each character as commands are sent serially to the Arduino board. Thus,  the Arduino will send back all conditions of leds in string form., for example, “10101010″. The character “0″ means the condition of the LED is die and vice versa “1″ is alive.

Variable and serial event

As a global variable is “charCmd” defined as byte to hold a character as a command that sent from the PC. Variable of ccmdOk defined as boolean is a flag to mark that character just received from PC. The special variable is stateLED defined as char. This is for holding the state of 8 LEDs in bit for each LED.

The serialEvent() function is event interrupt of microcontroler. This function by default on arduino will call automatically if just completely receive a char from RX pin. If the character has been received from PC, the result will be stored in the variable of “charCmd”, then flag of “cmdOk” is set to “true”.

Functions

Two functions are made to treat the LED on the Arduino board are:

  1. setLED()
    Serves to turn on or turn off each LED corresponding to logic of each bit in the variable conditions of stateLED. Line 28, is looping to get each bit of stateLED variable. Every bit of stateLED variable, is tested using bitRead function(). Thus, written to digital channel of arduino. The status of each led is sent to serial and received by PC as hanshaking or display status.
  2. invertLED()
    This function serve to invert the logic of each bit on stateLED variable, indexed  by n variable. This function have one passing parameter to point each bit on stateLED variable.

Setup() function

This initialization are open serial using 115200baud and making D2 to D9 as output, also all LEDs turn off. For shortened codes, i used loop of for() statement and variable of d is used as index of digital channels that to be connected to LEDs. 

Loop() function

The loop functio () checks if there are characters that is sent by the PC. If the variable cmdOk = true, then there are characters received from the PC is stored in the variable of charCmd. Next tested whether the character is ’1′ to ”8′, ‘*’ or ‘-’. If the character are  ’1 ‘to ’8′, will call the function of invertLED, means reversing the logic of each bit on variable of stateLED. If the character is ‘*’, stateLED will be assigned to 255 (all LEDs will be turned on), ‘-’ stateLED will be assigned to 0 (all LEDs will be turned off).

Source code of arduino program can be downloaded here.

 

 

 

 

 

 

 

 

Widget of visual basic 6

 I made this widget by using Visual Basic 6. You can install directly to a computer to download the setup program by clicking here. Or you can download the source program by clicking here. Do not forget to include the name of program creator, and web link on your project.

Demo

YouTube Preview Image

Last updated by at .

Avatar of Bambang Siswoyo

About Bambang Siswoyo

I am a college lecturer since 1988 at UB (University of Brawijaya) in the electronics department. My experience: Applications of Microprocessor system, Applications of Control System, Applications of Field Programmable Gate Array, Computer Programming in computer instrumentations. My hobby: Music especially playing the saxophone, hiking and exploring the countryside.
This entry was posted in Arduino, Tutorial and tagged , , . Bookmark the permalink.

14 Responses to Arduino tutorial: How to turn on/off 8 LED using visual basic 6

  1. claudio says:

    Hi
    I’ve downloaded the VB6 program source (How to turn on/off 8 LED using visual basic 6), but the form1.frm is missing from the downloaded files, so it’s no possible to run the program or look at the source code. (The source code is included in this form1, I guess)
    I’m a VB6 programmer and I’m looking for examples how to set ON/OFF the Arduino UNO digital outputs.
    Best Regards
    Claudio

    • I apologize for the mistake of compress files. In my project turned out to be outside the Form1 file folder, so it is not included in the file. I have uploaded the compress file again. Please you develop, by not forgetting to mention the link from the source.

  2. mufa says:

    Salam Sukses pak Bambang, pak saya sudah mencoba nya…, tetapi koq tetap tidak bekerja…. saya menggunakan arduino uno…. maaf masih belajar pak…., saya ingin bisa menyalakan 14 led lewat arduino uno dengan bantuan progam vb., mohon pencerahannya……..
    terima kasih

  3. michael says:

    Terima kasih telah berbagi dengan uraian yang sangat jelas.

  4. Jessika says:

    You created a lot of remarkable stuff with your article, “Arduino
    tutorial: How to turn on/off 8 LED using visual basic 6 | Bambang Siswoyo” christianhost .
    I may end up coming back again to your blog shortly. With thanks ,Edgardo

  5. ardi says:

    salam pak bambang.. pak saya mau tanya ni.. coding sya coba pake arduino uno. kok gak jalan ya pak..

  6. nurhamdhan says:

    salam pak bambang..

    saya mau tanya coding untuk menghubungkan arduino uno R3 dengan vb.6 menggunakan koneksi usb, saya sudah coba tapi vb.6 tidak bisa mendeteksi

    mohon bantuannya, terima kasih

  7. Adam says:

    is there a complete source code for the arduino program tnx

  8. Charles Harris says:

    Hi
    With the 8 led jproject is it possible to place a table in the Arduino with several combinations of sequence, and when a specific sequence required a button pushed and the sequence run until next sequence button pushed.
    Thankyou

    Charles Harris
    New Zealand

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>