Button Serial Print

Hello all!

I'm very new to Arduino and running into a probably stupid question...

I'm trying to read the button input simply as in the attached image, but when the button is pressed, there isn't any signal... However, when I change line 5 from "INPUT" to "INPUT_PULLUP", the signal shows even if it is reversed 1 and 0. I fail to understand why...

Your image suggests a floating input

Plz Add a Pullup 5-10 K resistor between the button.
1 Vcc--------R------button------Pinout 10

  •    / 
    
  •       \GND
    

Hello xyli21

Take a view to gain the knowledge how to adapt a button.

hth

Have a nice day and enjoy coding in C++.

Are you try it on real Arduino and button or on emulator?

I'm using a 2-pin push button on a real Arduino, but it didn't work, so I try to replicate it in the emulator. My goal is to get a signal 0 when the button is not pressed and a 1 when it is pressed...

According your schematic you should get inverse signal - 0 when button is pressed and 1 otherwise

Actually, I'm not getting anything but 0 with the schematic I showed... But when I have INPUT_PULLUP instead of the INPUT, I have the reversed as you said...

Ah, I got it now. I needed a resistor and to connect the pin with the ground instead of with 5v... Thank you everyone!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.