Parts required:
1 Arduino
1 Arduino proto shield
1 Pushbutton switch
1 10 KW resistor
(brown/black/orange)
2 Jumper wires
Pushbutton Circuit
Check off when complete:
; Make sure the power is off
before building the circuit.
; FIGURE 13: Pushbutton off and on schematic.
; Build the circuit as shown in Figure 12.
; Apply power to the circuit.
; Open the Arduino IDE and load the
C4_Pushbutton_Serial program.
; Verify and upload the program to your Arduino.
; Open the Tools menu item and click on the Serial
Monitor as shown in Figure 14.
; Push the button and release it several times to verify
that you get serial output showing the button state as
shown in Figure 15.
Pushbutton Program
; FIGURE 14: Open the Serial Monitor.
through the 10 KW resistor to ground, so it ‘sees’ the five
volts at the positive side of the 10 KW resistor. Figure 13
shows what happens in both cases. Let’s build and test
this circuit to help make these concepts clearer.
; FIGURE 15: Serial Monitor showing button pushes.
// C4_Pushbutton_Serial // Pushbutton program reports when a button is // pushed and released // Constants used to set pin numbers // (constants can’t change while the program // runs) const int buttonPin = 12; // the number of the pushbutton pin // variables // (Variables may change while the program runs) int buttonState = 0; // variable the pushbutton status void setup() { // initialize Serial communications Serial.begin(9600); // set the buttonPin mode to INPUT pinMode(buttonPin, INPUT); } void loop(){ // get the state of the pushbutton buttonState = digitalRead(buttonPin); // is the button pressed? // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // Tell the world Serial.println(“Button pushed.”); } else { Serial.println(“Button not pushed.”); } delay(500); // pause for 1/2 a second }
62 April 2014