# Why do some pins have ~ signs next to their numbers?

I was looking at my Arduino Uno and I noticed that symbol by digital pins 11, 10, 9, 6, 5, and 3. What do these mean? Does this affect the way it works? Can I not use these pins for certain situations?

• The tilde symbol means "approximately". As in, "this is approximately pin 11". During the mfg process the pins can shift around a little bit. Rarely will pin 11 be exactly 11. Usually it is a little more or a little less than 11. Pins that have an increased tendency to shift around will be denoted with the ~ symbol. :) – user3624 Jun 14 '13 at 14:18
• @AnnonomusPerson David's being facetious, which isn't immediately obvious if you're unfamiliar with pinouts and the likes. – Shamtam Jun 14 '13 at 21:47
• @Shamtam: Or if you're unfamiliar with David :) – Chris Laplante Jun 14 '13 at 22:16

Relax. Don't worry. These pins are called PWM and are the same as the other pins, except they have an "added bonus."

Some uses from Arduino's Website:

• Dimming an LED
• Simulates an analog output. The output is still digitally toggling from 0V to 5V. However, low-pass filter (capacitor and resistor) to simulate analog voltages.
• Generating audio signals.
• Providing variable speed control for motors.
• Generating a modulated signal, for example to drive an infrared LED for a remote control.

How it works:

The PWM pins are controlled by on-chip timers which toggle the pins automatically at a rate of about 490Hz. The "Pulse Width Modulation" (PWM) is how long the pin stays on or off for a single cycle of that frequency. This can dim a LED by giving the illusion it is at half the brightness as before, where it is really flashing very quickly.

When there is a 25% duty cycle, it is on one-forth of the time. If you used for a LED, it would appear about 1/4th as bright [give or take]. (Note: as some people pointed out this isn't truly proportional but let's leave it this way for simplicity. EX: 25% isn't always 1/4th the brightness.)

(If you are really electrical savvy, you could probably add a capacitor to make it also an analog output.)

How to use these pins to output:

First, you need to define the pin as output. Then, you use analogWrite(ledPin, 128); to start it. The ledPin is the PWM pin that you want to start PWM and 128 should be replaced with a number between 0 and 255; 0: 0% duty cycle (turns the pin completely off) and 255: 100% duty cycle. (turns the pin on completely)

Why can't I just turn the light on and off really fast in my code?:

Technically, you can, however, there are some problems:

• It may not be as precise as using the hardwired circuits with the Arduino
• Its simpler just to type instruction instead of having lots of "if" statements

It's not really going to make that much of a difference if the Arduino's sole purpose is to generate PWM signals. However, if you put any delays longer than 50 MS in the main loop, it will mess up the timing. With the software approach you would want to eliminate any "delay" functions since the Arduino only runs on one thread (it can only do one thing at one time). If you know what you're doing, it won't make that much of a difference dimming the light, but if you have an extra pin with PWM, you're just wasting your time with a software approach.

As others have pointed out:

You still need a resistor for your circuits to limit current and voltage. You cannot skip this.

• I have no idea what you mean by "processing power" (or whatever that phrase is suppose to mean). PWM works because it is triggered by the timers which are running independent of the running code. – baldengineer Apr 14 '13 at 22:12
• @JamesC4S I mean that it makes the overall code slower if you add the delay and it going "On" and "off." The processor can only do so many things per second before it overheats so it controls how fast it goes. – Anonymous Penguin Apr 14 '13 at 22:31
• @AnnonomusPerson You need to be much more clear in the answers you are giving. I still fail to see what your explanation has to do with "processing power." For example, you can write PWM routines that do not use delay(), using millis() for example, which would have minimal impact on the execution speed for the rest of the code. – baldengineer Apr 15 '13 at 5:34
• @AnnonomusPerson: I would say that there are two ways of implementing PWM in code: either one can have the processor perform the PWM in a loop which does nothing else except maybe decide when to exit, or else one can have a timer-tick interrupt perform the PWM. In the former situation, the processor won't be able to do anything else while the PWM is happening; in the latter, There will be limits to the accuracy and precision of the PWM timing. Hardware PWM circuits allow a chip to generate clean PWM waveforms that are accurate to within a faction of a microsecond while doing other things. – supercat Jun 14 '13 at 15:20
• Note that thanks to how vision works, a LED with 1/4 DC (or any other ratio) won't necessarily appear the corresponding fraction of full brightness. – Ignacio Vazquez-Abrams Feb 15 '14 at 22:30

A common misconception about the PWM pins is that when using PWM, it is not necessary to use current limiting resistors (with LEDs, for example).

This is not true. The PWM pins should be thought of as digital pins, which are turned on and off automatically. This means they go to the same HIGH voltage as any of the other pins.

When using LEDs with PWM, you must still using current limiting resistors. When using motors with PWM, you should (almost always) be using a transistor.

• @AnnonomusPerson No, that is not correct. You would still need current limiters for LEDs even if you had true analog outputs. LEDs need constant current sources, not constant voltage sources. – baldengineer Apr 16 '13 at 2:53
• You can get LEDs with a current-limiting resistor built in. I was so disappointed when I asked for an LED at Maplin and a suitable resistor to run it off 12V when they told me they had ones that ran directly from 12V. Heh, just wait until they try packaging a load of transistors into one package to make an AND gate or something. – Andrew Morton Feb 15 '14 at 23:14