I would like to do,

analogWrite(100,3); analogWrite(200,6);

at the same time. But the problem is that only the led on pin 3 lights up. I want both to light up at the same time. I've heard about direct port manipulation, but I can only find an alternate for digitalWrite() but I couldn't find one for analogWrite(). Can someone please help me with just a simple example on just how to do the above operation?

I'm using arduino uno.

1 Answer 1


You have your parameters the wrong way round:

analogWrite(2, 100);
analogWrite(6, 200);

However: pin 2 on the Uno cannot do PWM, so you will have to pick a different pin. Look for the pins marked with ~ - they are the PWM pins. On the Uno that is pins 3, 5, 6, 9, 10 and 11.

  • yeah I'm sorry it's pin 3. Now how to i turn both on at the same time? Apr 18, 2017 at 11:29
  • Just like that. When you run analogWrite() it starts PWM on that pin and it keeps going until you tell it otherwise. If you aren't getting anything out then you have probably broken that pin through misuse or doing something else in your code that's stopping PWM.
    – Majenko
    Apr 18, 2017 at 11:30
  • No. if i use pin 6 first, then pin 3. The pin 6 lights up and not pin 3 Apr 18, 2017 at 11:33
  • And if you do it the other way around? And NOT PIN 2.
    – Majenko
    Apr 18, 2017 at 11:33
  • analogWrite(6, 100); analogWrite(3, 200); This turns on pin 6 Apr 18, 2017 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.