Switches and push buttons: Difference between revisions

From wikiluntti
Line 17: Line 17:
A double pole single throw push button micro switch (DPST) is a widely used button. Push button switches are often color coded to indicate their function.
A double pole single throw push button micro switch (DPST) is a widely used button. Push button switches are often color coded to indicate their function.


Three methods to wire
Three methods to wire because Arduino has built-in internal resistors:
# External pullup or pulldown resistor: Use <code>pinMode( Button_pin, INPUT);</code> in the setup.  
# External pullup or pulldown resistor: Use <code>pinMode( Button_pin, INPUT);</code> in the setup.  
# Internal resistor (20k-50k Ω): Use <code>INPUT_PULLUP</code> in setup <code>pinMode( Button_pin, INPUT_PULLUP);</code>. The default value is <code>HIGH</code> (1) and by pressing the button the state goes to <code>LOW</code>.  
# Internal resistor (20k-50k Ω): Use <code>INPUT_PULLUP</code> in setup <code>pinMode( Button_pin, INPUT_PULLUP);</code>. The default value is <code>HIGH</code> (1) and by pressing the button the state goes to <code>LOW</code>.  
# The bad method: Use <code>pinMode( Button_pin, INPUT);</code> in the setup without any resistors. The default value will float between 0V and 5V: there is no internal or external  
# The bad method: Use <code>pinMode( Button_pin, INPUT);</code> in the setup without any resistors. The default value will float between 0V and 5V: there is no internal or external  
voltage reference for the push button.
voltage reference for the push button.

Revision as of 21:50, 23 July 2023

Introduction

Simple idea of switch and digital pins

The idea is given in the image below. If the switch is open, the pin is connected through the resistor to 5V, but when switch is closed, the pin is grounded to 0V. The resistor is called pull-up resistor, and prevents shorting to ground when the switch is closed. The other method is pull-down resistor.


See more different switches at https://learn.sparkfun.com/tutorials/button-and-switch-basics/all

Theory A: Simple switch

Theory B: Push Button

DPST button and function

A double pole single throw push button micro switch (DPST) is a widely used button. Push button switches are often color coded to indicate their function.

Three methods to wire because Arduino has built-in internal resistors:

  1. External pullup or pulldown resistor: Use pinMode( Button_pin, INPUT); in the setup.
  2. Internal resistor (20k-50k Ω): Use INPUT_PULLUP in setup pinMode( Button_pin, INPUT_PULLUP);. The default value is HIGH (1) and by pressing the button the state goes to LOW.
  3. The bad method: Use pinMode( Button_pin, INPUT); in the setup without any resistors. The default value will float between 0V and 5V: there is no internal or external

voltage reference for the push button.