Click the above photos for details.
Have you ever used a resistor with a button on a breadboard so you can use the button to control something when the button was pressed or not pressed, with internal resistors on the input of your microcontroller you can avoid needing that resistor on the breadboard. This is a simple tutorial to demonstrate the use of an internal pull-up resistor seen on the left button in photo and an internal pull-down resistor seen on right button in photo that are internally available on a PIC32 microcontroller input pin, this example demonstrates them being used with a button to turn on or off an LED on each side of the microcontroller.
Example internal pull-up resistor code:
pinMode(3, INPUT_PULLUP);
Example internal pull-down resistor code:
pinMode(17, INPUT_PULLDOWN);
To read the current value on the input use:
digitalRead(3);
or
digitalRead(17);
See the attached file for the complete code example using each one, an internal pull-up and an internal pull-down resistor. The way the code is written is that when the input pin reads high (3.3 volts) the LED is on and when the input pin reads low (0 volts) the LED is off.
Note (*) : Some of the PIC32 microcontroller versions only support internal pull-up resistors on I/O pins, so be sure to reference the datasheet if you are trying to use internal pull-down resistors on input pins. This code example is using a PIC32MX250F128B microcontroller which has both pull-up and pull-down internal resistors available to be used. Checking the datasheet for the PIC32MZ and PIC32MX1XX/2XX microcontroller versions, they have pull-up and pull-down internal resistors available.
Example internal pull-up resistor code:
pinMode(3, INPUT_PULLUP);
Example internal pull-down resistor code:
pinMode(17, INPUT_PULLDOWN);
To read the current value on the input use:
digitalRead(3);
or
digitalRead(17);
See the attached file for the complete code example using each one, an internal pull-up and an internal pull-down resistor. The way the code is written is that when the input pin reads high (3.3 volts) the LED is on and when the input pin reads low (0 volts) the LED is off.
Note (*) : Some of the PIC32 microcontroller versions only support internal pull-up resistors on I/O pins, so be sure to reference the datasheet if you are trying to use internal pull-down resistors on input pins. This code example is using a PIC32MX250F128B microcontroller which has both pull-up and pull-down internal resistors available to be used. Checking the datasheet for the PIC32MZ and PIC32MX1XX/2XX microcontroller versions, they have pull-up and pull-down internal resistors available.

pic32_internal_pullup_pulldown_example.pde |