I am trying to run build in LED when pin 3 is connected to pin 2.
Pin 3 is setup to be HIGH and pin 2 is not set up to be anything so logic tells me it is LOW by default.
When i touch PIN2 with PIN3 using a jumper wire, i expect to get 2 blinks.
I get 4
Welcome
Well done for using code tags. Not quite the right section but you can hit the flag and ask a moderator to change it for you.
A floating pin could be anything. Best not to let them float. Post a schematic. Generally a button, which is what you seem to be creating is done by setting the pin to input pull-up and then grounding it to switch
Look up debouncing also. You also should look up edge detection and state change code. Your current code will just keep running over and over if 2 is high. I’m surprised you get a standard number of blinks other than if your reflexes and the delay happen to work that way
I dont know what u mean by floating pin. Do i need a varible instead of a float value, is that what you are saying ?
Either way, i dont think this will make a difference. It makes sense both ways.
Schematics of what ?
All am doing is connecting pin 2 and 3 with a jumper wire in hopes that built in led will blink 2 times as per code.
I get 3 blinks if i remove the jumper wire fast enough but normally its 4 blinks.
This is nothing to do with the hardware, i am simply lacking something in the code. I dont understand why its doing it.
To me, it makes sense that it will blink 2 times every time i jump the wires, but it blinks 3 or 4 times instead.
A floating pin is a pin that has not been pulled high or low so could be anything. Not a good thing if you want a reliable button. Use the internal pull-up resistor to set the pin high then ground it to pull low and low equals button pushed
see the diagram above. Pin 20, D5, is not floating. it is pulled up by that external resistor when the switch is open
pin 25 is not floating. it is pulled down to ground by that external resistor when the switch is open
most of the other pins on the right are open and could be at any voltage from ground to 5V. they are floating. if you don't make a pin go to a voltage you choose, it can wander.
if you make pin 2 your ground path and pull it to ground with INPUT_PULLDOWN you run LED current through the microscopic internal resistor. you make your Arduino a fuse. avoid using the microcontroller as a current source or sink.
It is not “sensitive” you are just using it wrong. You have not “told” the pin to be any specific voltage so it is happily wondering around being whatever voltage seems nice and your code is running whenever it’s condition is met
Ok two people tell me 2 different things.
How to set pin 2 voltage then ?
When pin is set to HIGH by the code, its 5V
What do you mean i didnt specify any voltage ?
I kinda understand that i just told it to be high but its at 5V all the time according to my multimeter.
Do i need an oscilloscope to see that it actually goes randomly LOW ? Is that what am going to discover ?
Pin 2 is set as an input. It has no voltage set. It will be whatever voltage it feels like and therefore can activate your code (when it’s voltage is ~5). It will be 5v when connected to your high output pin 3 but it will also be 5v at other random times. It is floating!
You have been given a schematic and detailed instructions. To make a button stop what you are doing. It is wrong! Change to what has been advised. Set your buttonPin to input pull-up and connect it to ground when you want to “press’ your button
If you do this your pin will always be physically pulled up to 5v by the internal resistor and will read HIGH until it is grounded when it will read LOW. Now you have a clean high low logic to detect
Ok i begin to understand.
So i need to ground pin 2 in order for it to have 0V at all times or is there a way to set it to 0 with code ?
I dont want to deal with hardware right now. I am just trying to understand programming logic and some issues it has with the hardware on which it runs.
No. You need to use hardware, a resistor! There is one inside the arduino which is activated by the code input pull-up but it will change your pin to 5v not 0v. You ground the pin to low to activate your button.
If you want a HIGH for activate the button you need an external resistor to pull to ground
One other thing to understand is you posted in the wrong section, so I have moved it here. Please read the description of the section you posted in and understand it is only for installation of the IDE not for your project.