Using PWM in arduino using Matlab's writePWMVoltage() | applied electronics engineering

Latest

Using PWM in arduino using Matlab's writePWMVoltage()

By Applied Electronics - Tuesday, January 31, 2017 No Comments
In this tutorial we demonstrate with video how to use the Matlab writePWMVoltage() function for sending out PWM signals in arduino. This is a follow up of the last tutorial working with arduino PWM in matlab where we showed how to use the writePWMDutyCycle() function to send the same PWM signal.

The writePWMVoltage() is used to send PWM signal via one of the six PWM digital pins in Arduino UNO. In using this function we have to specify the arduino object, the pin number and the voltage we want to send.

The syntax of writePWMVoltage() function is,

writePWMVoltage(a, pin, voltage)

Remember that the function name is case sensitive.

As an example the following statement,

 writePWMVoltage(a, 'D10', 2)

will sends out PWM signal of 2V magnitude on pin 10.

As a real application of this function consider turning on the brightness of a LED(or bulb or motor) slowly ON and turning it slowing off. The following matlab code achieves this,


clear a
% create arduino object
a = arduino();

% Control the brightness of LED using writePWMVoltage()

voltage_step = 5/30;

for k = 1:30
    writePWMVoltage(a, 'D10', k*voltage_step);
    pause(0.1);
end

for k = 1:30
    writePWMVoltage(a, 'D10', 5-k*voltage_step);
    pause(0.1);
end

First we create an arduino object with a = arduino(). Then to turn slowly on and off the brightness of the LED we first create small voltage steps to increment. This is done by dividing full voltage range by some number like 30 in this case. Since the digital pin can output upto 5V, we divide it equally by 30. That means each voltage step is 5/30= 0.166V. Then using a for loop we increment from 0 to 5V by 0.166V. Similarly during lowering the brightness we decrease it from 5V to 0V using 0.166V voltage step.

Now the following video demonstrates this brightness control of the LED using arduino programmed by Matlab.




No Comment to " Using PWM in arduino using Matlab's writePWMVoltage() "