Love-o-Meter project - LEDs super dim

I checked my wires, resistors, and code many times, but I cannot seem to find the cause. The LEDs worked fine in the previous projects, and I get correct temperature and voltage (as seen in the serial monitor), and the LEDs light up one after another as I press onto the sensor, so I know the code is correct. I double-checked my resistors, and they are the 5-band ones, 220 Ohms. I also tried moving the LEDs to different rows and still got the same result. I'm including my code (which is basically the exact same code from the book), but just in case there is something wrong with it:

const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup() {
  Serial.begin(9600);

  for(int pinNumber = 2; pinNumber < 5; pinNumber++){
      pinMode(pinNumber, OUTPUT);
      pinMode(pinNumber, LOW);
  }

}

void loop() {

  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal/1024.0)*5;

  Serial.print(", Volts: ");
  Serial.print(voltage);

  float temperature = (voltage - 0.5)*100;

  Serial.print(", degrees C: ");
  Serial.println(temperature);

  if (temperature < baselineTemp+2){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }

  else if (temperature >= baselineTemp+2 && temperature < baselineTemp+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }

  else if (temperature >= baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }

  else if (temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }

  delay(1);

}

Also including a picture here:

Thanks!

Think about that line for a minute. You'll see it.

Hint: if you move one of the wires from pins 2, 3, or 4 to the 5V rail on the breadboard, your LED will be nice and bright. So why isn't it just as bright when hooked up to a pin?

Extra hint: both LOW and INPUT have a numerical value of 0.

All looks good.
Do not assume people here have your book (I happen to have one).
Luckily this is all fairly basic, so most will see how it is supposed to work from your sketch and picture.

Try fiddling with your gnd cable. That may fix a semi loose contact. Also fiddle near the uno!
What type of battery do you use? The small block ones that tend to be delivered with these kits may last just a few hours....

I see @van_der_decken found your problem!

These projects in the IDE:
IDE >> FILES >> EXAMPLES >> 10.STARTER KIT BASIC KIT >> (p02..p15)

@van_der_decken Omg!! Thank you so much!!

@build_1971 Thank you so much for taking the time to respond! I was so sure I had everything correct. I feel stupid now lol!

Your resistors does not look like 220Ω.

@van_der_decken I am curious, though, since I called the wrong function, did the second line "pinMode(pinNumber, LOW)" get "ignored" (since the argument was invalid)? If so, did the LEDs not light up by default when the sensor was not touched? And why did they still light up very, very faintly one by one when the sensor was touched?

pinMode(x, LOW);
Sets the pinmode to INPUT
Both LOW and INPUT are defined as 0...

INPUT has a very high resistance (around 20 Mohm). I am surprised you can see the LED shining at all... (as it is a factor 100000 more than 200 ohms)
Are you in the dark?

Don't feel stupid!
Just learn!
It is pretty tough in the beginning.
Many things can go wrong. And will go wrong (as Murphy said).

Ignored, no. Invalid, no. Your line evaluated to pinMode(pinNumber, 0);. Which is the same thing as saying pinMode(pinNumber, INPUT);.

The reason your LEDs were so dim was that doing a digitalWrite(pinNumber, HIGH); while the pin is defined as an INPUT on an ATmega328P turns on the internal pullup resistor on the pin (i.e. doing the equivalent of pinMode(pinNumber, INPUT_PULLUP);. The value of the internal pull-up is, if I recall correctly, between 20K and 50K. So your LEDs were getting in the range of 0.1mA. LEDs are much more efficient than they were decades ago, but 0.1mA is still not very much current to work with.

To sum up: with the pin configured as an INPUT, digitalWrite(pinNumber, LOW); turned off the large pullup, and the LED went out. digitalWrite(pinNumber, HIGH); turned on the large pullup, and the LED got just enough current to barely turn on.

I'll wager things brightened by orders of magnitude once you changed that pinMode(pinNumber, LOW); in setup() to digitalWrite(pinNumber, LOW); and left the pin configured as an OUTPUT rather than changing it back to an INPUT.

Ah, that explains!

The AVR doesn’t actually switch in a discrete 20–50 K resistor.

Engaging the pull-up turns on a weak current source implemented inside the I/O cell. Its effective resistance behaves like something in the 20 - 50 kΩ range.

Talking about it as a resistor is a convenient shorthand. If it was a resistor, I expect the datasheet would not need a range.

In any case, it's weak.

a7

Thank you for the clarification!

I was not in the dark. I actually had everything set up under a desk lamp. But you were right. At first I thought none of them lit up because they were so dim. Since they turned on one by one, I kind of had a reference for what a "lit" LED looked like compared to an unlit one. I looked closer and then saw a tiny bit of shine in the center of the LED so that's why I thought my code was working. I just couldn't figure out why there seemed to be so little power going to them.