r/arduino • u/AbruptOyster456 • Oct 15 '26
Beginner Help
(Solved)
I know this is going to be a dumb fix, but for the life of me I cannot figure out why the LED is not coming on. I tried the LED both ways but still nothing. (220ohm resistor used)
const int slidepin = 2;
const int ledpin = 9;
int swstate = 0;
void setup()
{
pinMode(slidepin, INPUT);
pinMode(ledpin, OUTPUT);
Serial.begin(9600);
}
void loop(){
swstate = digitalRead(slidepin);
if(swstate == 0){
digitalWrite(ledpin, HIGH);
Serial.println("HIGH");
}
else{
digitalWrite(ledpin, LOW);
Serial.println("LOW");
}
delay(100);
}


2
Upvotes
6
u/GypsumFantastic25 Anti Spam Sleuth Oct 15 '26
The LED is connected to the top + rail.
The top + rail isn't connected to anything.
1
u/ventus1b Oct 15 '26
In your images, the second pin of the LED is connected to the top red rail, which isn’t connected to anything.
1
u/n_sh_44 Oct 15 '26
Since the serial monitor prints HIGH, the code is running that branch and pin 9 is being driven high, so it's almost certainly wiring, not code. Quick checks: pull the LED and resistor off and put a multimeter (or the LED+resistor alone) from pin 9 to GND, you should see ~5V. Make sure the LED's short leg goes to a GND that's actually connected to the Arduino's GND (a lot of breadboards have the power rails split in the middle, so the rail can look connected but isn't). And confirm the resistor and LED are in different rows, not both legs in the same 5-hole strip, which shorts them out.
Separate issue: with pinMode(slidepin, INPUT) the switch pin floats when the switch is open, so it'll read random values. Use INPUT_PULLUP and wire the switch between pin 2 and GND (it'll read 0 when closed).