thumbnail image

  • Home
  • Our Story
  • ACE-Model 
    • Overview
    • Stage 1: ACE-Core
    • Stage 2: ACE-Box
    • Stage 3: ACE-Apply
  • Members
  • Contact
  • …  
    • Home
    • Our Story
    • ACE-Model 
      • Overview
      • Stage 1: ACE-Core
      • Stage 2: ACE-Box
      • Stage 3: ACE-Apply
    • Members
    • Contact
    • Login

  • Home
  • Our Story
  • ACE-Model 
    • Overview
    • Stage 1: ACE-Core
    • Stage 2: ACE-Box
    • Stage 3: ACE-Apply
  • Members
  • Contact
  • …  
    • Home
    • Our Story
    • ACE-Model 
      • Overview
      • Stage 1: ACE-Core
      • Stage 2: ACE-Box
      • Stage 3: ACE-Apply
    • Members
    • Contact
    • Login
  • 1.3 LED (PWM) Exercise

    Learning Outcomes

    After completing this Section, you will be able to:

    1. Understand the use of the Simulink Arduino support package for algorithm design for a
      simple circuit, e.g., for an LED.
    2. Understand the operation of Pulse Width Modulation (PWM) and the use of saturation limits.
    Recap: Instructions to Install Simulink Arduino Support Package for Arduino Hardware
  • Hardware Set-Up

    This is the same hardware set-up as used in the previous exercise.

    The exercise involves connecting an LED to a digital Arduino output pin and controlling its state by switching it on and 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

    Set-up the hardware as shown and following these steps:

    1. Attach one end of the 220Ohm resistor to output pin 9 on the Arduino board, using the small breadboard and male-male breadboard wires
    2. Attach the long leg (positive) of the LED to the resistor

    Exercise Algorithm Design – LED Varying Brightness

    In this part of the exercise, you will develop a Simulink model to control the Arduino PWM output (1). A sine wave signal will be used to vary the PWM values between 0 (off) and 255 (fully on), smoothly adjusting the LED brightness across its full range.

    The steps to set up the model are as follows:

    1. Use a Sine Wave block (from Sources) as the input and connect it to an Abs (absolute value) block (from Math Operations), as shown in (2).
    2. 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 saturation block would be set to 117. However, for this exercise, set the upper limit to 255 (equivalent to 5 V on the Arduino Uno) (3).
    3. Add a PWM block (from Common in the Simulink Support Package for Arduino Hardware) and connect three Scopes (from Sinks).

    Key Properties to Modify

    1. Sine Wave (Sine type) → Set to Sample-based
    2. Sine Wave (Sample per period) → Set to Sample-based
    3. Sine Wave (Sample time) → Set to 0.01 seconds
    4. Slider Gain (High) → Set to 255

    All other properties may remain as their default values.

    Recap: Running Code Generation
  • Operation of LED (PWM) Exercise

    Coming soon!

    Section image

    Coming soon!

  • Download Now

    Download the PDF version of the exercise

    DOWNLOAD NOW
Advancing control engineering education through global collaboration
Cookie Use
We use cookies to ensure a smooth browsing experience. By continuing we assume you accept the use of cookies.
Learn More