Why the led is not turning on when I press the button?
Hello daver2ds
Post a none-Fritzing schematic to see how we can help.
Because there's nothing in your code to make it do.
Oh wait, we can't see your code. Hint.
Also, if that diagram is accurate, didn't squint too long at it, you have not wired the LED correctly at all. Maybe.
a7
Because you make a short circuit between 5V and Gnd if you press the button.
Hi, @daver2ds
Welcome to the forum.
How do you expect the UNO to do anything if the button is not connected to an I/O pin?
If fact your button will short the 5V supply to gnd.
Your UNO will not switch the LED because it is not connected to an I/O pin.
Your LED 's two pins are both connected to gnd.
Tom..
Hi,
when you press the button, you short-circuit +5V and GND.
Actually it makes sense! Thank you and the others! Still a beginner here😅
Even the simplest circuits can benefit from a proper schematic. I suspect even more so for tyros. This standard view shows at a glance the problems with the circuit.
Draw a schematic of the circuit. NOT a copy of the fritzing diagram, a representation of the physical components you have in front of you. Drawing software isn't required, just make one by hand a post a picture of it.
You might have the LED wired backwards.
Not at all, I tried both direction, connecting the just the led and resistor and of course it works, trying a sample code with the button and it works so the button is not the problem, so i guess there is a problem with this kind of circuits, the button doesn't act like a physical switch,but just works with "digitalRead" or maybe another reason I don't understand
Sure, if you tried it both ways then it might not be the problem. But there is no mysterious cause, like the one you suggested. There is no problem with a basic light switch circuit, go turn your room light on and off if you don't believe me. You have just made some wiring error. It would be easier to explain to you if you had followed the advice to post a schematic. Personally, I am not going to add anything more until you do.
If you feel really lazy, just take photos of your hardware and post those.
Else, simplify your circuit. Leave out the switch, just connect the LED and resistor and play until it comes on. Then add the switch.
Yeah sure here it is. Sorry if can't see, anyway blue is gnd and white 5v. In the third image the led should turn on through the button because that side is "connected". In the second I just should the working of the led and it's correct direction just by moving one side of the resistor. As said I already checked the working of the button with a sample code and it works.
I am sure you still have something wrong, but at this point if you are convinced you don't then
measure the resistance of the switch when pressed.
It is possible if unlikely that you have some dodgy switch.
You could also try using a jumper wire right across the switch.
And so forth.
a7
Hi,
Do you have a DMM?
Measure the resistance of the button out of circuit.
Then we will get you to measure some voltages around your circuit.
Thanks.. Tom...
Try moving everything down a few rows, there may be a defect in the protoboard.
Hi,
The Button legs may not all be going into the protoboard completely.
Tom..
Yes, many components are not fully breadboard compatible. They just happen to barely snap in. I've seen it with lots of other components.
PCB DIL switch arrays are the same, different "pin" length for each manufacturer.
Tom..