Skip to content

Button & Switch Wireling Tutorial

<

This tutorial covers how to handle basic inputs from Wirelings that utilize the analog line. This includes the Small Button Wireling, Large Button Wireling, Switch Wireling, and even the Digital Hall Effect Sensor Wireling. Program this as an interrupt to run asynchronous functions within your code loop.

Large Button Technical Details

FMS8HSMA Specs

  • Height 7mm

    TinyDuino Power Requirements

    • Voltage: 3.0V - 5.5V 

    Pins Used

    • A5/SCL - I²C Serial Clock line
    • A4/SDA - I²C Serial Data line 

    Dimensions

    • 10mm x 10mm (.394 inches x .394 inches)
    • Max Height (from the lower bottom of Wireling to upper top Large Button): 10.3mm (0.41 inches)
    • Weight: 1 gram (.04 ounces)

    Notes

    • You can also use this shield without the TinyDuino – modifying the connecting cable by removing the opposite connector and stripping/tinning the wires, you can solder the connector cable to any other microcontroller board of your choice!   
    Small Button Technical Details

    ALPS SKTHBAE010 Switch Specs

    • Height 2.5mm
    • Operating Force: 3N
    • Travel 0.12mm

    TinyDuino Power Requirements

    • Voltage: 3.0V - 5.5V 
    • Current: 10µA

    Pins Used

    • A5/SCL - I²C Serial Clock line
    • A4/SDA - I²C Serial Data line 

    Dimensions

    • 10mm x 10mm (.394 inches x .394 inches)
    • Max Height (from the lower bottom of Wireling to upper top WirelingConnector): 3.70mm (0.15 inches)
    • Weight: 1 gram (.04 ounces)
    Switch Technical Details

    Specs

    • Cover: Stainless Steel
    • Mechanical Lifecycle: 10,000 cycles

      TinyDuino Power Requirements

      • Voltage: 3.0V - 5.5V 

      Pins Used

      • A5/SCL - I²C Serial Clock line
      • A4/SDA - I²C Serial Data line 

      Dimensions

      • 10mm x 10mm (.394 inches x .394 inches)
      • Max Height (from the lower bottom of Wireling to upper top Wireling Connector): 3.70mm (0.15 inches)
      • Weight: 1 gram (.04 ounces)

      Notes

      • You can also use these Wirelings without the TinyDuino – modifying the connecting cable by removing the opposite connector and stripping/tinning the wires, you can solder the connector cable to any other microcontroller board of your choice!

      Materials

      In order to interface with any Arduino-based board, you'll need the Arduino IDE.

      There are multiple processor/adapter combinations that can be used with Wirelings. Use the following table to find the combination that works for you.

      Processor
      Adapter
      Programming Cable
      +
      -
      -
      Arduino USB A to B Cable
      Raspberry Pi

      In order to interface with Wirelings, you'll need one Wireling Cable per Wireling and the Wireling.h Library (You can download this from GitHub as linked, or from the Library Manager in the Arduino IDE).

      The table below lists which Wirelings can be utilized with the following code.

      Wireling Selection

      Hardware Assembly

      WirelingZero with Wireling cable connecting from port 0 to Input Wirelings

      Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling to Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch by editing the Analog pin used as noted in the program.)


      Software Setup

      If you haven't already downloaded it, make sure you have the Wireling library. To install an Arduino library, check out our Library Installation Help Page.

      For these Wirelings, you just need the example Arduino program included above under the Software section. Open up the program in the Arduino IDE, and upload it to your board.

      Make the correct Tools selections for your development board. If unsure, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


      Upload Program

      Upload the program to your development board of choice!

      Code
      /*
        TinyCircuits Button/Switch Wireling Example Sketch
        This sketch will indicate if the button or switch
        is active or inactive.
      
        Written 30 July 2019
        By Hunter Hykes
        Modified 07 January 2020
        By Hunter Hykes
      
        https://TinyCircuits.com
      */
      
      #include <Wire.h>
      #include <Wireling.h>
      
      #if defined (ARDUINO_ARCH_AVR)
      #define SerialMonitorInterface Serial
      #elif defined(ARDUINO_ARCH_SAMD)
      #define SerialMonitorInterface SerialUSB
      #endif
      
      #define WIRELING_PIN A0 // pin corresponds to port (i.e. A0 -> PORT0, A1 -> PORT1, etc.)
      
      #define LED_PIN 10 // For WirelingZero
      //#define LED_Pin 13 // For TinyDuino, TinyScreen+, TinyZero, and RobotZero
      
      void setup() {
        SerialMonitorInterface.begin(115200); // start serial communications at 115200 Baud
      
        Wire.begin();     // start I2C communications for Wireling Library
        Wireling.begin(); // needed to reach Wireling ports on RobotZero and Wireling Adapter TinyShield
      
        pinMode(LED_PIN, OUTPUT);     // set the built-in LED pin as an output
        pinMode(WIRELING_PIN, INPUT); // set the pin of the button/switch as an input
      
        delay(500);
      }
      
      void loop() {
        // NOTE: switch is active low so '0' is ON
        if(!digitalRead(WIRELING_PIN)) {
          SerialMonitorInterface.println("Active");
          digitalWrite(LED_PIN, HIGH);
          delay(1);
        } else {
          SerialMonitorInterface.println("Inactive");
          digitalWrite(LED_PIN, LOW);
          delay(1);
        }
      }
      

      When the button or switch is active, the word "active" will be printed to the Serial Monitor and the onboard LED will turn on. When the button or switch is inactive, "inactive" will be printed to the Serial Monitor and the onboard LED will turn off.

      If using a WirelingZero, make sure LED_PIN is set to 10. Otherwise, set it to 13.


      Contact Us

      If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

      Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

      Thanks for making with us!


      Downloads

      Large Button
      Small Button
      Slide Switch
      Datasheet
      Schematic
      EAGLE Files
      Arduino Sketch