0

I'm using the Arduino UNO and started noticing some funny behavior when I was trying a few basic projects. Specifically when trying to write an analog signal through one of the PWM pins, then a digital signal through another.

Using some LED's connected to a few different permutations of pins 8-13, I found that when I have an analog output set for one of the pins (in this case 9, 10, or 11 as they're the only one's of the set capable of PWM) and then try to output a digital signal from a different pin to another LED the digital signal seems much weaker. That is, the LED shines very very dim.

The pins 2-7 work fine. Does the behavior described above indicate anything wrong with the arduino? are those pins potentially damaged, or is there something I'm not understanding here?

My code:

void setup()
{}

void loop()
{
   analogWrite(9, 255);
   delay(1000);
   analogWrite(9, 0);
   delay(2000);
   digitalWrite(8, HIGH);
   delay(1000);
   digitalWrite(8, LOW);
   delay(2000);
}

Diagram

4
  • 2
    It would help to see your actual circuit. Are you using resistors? Are they all the same value? Ditto with the LEDs – all the same, or behave the same if you swap a dim one with a bright one?
    – dlu
    Jan 13, 2016 at 1:05
  • Sounds like an electrical problem. Please post your schematic and also your code.
    – Nick Gammon
    Jan 14, 2016 at 8:20
  • just put the schematic and code up. also I've tried switching out the LED's but I'm still got the same result.
    – Matthew R
    Jan 16, 2016 at 18:08
  • 1
    Is the code shown here complete? I don't see any output setups.
    – JRobert
    Jan 16, 2016 at 18:36

2 Answers 2

4

I tested your code and it does indeed behave the way you said. But that is because you have not declared any pins as output.

analogWrite does this for you automatically in the library, however digitalWrite does not. This is because sending a digital pin HIGH when it is INPUT turns on the internal pull-up resistors. These are around 50k. Thus you will only see very dim output on the LED. Add this line to setup:

 pinMode (8, OUTPUT); 

(And preferably pin 9 as well, just in case you decide to change to digital writes later).

0

The pin groups your describe are on different ports of the chip which have different current sourcing ratings. I'm sure you'll find an even brightness using similar LEDs on all pins and using a 1K res in series with each led to limit current. Also , to ensure the sourcing transistors are ON within the chip, be sure to declare the pins as output when required.

Your Answer

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

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