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!

That's not reversed. For some reason people really want the pressed button to read 1. 1 has to mean on and 0 has to mean off. But it isn't this way. The more common way to wire a button is to have it connect to ground so it reads 0 when pressed and 1 when not pressed. There are several engineering reasons for this. But the point is not to get caught thinking that 1 and on are always linked.

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