• Tactile Button Switch Exercise | ACE-Lab

    Tactile Button Switch Exercise

    Developed by Dr James E. Pickering

    The video below shows the tactile button switch exercise in action. Follow the steps on this page to build the hardware, configure the Simulink PWM model, generate the code, and test how pressing the tactile switch completes the LED circuit path.

    1. Learning Outcomes

    After completing this exercise, learners should be able to apply a Simulink Arduino workflow to an LED circuit controlled through a tactile push-button switch.

    1
    Use the Simulink Arduino support package

    Build a simple hardware-linked model for an LED circuit that includes a tactile push-button switch.

    2
    Configure Arduino pin 9 for PWM output

    Use Arduino Uno pin 9 to drive the LED circuit through the tactile switch, resistor, and LED path.

    3
    Apply the PWM model structure

    Configure the Sine Wave, Abs, Slider Gain, PWM, and Scope blocks used in the tactile switch exercise.

    4
    Deploy and test the tactile switch behaviour

    Generate code, run the model on the Arduino Uno, and observe how pressing the switch affects the LED.

    2. Hardware Set-Up

    The exercise involves connecting an LED to a tactile button switch that controls whether the LED circuit is complete through physical force on the switch. The ACE-Box can be used, but only the individual components listed below are required.

    Required hardware:

    • Arduino Uno board supported by Simulink
    • USB cable Type A to Type B
    • Breadboard
    • LED
    • 220 Ohm resistor
    • 2 × male-to-male breadboard wires
    • Tactile button switch

    Assembly guidance

    Place the tactile button switch across the breadboard centre gap so the switch legs sit on separate internally isolated sides. Route Arduino pin 9 through the tactile switch, then through the resistor and LED to ground.

    1

    Insert the tactile button switch so its legs are positioned across the centre gap of the breadboard, with each pair of legs on opposite sides.

    2

    Use a male-to-male jumper wire to connect pin 9 on the Arduino to one leg of the tactile switch.

    3

    Insert a 220 Ohm resistor so that one end is in the same column as the opposite leg of the tactile switch. Place the other end of the resistor in a separate row.

    4

    Connect the long leg of the LED, the anode, to the free end of the resistor. Connect the LED cathode to an Arduino GND pin using a jumper wire.

    Tactile button switch circuit diagram showing Arduino Uno, breadboard, LED, resistor, and tactile button switch
    Circuit diagram for the tactile button switch exercise.

    4. Running Simulink Code Generation

    Configure the model for Arduino Uno hardware and deploy it so the PWM signal runs directly on the board. The tactile button switch then controls the physical continuity of the LED circuit.

    Connect the Arduino board

    Connect the Arduino Uno to your computer using the USB Type A to Type B cable.

    Open Model Settings

    In Simulink, open Model Settings by selecting Modelling → Model Settings.

    Select the hardware board

    Under Hardware Implementation, choose Arduino Uno as the hardware board, then click Apply and OK.

    Confirm the Hardware tab

    Check that the Hardware tab appears in Simulink after the target board is configured.

    Deploy the model

    Set the simulation stop time to inf, then use Monitor & Tune to compile and deploy the model to the Arduino.

    Test the tactile switch

    Once the model is running, press and release the tactile button to complete and interrupt the LED circuit path.

    Simulink hardware implementation and deployment view
    Hardware implementation and Monitor & Tune configuration for Arduino deployment.

    5. Additional Exercises

    After completing the main task, learners can extend the exercise by changing the PWM behaviour or adding another switched output.

    Exercise 1: Change the brightness pattern

    Modify the Sine Wave and Slider Gain settings so the LED brightness changes at a different rate. Test how the tactile button affects the revised pattern.

    Exercise 2: Add a second LED path

    Add a second LED on another Arduino output pin and compare how the tactile switch affects one LED path versus the other.

    6. Concluding Remarks

    This exercise extends the PWM LED workflow by adding a tactile button switch to the hardware circuit. The result demonstrates how a physical switching element can control whether the LED path is complete, even while the Simulink model continues to generate the PWM command.

    By combining model-based PWM output with a tactile switch in the circuit path, learners reinforce their understanding of circuit continuity, Arduino pin use, and the relationship between Simulink deployment and practical embedded hardware behaviour.