real dumb question ... PWM vs digial output pins

OK … first time actually touching an Arduino.

I have a mega 2560

Got the software installed … loaded the program … onboard LED blinks … GREAT!

So, I wanted to put an external.

I understand I need to change the first line of the code from


to some other pin.

My question is what pin? I see an example showing pin 9

When I look, Pin 9 is a PWM output (on both the UNO and MEGA).

Do I need to use a PWM pin or could I use any of the pins marked Digital (say 30 though 40)?

I just wanted to make sure I was not going to draw to much power and kill the board the first night.

I do have a 330 ohm resistor in line with the LED.

Thanks … Mike

PWM stands for Pulse Width Modulation. It's a technique of outputting "Analog signal" using nothing but digital circuitry. The idea is that instead of running constant 5V or pulling all the way to 0V (basically pure digital), the controller would pulse the signal on and off for certain amount of time each. So, for example, in one second, the pin would output 0.5 seconds of HIGH (5V) and 0.5s of LOW (0V), and repeats the cycle next second. This would bring the average voltage to 0.5 times of 5V (2.5V), thus "emulating" analog signal.

For your purposes, IF you only want to turn an LED on and off, you don't need PWM. Any digital pin would work. BUT, if you're trying to fade the LED, then PWM is required.

P.S: Arduino has a mini PWM introduction here

Oh, and don't forget the resistor. Still need the resistor.

Got it ...

I was just afraid the PWM outputs were somehow designed for a higher output current ... obviously not.

I changed the code to pin 40 ... plugged into pin 40 (with the 330 ohm resistor) .... it works!

PWM with a tri color LED is the next lesson. I am following some online examples but many are for UNO and not MEGA .... just changing the pin identifier at the beginning of the program.

Thanks so much !!!!!!!!!!!!

@xtal_01 - you may find some of the info and projects on my site interesting.

You can get an Arduino Nano (clone) for nickels, and a breadboard that will support lots of beginner projects. The Nano is very like the Uno as it uses the same chip.

I was just afraid the PWM outputs were somehow designed for a higher output current

Let's suppose it was ( which as you rightly point out it is not ) What then would be the consequences of connecting a LED and resistor to it?

Answer, nothing at all!

The thing determining the current in a circuit is the voltage applied to the circuit, and the resistance of the circuit. The current capability has nothing to do with the actual current that flows. That is if you have a circuit that takes under the maximum current capability.

Think of your house lights. They are normally on a circuit that can provide 5 Amps ( because of a 5 Amp fuse ), yet you can plug in any wattage light into it. A 25W light takes only a quarter of the current of a 100W light and yet the current capacity of your light system has no problem and the smaller current light does not blow up.