# Button is giving me the same voltage when pressed or released

I am doing a simple program with my PIC (PIC24FJ1024GB610).

When a button is pressed the LED is turned on, when it is released LED is turned off.

I presumed that the input pins have a pullup resistor connected to it inside the microcontroller by default, because when I measured the voltage across the pin when it was floating, it was 3.3V

simulate this circuit – Schematic created using CircuitLab

In a pull-up configuration, Vinput is 3.3V when the button is released, and 0V when the button is pressed.

However, when the button is pressed or released I measured the same value which is 3.3V

I am using a breadboard to design the circuit, and a pic development board: Explorer16/32

I added the code FYI.

#include "System.h"
#include <xc.h>

/*

P44 is input RB15
P88 is output RF1 5V tolerant

*/

#define ANALOG  1
#define DIGITAL 0

#define INPUT   1
#define OUTPUT  0

//BTN RB15
#define BTN_ANS     ANSBbits.ANSB15
#define BTN_TRIS    TRISBbits.TRISB15
#define _INPUT      PORTBbits.RB15

//LED RF1
#define LED_TRIS    TRISFbits.TRISF1
#define _OUTPUT     _LATF1

int main (void)
{
//LED_ANS = DIGITAL;
LED_TRIS = OUTPUT;

_OUTPUT = 0;

BTN_ANS = DIGITAL;
BTN_TRIS = INPUT;

while(1)
{
if(_INPUT == 1)
_OUTPUT = 1;
else
_OUTPUT = 0;
}

return 0;
}

• Assuming a pullup isn't a great idea; if you actually wanted to know without analyzing the code, briefly use an external resistor (maybe something around 33K) to ground and see what intermediate voltage you get, from which you can not only see if an internal pullup is present, but calculate its value. Commented Oct 6, 2020 at 3:59
• In terms of your claim that the 3v3 remains when the switch nominally connected to ground is closed, this suggests a faulty switch or faulty wiring. Maybe disconnect it and investigate the switch itself with a continuity tester. Or substitute a jumper wire installed/removed from the breadboard for the switch. Few switches will insert into a breadboard in a way which makes reliable electrical contact though they might falsely seem connected to it. When you say "measure" you do mean with a voltmeter and not only the result for your program, right? Commented Oct 6, 2020 at 4:01
• The reason I assumed that, because when I measured the voltage of the pin (by its self) I found the voltage to be 3.3V. Commented Oct 6, 2020 at 4:06
• @ChrisStratton I tested the continuity of the button, I measured the resistance of the button with a DMM, when released it had a high resistance when pressed resistance is almost 0. Commented Oct 6, 2020 at 4:08
• I will test it with an external resistor, but what bothers is, why is the voltage of the pin = 3.3V, when it isn't connected. Commented Oct 6, 2020 at 4:10

## 1 Answer

Buttons rarely make reliably sound electrical contact with breadboards.

Based on comments, that appears to have been your issue, along with possible quality issues in the button itself.

Sometimes there are thing you can go to make something work well enough for a quick test, eg, I had some buttons where twisting each of the pins 90 degrees would make them better fit the breadboard contacts and so work a useful fraction of the time. But really, breadboards are not for reliability, especially not with anything that is not a DIP IC or wire lead component of suitable wire gauge.

You would be better off soldering your button to a circuit board (perhaps a pre-made prototype board), or buying some pre-made assembly of buttons, and wiring that into your MCU board directly.

• I will keep that in mind, Thanks Chris Commented Oct 6, 2020 at 4:43