PWM

hello,

Can i create and/or control PWM using AduinoUNO?

Bassam

Yes, have a look at the documentation.

is there anyway of getting more than 5V using UNO, if NO, how can I get more than 5V?

Why do you need more than 5V? (There are different ways, depending upon what you need)

is there anyway of getting more than 5V using UNO, if NO, how can I get more than 5V?

Yes, you simply wire a transistor rated for the voltage and current required for you load and the arduino will turn on or off the transistors base (or gate) with it's five volt signal. Note that for npn transistors you must have a series base resistor from the arduino output pin to the base of the transistor such that the current is limited to the safe current limit for the output pin or transistor base current, whichever has the lower max current specification. Also if using an external power for the device the transistor is switching, there must be a connection made between the arduino ground pin and the external power supply ground terminal.

Lefty

For info on PWM see:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

For motors see:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

thanks all for replying.

i'm using the following lines for PWM:

// PWM SECTION:

{
if (cm >= 55 && cm <= 280)
{
x = ((cm/300)*255); // x is int, and cm is long, maintane car distance from the object, (0% < Duty cycle < 100%)
}
else if (cm <55)
{
x = 0; // STOP car!, Duty cycle = 0%
}
else
{
x = 255; // full speed, clear road, Duty cycle = 100%
}

analogWrite (pwmPin, x); // this pin is connected to a chip to drive the car motor.
delay (30);
}

I think the above will produce a (0-5v) PWM with different duty cycles. can you confirm?

THE QUESTION?

Can I reverse the PWM to reverse the direction of the motor i'm trying to control?

i.e.: (-5v-0) PWM ?

Common fault -

((cm/300)*255);

if cm is 100, then 100/300 = 0 (big fat zero) because you are doing an INTEGER DIVIDE, and you car will stay still until your test >280cm kicks in.

Write (cm/300.0*255.0) this way 100/300 will be 0.3 then multiplied by 255 and yield the expected result, which nicely gets converted to fit in the x (or use x = int((cm/300.)*255.) )

Alternativly as you write the cm is long it would work if you move the brackets x = ((cm*255)/300) and is the shortest computation.

Or better, use the map() function, that is what it is there for - to change a number from one range (0-300) to another 0-255): map(x,0,300,0,255) You can even use the map function so that 54-281 is changed to a 1-254 range : map(x,54,281,1,254)

Can I reverse the PWM to reverse the direction of the motor i'm trying to control?

No.

You didn't read the links I posted last time did you?

is there anyway of getting more than 5V using UNO,

No

if NO, how can I get more than 5V?

Use a transistor as per the motors link.