Tutorial.InputPullupSerial History

Hide minor edits - Show changes to markup

April 11, 2013, at 12:03 PM by Roberto Guido - minor typo, thanks Alfredo Albánez for alert
Changed lines 50-51 from:

Now that your setup has been completed, move into the main loop of your code. When your button not is pressed, the internal pull-up resistor connects to 5 volts. This causes the Arduino to report "1" or HIGH. When the button is pressed, the Arduino pin is pulled to ground, causing the Arduino report a "0", or LOW.

to:

Now that your setup has been completed, move into the main loop of your code. When your button is not pressed, the internal pull-up resistor connects to 5 volts. This causes the Arduino to report "1" or HIGH. When the button is pressed, the Arduino pin is pulled to ground, causing the Arduino report a "0", or LOW.

February 11, 2013, at 11:15 AM by Roberto Guido - removed links to internal editorial site
Changed lines 5-6 from:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It monitors the state of a switch by establishing serial communication between your Arduino and your computer over USB.

to:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It monitors the state of a switch by establishing serial communication between your Arduino and your computer over USB.

Changed lines 52-53 from:

The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an int datatype. Call this variable sensorValue, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

to:

The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an int datatype. Call this variable sensorValue, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

December 30, 2012, at 05:55 PM by David Cuartielles -
Changed line 66 from:
to:
May 02, 2012, at 03:36 AM by Scott Fitzgerald -
Changed line 66 from:
to:
March 28, 2012, at 06:01 PM by Scott Fitzgerald -
Deleted lines 28-29:

If you disconnect the digital i/o pin from everything, you may see 1 and 0 erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW.

March 27, 2012, at 06:22 PM by Scott Fitzgerald -
Changed lines 25-28 from:

Connect two wires to the Arduino board. The black wire, connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.

to:

Connect two wires to the Arduino board. The black wire connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.

Changed lines 44-45 from:

Next, initialize digital pin 2, the pin that will read the output from your button, as an input with the internal pull-up resistor enabled:

to:

Next, initialize digital pin 2 as an input with the internal pull-up resistor enabled:

Changed lines 52-53 from:

Now that your setup has been completed, move into the main loop of your code. When your button is pressed, 5 volts will freely flow through your circuit, and when it is not pressed, the input pin will be connected to ground through the 10-kilohm resistor. This is a digital input, meaning that the switch can only be in either an on state (seen by your Arduino as a "1", or HIGH) or an off state (seen by your Arduino as a "0", or LOW), with nothing in between.

to:

Now that your setup has been completed, move into the main loop of your code. When your button not is pressed, the internal pull-up resistor connects to 5 volts. This causes the Arduino to report "1" or HIGH. When the button is pressed, the Arduino pin is pulled to ground, causing the Arduino report a "0", or LOW.

Changed lines 62-64 from:

Now, when you open your Serial Monitor in the Arduino environment, you will see a stream of "0"s if your switch is open, or "1"s if your switch is closed.

to:

Now, when you open your Serial Monitor in the Arduino environment, you will see a stream of "0"s if your switch is closed, or "1"s if your switch is open.

The LED on pin 13 will illuminate when the switch is HIGH, and turn off when LOW.

March 16, 2012, at 11:53 PM by Scott Fitzgerald -
Changed lines 5-6 from:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It also shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB. Additionally, when the input is HIGH, the onboard LED attached to pin 13 will turn on; when LOW, the LED will turn off.

to:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It monitors the state of a switch by establishing serial communication between your Arduino and your computer over USB.

Additionally, when the input is HIGH, the onboard LED attached to pin 13 will turn on; when LOW, the LED will turn off.

Deleted lines 22-23:
Changed lines 25-28 from:

Connect two wires to the Arduino board. The first, black, connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because the connection to ground is completed.

to:

Connect two wires to the Arduino board. The black wire, connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.

Changed lines 48-51 from:
  • PICK UP HERE!!!!!
to:

The following line make pin 13, with the onboard LED, an output :

pinMode(13, OUTPUT);

March 16, 2012, at 11:25 PM by Scott Fitzgerald -
Changed lines 5-7 from:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It also shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB.

to:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It also shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB. Additionally, when the input is HIGH, the onboard LED attached to pin 13 will turn on; when LOW, the LED will turn off.

March 15, 2012, at 04:54 AM by Scott Fitzgerald -
Changed line 36 from:
to:
March 15, 2012, at 04:49 AM by Scott Fitzgerald -
Changed line 12 from:
  • breadboar
to:
  • breadboard
Changed lines 19-22 from:

to:
March 15, 2012, at 03:03 AM by Scott Fitzgerald -
Changed lines 5-9 from:

This example shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB.

to:

This example demonstrates the use of INPUT_PULLUP with pinMode(). It also shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB.

Changed lines 12-14 from:
  • breadboard
  • hook-up wire
to:
  • breadboar
  • hook-up wire
Changed lines 19-22 from:

to:

Changed lines 25-30 from:

Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

to:

Connect two wires to the Arduino board. The first, black, connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because the connection to ground is completed.

If you disconnect the digital i/o pin from everything, you may see 1 and 0 erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW.

Changed lines 44-47 from:

Next, initialize digital pin 2, the pin that will read the output from your button, as an input:

pinMode(2,INPUT);

to:

Next, initialize digital pin 2, the pin that will read the output from your button, as an input with the internal pull-up resistor enabled:

pinMode(2,INPUT_PULLUP);

  • PICK UP HERE!!!!!
March 15, 2012, at 02:31 AM by Scott Fitzgerald -
Changed line 78 from:
to:
March 15, 2012, at 02:30 AM by Scott Fitzgerald - added example
Changed line 64 from:
to:
Changed line 78 from:
to:
March 15, 2012, at 02:11 AM by Scott Fitzgerald - page creation based on digitalreadserial
Added lines 1-78:

Share