Arduino + Visual Basic : PWM Control

Vb Pwm Banner
Pulse Width Modulation or PWM allows the microcontroller to mimic analog control by turning the voltage on and off very quickly.

The Arduino has an 8 bit PWM built-in, which means it has up to 256 levels of control. ( 2^8 = 256 ).

These 256 levels of control actually determines the percentage of the ON duty cycle over the OFF.

pwm_duty

0 is completely OFF while 255 is completely ON.

In this article, I’m using a Visual Basic program to control the PWM on the Arduino.

PWM can control many things, such as LED, motors, sound amplitude, etc.

pwm_led

If you wish to control a motor, you’ll need a transistor as shown below.

vb_pwm_circuit1

The Visual Basic and Arduino source code can be downloaded below but make sure you change the code highlighted below to the correct COM port.

vb_change_port

Download Code

  1. Dan B02-16-2016

    hi great code thanks
    beginner question
    when using the slider in VB with the mouse it works great

    however if you use the keboard arrow keys to move the sliders up and down they have no effect on the led or motor
    is there an easy fix?
    thanks for sharing
    regrds
    dan

  2. Faiz04-15-2015

    Hello waihung, If I wanna control more than 2 motors with different value of pwm to be set. How can i write it in vb and arduino. I need to control PWM for 3 different DC motors using graphical user interface like the one you made. Thanks for the help.

  3. medina08-11-2014

    Good waihung an excellent job, but would like to consult you one little thing about a project I want to write, is created with vb form in which a trackbar can dimear PWM output .until no good and I succeeded but with limitation that is only the state change brightness LED running when I stop and move the trackbar .si I move to 25 lights hit 25 like it was progesivo .me from 0- 255.por other hand if another insert more output in the form not how to connect vb with arduino to answer me this new pin .I have in mind to create the same as you will see in the project but for 14 pwm outputs .me like to control them independently.
    this is my whole project
    https://www.dropbox.com/s/v33akm2nmiaxpnv/APP%2016CHANEL.rar
    If I could help you appreciate just implantaras .con a pin in both traditionally files I would do the rest .thanks again

  4. ronald02-05-2014

    wonderful info,

    how about arduino ide sketch that to make arduino transform from serial data input to output pwm?

    • Wai Hung02-05-2014

      The arduino sketch is in the compressed file RAR file that you can download above.

  5. Juan12-28-2013

    Thank you very much for this Web, really helpfull.

    moving forward, i can´t change the port to com9. I´ve edit the Form1.vb file but nothing it keeps me showing an error that says that port com4 doesn’t exist. for the three softwares.

    Any clue?

    thank you

    • Wai Hung12-28-2013

      Try to click on the SerialPort1 properties to change the com port from there.

Leave a Reply to Faiz Click here to cancel reply.