
On/Off Power Switch Exercise
1. Learning Outcomes
After completing this Section, you will be able to:
- Understand the use of the Simulink Arduino support package for algorithm design for a simple circuit, e.g., for an LED containing an on-off power switch
- Understand the functions of the Arduino Uno and the digital pins for use with a simple circuit (e.g., using PWM to control an LED in combination with an on/off switch
2. Hardware Set Up
This is a similar hardware set up as used in the previous two exercises.
The exercise involves connecting an LED to a switch that can contract the state of the LED being on or off.
Note that while the ACE-Box can be used for all the exercises, it is not required and only the individual components are needed.
Required hardware for this exercise:
- Arduino Uno board (supported by Simulink)
- USB Cable Type A to B
- Breadboard
- LED
- 220Ohm resistor
- 2 x male-male breadboard wires
- On-Off Power Switch
Set up the hardware as shown and following these steps:
- Connect the on/off power switch to the breadboard. Then use a male-to-male jumper wire to connect Pin 9 on the Arduino to the same column as one terminal of the switch.
- Insert a 220Ohm 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 row of the breadboard.
- Connect the long leg (anode) of the LED to the free end of the resistor. Finally, complete the circuit by running a male-to-male jumper wire from the LED’s cathode column to a GND pin on the Arduino.
Download Now
Download the PDF version of the exercise
3. Simulink Set Up and Switch Testing
As an on/off power switch has been added to the hardware (i.e., there are no additional inputs/outputs), the Simulink setup is the same as the LED(PWM)). However for completeness, the full set-up is explained again - with a demonstration provided via the video recording below.
The steps to set up the model are as follows (again, these are the same as the LED (PWM)) setup:
- Use a Sine Wave block (from Sources) as the input and connect it to an Abs (absolute value) block (from Math Operations).
- Connect a Slider Gain block (from Math Operations). You can specify the lower (Low) and upper (High) limits of the gain to constrain the output voltage. For example, to limit the voltage to 2.3 V: 256 × 2.3 = 117.76 ≈ 117. In this case, the upper limit (High) for the Slider Gain would be set to 117. However, for this exercise, set the upper limit to 255 (equivalent to 5 V on the Arduino Uno).
- Add a PWM block (from Common in the Simulink Support Package for Arduino Hardware) and connect three Scopes (from Sinks).
- Then run the steps from the previous exercise to perform the code generation (a recap link is provided below), to create an LED that is varying in brightness! Explore the effect of the gain value within the Slider Gain. Watch the video below for further help!

Key Properties to Modify
- Sine Wave (Sine type) → Set to Sample-based
- Sine Wave (Sample per period) → Set to Sample-based
- Sine Wave (Samples per period) → Set to 300
- Sine Wave (Sample time) → Set to 0.01 seconds
- Slider Gain (High) → Set to 255
All other properties may remain as their default values.
Advancing automatic control engineering (ACE) education through global collaboration



