# analogWrite command

**URL:** <https://forum.arduino.cc/t/analogwrite-command/679690>\
**Category:** Programming\
**Created:** [October 23, 2020, 10:38am UTC](https://forum.arduino.cc/t/analogwrite-command/679690 "2020-10-23T10:38:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SierraGolfMike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sierragolfmike/32/1126779_2.png) [@SierraGolfMike](https://forum.arduino.cc/u/SierraGolfMike)\
**Post date:** [October 23, 2020, 10:38am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/1 "2020-10-23T10:38:51Z")

</div>

I watched a tutorial video on RGB LEDs and they were using Pins 8, 9 & 10 doing analogWrites to each pin to get various colours. I assumed that analog write commands could only be used on PWM pins, of which 8 isn't 1. Have I missed something here?

Puzzled

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [October 23, 2020, 10:41am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/2 "2020-10-23T10:41:17Z")

</div>

Which Arduino board was being used ?

Please provide a link to the video

---

<div class="post-metadata">

**Author:** ![SierraGolfMike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sierragolfmike/32/1126779_2.png) [@SierraGolfMike](https://forum.arduino.cc/u/SierraGolfMike)\
**Post date:** [October 23, 2020, 10:50am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/3 "2020-10-23T10:50:08Z")

</div>

> UKHeliBob:  
> Which Arduino board was being used ?
> 
> Please provide a link to the video

It is an arduino UNO (Elegoo) and the video link is [https://www.youtube.com/watch?v=kj2br03bOuk&feature=emb\_logo](https://www.youtube.com/watch?v=kj2br03bOuk&feature=emb_logo)

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [October 23, 2020, 11:12am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/4 "2020-10-23T11:12:17Z")

</div>

Bad tutorial. Pin 8 is used for the Red LED and when switching from digitalWrite() to analogWrite() he only ever uses 0 and 255 for the red value. Those two are equivalent to digitalWrite(8, LOW) and digitalWrite(8, HIGH). As long as you don't try to get any color with an intermediate amount of red it will appear to work. Any value below 512 will act the same as 0 and any value of 512 or higher will act as 255 (that's how analogWrite() works on non-PWM pins).

He should have moved Red to a PWM pin when switching from digitalWrite() to analogWrite().

---

<div class="post-metadata">

**Author:** ![fionning\_macara](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@fionning\_macara](https://forum.arduino.cc/u/fionning_macara)\
**Post date:** [October 23, 2020, 11:16am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/5 "2020-10-23T11:16:09Z")

</div>

Perhaps he should drink _less_ coffee?

---

<div class="post-metadata">

**Author:** ![SierraGolfMike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sierragolfmike/32/1126779_2.png) [@SierraGolfMike](https://forum.arduino.cc/u/SierraGolfMike)\
**Post date:** [October 23, 2020, 12:09pm UTC](https://forum.arduino.cc/t/analogwrite-command/679690/6 "2020-10-23T12:09:28Z")

</div>

I really thought I had missed something! Thanks for the confirmation that my assumption was correct!

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [October 23, 2020, 1:33pm UTC](https://forum.arduino.cc/t/analogwrite-command/679690/7 "2020-10-23T13:33:09Z")

</div>

> fionning\_macara:  
> Perhaps he should drink _less_ coffee?

Who? @ johnwasser? Probably 😃

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:48am UTC](https://forum.arduino.cc/t/analogwrite-command/679690/8 "2021-05-06T00:48:57Z")

</div>


