This is my code:

void setup() {
    pinMode(2, OUTPUT);

void loop() {
    digitalWrite(2, HIGH);

This is my circuit: enter image description here


enter image description here

Light A and B doesn't work when I plug the red cable to 4 and 5. All the other lights works just fine.

  • Did you try using a different part? Jun 6, 2017 at 1:52
  • Do you mean to another 7-segment display ? I don't have one right now but I can buy one tomorrow. I was hoping that I have any type of error. I don't have any error ?
    – EAX
    Jun 6, 2017 at 1:58
  • You don't have enough code to have any fatal errors. You haven't proven that the pins are the correct ones though. Jun 6, 2017 at 2:13
  • 1
    Be sure you have a current-limiting resistor in series with any LED segments that you light up, in either the ground side or the high side. Do segments A or B light up when you apply 5 V instead of trying to drive them with an Arduino IO? Jun 6, 2017 at 3:32

1 Answer 1


As jwpat7 states, you need a current-limiting resistor for each segment, between the data pin (on the Arduino) and the segment pin (on the display). Your Fritzing diagram only shows one resistor in the circuit, from the common cathode to GND on the Arduino.

You can not, or should not, share one resistor to ground (assuming that you have a common cathode seven segment display). You need a current-limiting resistor on each anode (again, (assuming that you have a common cathode seven segment display).

If you are sharing the current-limiting resistor between all segments, and then try to light more than more segment, at a time (which it sounds like you are doing ("when I plug the red cable to 4 and 5"), then the current through the current-limiting resistor will increase, and as a result, the voltage will change significantly enough, such that there is not sufficient voltage drop across the LED in order to make it light up.

Remember, 0.7 V is dropped across the LED.

Test each on the segments, one at a time, to make sure they all work, as Ignacio states in his comment.

Also, your sketch should be more complete, along the lines of:

void setup() {
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);

void loop() {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);

Connect up all of the pins, using a current-limiting resistor on each anode, and then try it programmatically.

If your seven segment display is a common anode, then, again, you need a resistor between each cathode and the data pins, and bring the pins LOW to light the corresponding segment, i.e.

    digitalWrite(8, LOW);

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.