Fading Example

The Arduino SDK includes an PWM example called "Fading". I haven't tried it yet because I don't currently have the hardware (LED). However, after looking at the example it simply modifies the voltage (AMPLITUDE) of the signal and not the ratio (WIDTH) of the signal. What am I missing here?

it simply modifies the voltage (AMPLITUDE) of the signal

It does no such thing.

The output from a digital pin will always be 0V or 5V. The second parameter of analogWrite() alters the proportion of the time spent at each voltage and hence the average voltage of the pin over time.

mulu:
I haven't tried it yet because I don't currently have the hardware (LED).

If you have an Arduino UNO or MEGA or Leonardo or clone of any of them there is a BUILT_IN LED on Pin 9.

If you are measuring the output pin with a meter you are probably seeing the average voltage. Try an oscilloscope to see the actual PWM waveform.

If you have an Arduino UNO or MEGA or Leonardo or clone of any of them there is a BUILT_IN LED on Pin 9.

Pin 9 ?

And if you have a Uno or Mega you can use the onboard led as well. Simply don't set pin 13 (on which the onboard led is) to output (leave/make it an input) and put a wire between the PWM pin you want and pin 13.

UKHeliBob:
Pin 9 ?

Oops... Pin 13.

Thanks everybody for the input. I thought this was an analog output, hence my confusion about thinking this sets the amplitude. I didn't realize that PWM is 'built-in' on some digital pins and that the value set is the duty cycle. I thought I had to write code for that myself. This makes everything super easy. I have a nano so I just connected pin 11 (PWM) and pin 13 (LED) and in the setup configured pin 13 as an input.

The next goal is to dim an LED strip light. I just got some MOSFETs today (IRF540N). Let's see how that goes...

And you know IRF are not logic level MOS FETs.

.

LarryD:
And you know IRF are not logic level MOS FETs.

Sorry my ignorance but what are "logic level MOS FETs"? "logic level" sounds like binary. Maybe they are not switching quickly enough to be considered "logic level"? Just a guess.

In any case, I used the IRF540N that I received today and was able to dim a 5m LED strip. It seems to do what I want it to do but please enlighten me about what I am missing. Thanks in advance.

Delta_G:
Careful Bob, I made that statement a couple days ago and got hit by the technicality police.

I saw that, but I was feeling brave !

Logic level
look at this:

.

LarryD:
Logic level
look at this:
https://m.youtube.com/watch?v=GrvvkYTW_0k

Thanks you. I looked at the spec sheet of the IRF540N. It turns out that while it does switch on at 5V (it does somewhere between 2-4V) it doesn't fully open until the voltage is significantly higher. So I producing a lot of heat (and possibly destroy it). I ordered some new ones. Thanks for that input.

You can tell if you have a Logic Level MOSFET from the RON (on resistance) specification in the datasheet. If the reported RON is measured at a gate voltage well above your logic voltage (typically 10V or higher) it is NOT a Logic Level MOSFET. If RON is measured at a gate voltage at or below your logic voltage (typically 5V, 4.5V or lower) it IS a Logic Level MOSFET.