• On/Off Power Switch Exercise | ACE-Lab

    On/Off Power Switch

    Developed by Dr James E. Pickering

    The video below introduces the switched LED circuit. Follow the steps on this page to assemble the hardware, deploy the Simulink PWM model, and then use the physical on-off switch to interrupt and restore the LED circuit path.

    1. Learning Outcomes

    After completing this exercise, learners should be able to combine a Simulink PWM output workflow with a simple physical switching element in an Arduino LED circuit.

    1
    Build a deployable PWM Simulink model

    Create a model that drives an Arduino PWM output using a Sine Wave, Abs, Slider Gain, and PWM block.

    2
    Wire a switched LED circuit correctly

    Place an on-off switch in the LED current path so the circuit can be opened and closed physically.

    3
    Configure Arduino pin 9 for output control

    Route the PWM command to Arduino pin 9 and connect the hardware path through the switch, resistor, and LED.

    4
    Verify model behaviour against hardware behaviour

    Deploy the model, observe the LED brightness variation, and confirm that the switch interrupts and restores the circuit.

    2. Hardware Set-Up

    The switch is placed into the LED circuit path so that continuity can be interrupted or restored. Pin 9 on the Arduino is routed through the switch, then through the resistor and LED to ground.

    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
    • On-off power switch

    Assembly guidance

    Assemble the circuit so that current flows from Arduino pin 9 through the closed switch, resistor, and LED before returning to GND. Opening the switch should break the circuit path even while the Simulink model is still running.

    1

    Connect the on-off power switch to the breadboard. Use a jumper wire to connect Arduino pin 9 to the same column as one terminal of the switch.

    2

    Insert a 220 Ohm resistor so that one end is in the same column as the opposite terminal of the switch. Place the other end of the resistor in a different breadboard row.

    3

    Connect the long leg of the LED, the anode, to the free end of the resistor. Complete the circuit by connecting the LED cathode column to an Arduino GND pin.

    Arduino Uno, breadboard, LED, resistor, and on-off switch hardware wiring diagram
    Hardware arrangement for the On/Off Power Switch exercise.

    4. Running Simulink Code Generation

    Configure Simulink for the Arduino Uno target, deploy the PWM model, and then verify the effect of the physical switch on the live circuit.

    Connect the Arduino board

    Connect the Arduino Uno to your computer using the USB 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.

    Deploy the model

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

    Verify the switch

    Observe the LED when the switch is closed, then open the switch and confirm that the LED turns off because the circuit path is broken.

    5. Troubleshooting Checks

    Use these checks if the model deploys but the LED or switch does not behave as expected.

    The LED does not turn on when the switch is closed

    Check the LED orientation, confirm the resistor is in series, and make sure the switch terminals are connected across the intended breadboard break rather than the same connected row.

    The switch does not appear to change anything

    Confirm that Arduino pin 9 routes through the switch before the resistor and LED. If the switch is bypassed by another wire, opening it will not interrupt the circuit.

    The LED brightness does not vary

    Re-check the Sine Wave, Abs, Slider Gain, and PWM settings. The Slider Gain high limit should be 255, and the PWM block should be assigned to pin 9.

    Simulink cannot deploy to the board

    Confirm the Arduino support package is installed, the board is set to Arduino Uno, the USB connection is active, and the model stop time is set to inf before using Monitor & Tune.

    6. Additional Exercises

    After completing the main task, learners can extend the exercise by changing the PWM behaviour, adding switch-state observations, and documenting how their revised behaviour was verified.

    Exercise 1: Modify the PWM Brightness Pattern

    Choose new values for the sine wave timing or slider range. Deploy the revised model and verify that the LED brightness changes while the switch is closed.

    Exercise 2: Compare Model Control and Physical Switching

    Explain the difference between changing the PWM command in Simulink and opening the physical switch in the circuit. Record what happens in each case.

    7. Concluding Remarks

    This exercise extends the earlier LED activities by introducing a physical on-off switch into the hardware path. The result demonstrates how a circuit element can change system behaviour even when the deployed Simulink model continues to run.

    By combining a PWM model with a switched circuit path, learners reinforce their understanding of circuit continuity, PWM-driven LED control, and the relationship between model-based design and practical embedded hardware implementation.