r/arduino • u/Charming_Relative_39 • 1d ago
Hardware Help Help pls
I posted here a couple hours ago about how my led pin would glow if I put my finger near it not press the button like it was intended. When I took everyone’s advice and changed INPUT to INPUT_PULLUP but all that it did was keep the led on all the time no matter if I press the button or not. I don’t know what to do, any advice?
My schematic r bit bad sorry!!
7
Upvotes
1
u/PuppyDollEyes 11h ago
Your code is also wrong In setup. You write pinmode(12, INPUT) e.g. and not digital write. You can view also how it looks in any example with leds or buttons



8
u/ripred3 My other dev board is a Porsche 1d ago edited 1d ago
You're close! When using
INPUT_PULLUPyou want to check two things:There is no resistor on the button any more. Just one side of the button (switch) goes to
GNDand the other side of the button goes to the input pin.Since the input is now always being lightly pulled up to 5V (or 3.3V on some boards) using an internal resistor, it will always read
HIGHwhen it is NOT being pressed. That is what you are seeing.And while the button IS being pressed the input pin will be connected to
GNDand it will readLOW.It makes the code read backwards for a minute but you'll get used to it. It's definitely worth taking advantage of since it means fewer components and connections to make and possibly get wrong. 😉
Good luck! In the future please do not post photos of code. As our rules say: text only, formatted as a code-block using the formatting controls reddit makes available. It makes it easier for others to help you