11.3: Filter Design and Introduction to Arduino MKR 1000 Wi-Fi

Mechatronics: Fundamentals, Design, Integration, and Validation · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.3: Filter Design and Introduction to Arduino MKR 1000 Wi-Fi
    Lab B.3 Objectives

    After completing this lab session, you will be able to:

    1. Explain both low- and high-pass filter design in both continuous- and discrete-time domains.
    2. Describe the architecture and Simulink implementation of duel-PID control of the mini-Segway.

    Low-Pass and High-Pass Filter Design

    This lab section introduces continuous- and discrete-time low- and high-pass filters. Consider the following signal.

    \[f\left(t\right)=0.05 \sin \left(2π\times 5000t\right) +2 \sin \mathrm (2π\times 50t) \label{B.5}\]

    including two frequency components of 50 and 5000 Hz with different amplitudes. Its wave form in time domain is shown in Figure B.24.

    A MATLAB plot of a continuous-time wave consisting of a summation of two sinusoidal functions with different frequencies.
    Figure B.24: Wave form of the continuous-time signal in equation \ref{B.5}.

    To develop a simulation model in Simulink, Clock, MATLAB Function, and Transfer Fcn blocks need to be dragged into the Simulink model from the Simulink library, respectively. Figure B.25 shows the constructed model.

    A Simulink block diagram used for validating the filter design by comparing the filtered and original signals.
    Figure B.25: Filter design validation model.

    Continuous-Time Low-Pass Filter Design

    The low-pass filter can help to attenuate the high frequency signal components and pass the low frequency ones. Note that the continuous-time low-pass filter was introduced in Section 4.4; see Figure B.26.

    A MATLAB Bode plot showing the frequency responses of a first-order low-pass filter along with mathematical expressions of its magnitude and phase.
    Figure B.26: Frequency responses of a first-order low-pass filter.

    The cutoff frequency \(ω_c\) (in rad/s) needs to be higher than the expected frequency and lower than the unexpected. In this example and equation \ref{B.5}, select \(f_c=200\ \)Hz that is between 50 and 5000 Hz. Hence, the parameters of the Transfer Fcn block need to be set as below in the filter calibration window (see Figure B.27).

    A screenshot of Simulink parameter window for the "Transfer Fun" block used to calibration both polynomial coefficients of numerator and denominator.
    Figure B.27: Low-pass filter parameter selection.

    After simulation, the comparison results are shown in Figure B.28. Here, the high frequency component (5000 Hz) has been filtered, but the low frequency part (50 Hz) remains with a phase delay. If \(f_c=ω_c/(2π)=500\ \)Hz were selected, what would be expected?

    A MATLAB plot comparing low-pass filtered and unfiltered signals of a summation of two sinusoidal functions with different frequencies.
    Figure B.28: Comparison of low-pass filtered and unfiltered signals.

    Continuous-Time High-Pass Filter Design

    The high-pass filter can help to attenuate the low frequency signal components and pass the high frequency ones. The continuous-time high-pass filter was introduced in Section 4.4 and is shown in Figure B.29.

    A MATLAB Bode plot showing the frequency responses of a second-order low-pass filter along with mathematical expressions of magnitude and phase.
    Figure B.29: Frequency responses of a first-order high-pass filter.

    Similarly, the cutoff frequency \(ω_c=2πf_c\) (in rad/s) needs to be lower than the expected frequency and higher than the unexpected. In this example, \(f_c=500\) and 1000 Hz are selected, separately, between 50 and 5000 Hz. Parameters of Transfer Fcn block need to be set as below, respectively, in Figure B.30.

    Two screenshots of Simulink parameter windows for "Transfer Fun" block with calibrations of 500 and 1000 Hz high-pass filters.
    Figure B.30: High-pass filter parameter configuration.

    After simulations, the comparison results are shown in Figure B.31, where the low frequency portion has been mostly filtered with suppressed magnitude. However, the amplitude and phase shift are different with different cutoff frequencies. Note that the red line with low cutoff frequency of 500 Hz is preferred.

    A MATLAB plot comparing high-pass filtered (with cutoff frequencies of 500 and 1000 Hz) and unfiltered signals of a summation of two sinusoidal functions with different frequencies.
    Figure B.31: Comparison of high pass filtered and unfiltered signals.

    Discrete-Time Low-Pass Filter Design

    The input of a discrete-time low-pass filter needs to be discretized. Hence, the signal is sampled and held using the Zero Order Hold block discussed in Lab B.2; it will be implemented here. Add the Zero Order Hold and Discrete Filter blocks into the Simulink model and connect them, as shown in Figure B.32. The sample period is set to \(T=5.0\times {10}^{-5}\) second (10 time higher than 5000 Hz) for both of these blocks.

    A Simulink block diagram showing a digital low-pass filter simulation model expressed in z-transform and comparing filtered and unfiltered signals.
    Figure B.32: Digital low-pass filter simulation model.

    The transfer function of a discrete-time first-order low-pass filter was introduced in Chapter 4 and again in equation \ref{B.6}.

    \[\dfrac{Y(z)}{X(z)}=\dfrac{1-α}{1-αz^{-1}} \label{B.6}\]

    The continuous-time cutoff frequency \(ω_c=2πf_c\) (in rad/s) needs to be higher than the expected frequency and lower than the unexpected in the continuous-time domain. In this example, \(f_c=200\) Hz between 50 and 5000 Hz is selected. With the given continuous-time cutoff frequency, parameter \(α\) can be calculated using the following relationship between continuous- and discrete-time domains.

    \[α=e^{-ω_cT} \label{B.7}\]

    where \(ω_c=2π\times 200=400π\) and \(α=e^{-400π\times 5.0\times {10}^{-5}}=0.939\) with \(T=1/200\) second. The associated command in MATLAB is alpha=exp(-400*pi*5.0*10\(\mathrm{\wedge}\)(-5)). Using the same method, parameter \(α\) for \(f_c=500\ \)Hz can also be calculated. Figure B.33 shows the comparison results after conducting model simulations, with blue for \(f_c=500\ \)Hz and red for \(f_c=200\ \)Hz, where the high frequency component has been filtered.

    A MATLAB plot comparing digital low-pass filtered and unfiltered signals of a summation of two sinusoidal functions with different frequencies with cutoff frequencies of 500 and 1000 Hz.
    Figure B.33: Comparison of discrete-time low-pass filter simulation results.

    Discrete-Time High-Pass Filter Design

    For the high-pass filter, the cutoff frequency is selected to be \(f_c=1000\ \)Hz while the discrete transfer function of the high-pass filter needs to be modified, as shown in equation \ref{B.8}. Thus, the high-pass filter simulation model shown in Figure B.34 can be adopted as the simulation model.

    \[\dfrac{Y(z)}{X(z)}=1-\dfrac{1-α}{1-αz^{-1}}=\dfrac{α(1-z^{-1})}{1-αz^{-1}} \label{B.8}\]

    where \(α\) is determined by equation \ref{B.9}.

    \[α=e^{-ω_cT}=e^{-2\times π\times 1000\times 5\times {10}^{-5}} =0.7304 \label{B.9}\]

    A Simulink block diagram showing a digital high-pass filter simulation model used to show the difference between filtered and unfiltered signals.
    Figure B.34: Discrete-time high-pass filter simulation model.

    After simulation, Figure B.35 shows the comparison results, where the low frequency component has been filtered.

    A MATLAB plot comparing digital high-pass filtered and unfiltered signals of a summation of two sinusoidal functions with different frequencies.
    Figure B.35: Comparison of discrete-time high-pass filter simulation results.
    Exercise \(\PageIndex{1}\)

    This exercise is for low- and high pass filter design. Consider the following time-domain signal

    \[y=5 \sin \left(2π\times 100t\right) + \sin \left(2π\times 2000t\right) + 0.5 \sin(2π\times 8000t) \label{B.10}\]

    and complete the following tasks step-by-step.

    1. Design a continuous-time low-pass filter to allow passing the lowest frequency portion (100 Hz) of signal. Show the simulation results and describe the cutoff frequency selected.
    2. Design a continuous-time high-pass filter to allow passing the high frequency components (2000 and 8000 Hz) of signal. Show the simulation results and describe the cutoff frequency selected.
    3. Design a continuous-time band-pass filter based on contents in Section 4.4. Combine low- and high-pass filters to allow passing a middle frequency component (2000 Hz) of the signal. Show the simulation results and provide both cutoff frequencies selected.
    4. Design a discrete-time low-pass filter to allow passing the lowest frequency portion (200 Hz) of the signal. Show the simulation results and provide the cutoff frequency and sample period selected.

    Introduction to Arduino MKR 1000 Wi-Fi

    Over the decades, Arduino has developed a variety of microprocessor boards with different capabilities and functionalities. For instance, different MKR boards are designed for different communication protocols, such as Wi-Fi and Bluetooth. The most popular board for beginners is the Arduino UNO based on the ATmega328P processor from ATMEL. UNO is the most used and robust board for the entry-level Arduino family; it is a good candidate for getting started with the Arduino platform.

    Arduino processor boards released after 2017 use more advanced microprocessors with more memory and enhanced input/output features. For the most part, however, they use the same pinout arrangements and work with existing add-on boards (called shield or carrier) and various add-on components such as sensors, communication chip sets, and actuators.

    In 2017, Arduino released the MKR 1000 board, an entirely new design with a new standard pinout, shape, and operating voltage (3.3V). Since then, several boards have been released following this new standard, creating a new subset of Arduino boards called the MKR family. This family of boards are made for those who need a specific digital communication protocol (Wi-Fi, Lora, SigFox, etc.) while keeping the classic Arduino board features.

    Arduino MKR 1000 Wi-Fi Board

    The MKR 1000 Wi-Fi board is used in Chapters 8 and 9 of this book (see Figure B.36). The board includes a LiPo charging circuit that allows it to run on batteries. It has a Wi-Fi module with a crypto chip to ensure secure communications, and it can be configured to constrain its power consumption to keep it running for long period. The MKR 1000 Wi-Fi board has 28 pins. Some of them have fixed functionalities and others are configurable. Fixed functionality pins include GND and 5V to provide access to the board ground and 5-volt reference voltage lines, respectively. The pins A0 to A6 are analog pins. They can transmit or receive voltage values between 0 and 3.3 volts, relative to GND. Finally, the pins 0 to 14 are digital pins. When these pins transmit data, they can only transmit voltage values of 0 or 3.3 volts, relative to GND. When they receive data, the voltage is interpreted as HIGH or LOW, relative to some threshold between 0 and 3.3 volts. Note that you must never apply more than 3.3 volts to the board’s digital and analog pins. Care must be taken when connecting sensors and actuators to assure that the 3.3-volt limit is never exceeded. Connecting higher voltage signals, like the 5V commonly used with the other Arduino boards, will damage the MKR 1000 Wi-Fi board.

    A backside image of Arduino MKR 1000 Wi-Fi board showing its pin definitions.
    Figure B.36: MKR 1000 Wi-Fi board.

    The pins on the Arduino boards can be used to control and communicate with external components, such as LEDs, motors, or sensors. They can be configured either as input or output ones. Input pins enable the board to read values from external components attached to them, such as the state of a button. When pins are configured as output, the board can control and communicate with actuators, e.g., lighting up an LED.

    Output pins are said to be in a low-impedance state. In this configuration, they can provide current to other circuits. In the MKR 1000 Wi-Fi board, output pins can source up to 7 mA (milliamps) of current per I/O pin to other devices and circuits. This means, for example, that we cannot drive a motor directly from an output pin because the current will not be sufficient. We need to consider the use of drivers of different types to achieve different tasks like lighting up high power LEDs, driving motors, or activating relays.

    Digital pins have only two states: on and off. In the Arduino programming language, these are labeled high and low. We can use the digitalWrite() function to set a pin to the desired state, indicating between these brackets which pin we want to act upon and the state we want it to be in.

    Installing the Arduino IDE

    To test the MKR 1000 Wi-Fi board included in the kit, you need to install the Arduino IDE. The classic Arduino IDE can be downloaded from https://www.arduino.cc/en/Main/Software. Choose the version corresponding to the operating system in your computer, then follow the instructions. More details about installation in different OSs (operating systems) can be found in the link: https://www.arduino.cc/en/Guide/HomePage.

    By installing the necessary files to compile programs for the MKR 1000 Wi-Fi, you will also install the drivers needed for your computer to identify the board and communicate with it.

    The following steps provide the installation instruction to be used for your own PC:

    1. Install Board Driver. Choose Board in the “Tools Menu” and then choose Board Manager on the top of the list of boards. The window shown in Figure B.37 will pop up. In the drop-down list of Type, choose Arduino. Further filtering your search by typing MKR1000 into the search blank will point to the available driver for the MKR 1000 family. Install this driver in your personal computer.
    A screenshot of Arduino "Boards Manager" window for IDE software for selecting the Arduino board.
    Figure B.37: Board IDE manager.
    1. Install the Library. Similarly, choose Library Manager in the Sketch menu; see Library Manager in Figure B.38.
    A screenshot of Arduino "Library Manager" window used to search and install Arduino libraries.
    Figure B.38: Library manager.

    Two libraries are necessary for this lab session: MKRMotorCarrier and WIFI101. Select and install them.

    Three main computer operating systems (Windows, Linux, and Mac OS) handle the connection of new USB devices differently. For example, the term COM followed by a number in Windows is different from that in Linus or Mac OS.

    Programing by IDE

    (This task should be completed during the lab session and used to verify if the software is installed successfully.) Choose Examples from the drop-down menu and then single-click Blink from the item list of “Basics.” The Blink program should be as shown in Figure B.39.

    A screenshot of Arduino IDE blink program as an example.
    Figure B.39: Blink program.

    The mode of pin 6 is set to output so that pin 6 can be set to the desired state (on or off) for lighting an LED. Try to tune the value in the command delay(*)to observe the changes.

    Communicate between Arduino and MATLAB/Simulink.

    The remaining lab sessions, including this one, use the MATLAB/Simulink as the programming tools for real-time control of the Arduino MKR 1000 Wi-Fi board. The following discussion details how to use this tool for the MKR 1000 Wi-Fi.

    MATLAB and Simulink Package Installation

    These instructions for installing MATLAB and Simulink can be used for your own PC. You will need the MathWorks products (toolboxes) listed in Lab B.0 to program the projects with the Arduino Engineering Kit. If MATLAB is installed, you can check if you have the required products by typing ver in the command window; then press “Enter” (or “return”) in the MATLAB command window. After completing the installation, install several add-ons that will be used in future lab sessions. First reopen MATLAB with administrator access. Then select Add-Ons from the MATLAB tool bar, as shown in Figure B.40. Click on Get Add-Ons.

    A screenshot of MATALB window toolbar with Simulink icon highlighted.
    Figure B.40: Matlab tool bar.
    Install these add-ons in the exact order provided below
    1. MATLAB Support Package for Arduino Hardware: Acquire inputs and send outputs to Arduino boards and connected devices.
    2. Simulink Support Package for Arduino Hardware: Run Simulink models on Arduino boards.
    3. MATLAB Support Package for USB Webcams: Acquire images and video from USB webcams.
    4. Arduino Engineering Kit Hardware Support: Select the right version depending on your MATLAB release (Arduino Engineering Kit Hardware Support R2019a or later, e.g., 2024b) and install MATLAB and Simulink Support Package for the Arduino MKR Motor Carrier and other components used in the Arduino Engineering Kit.

    Connection Setup for Matlab and Arduino

    You can set up the MKR 1000 Wi-Fi board in MATLAB. Using this method, you can check the connection status when you get any errors during programing between MATLAB/Simulink and Arduino. Type the following command in the MATLAB Command window to start:

    >> arduinosetup

    This command will open the Hardware Setup window shown in Figure B.41. Select USB from the available options and click “Next.”

    A screenshot of MATLAB window showing Arduino hardware setup interface with connection option of using USB.
    Figure B.41: Hardware setup window.

    Next, select your Arduino board type, the port through which you will communicate with it, and the external devices you will need for access. You will need to access the MKR motor carrier board (see Section 7.4). This board interfaces among the MKR 1000 Wi-Fi, DC motors, encoders, and servo motors. This example uses one DC motor and its associated rotary encoder. Set your board to MKR 1000 Wi-Fi, set the communication port to the COMx, and select Arduino/MKRMotorCarrier and RotaryEncoder, as shown in Figure B.42. Click Program.

    This step may take several minutes to complete. After the libraries have successfully loaded to the MKR 1000 Wi-Fi board, click Next and complete the remaining dialog. The firmware you are uploading will enable the Wi-Fi board to communicate back to your computer, where MATLAB/Simulink executes commands with the help of the information that is captured by sensors and sends it back to actuators via the same communication channel.

    A screenshot of MATLAB window showing the "Upload Arduino Server" window for hardware setup.
    Figure B.42: Upload server window.
    Exercise B3.2

    Setup communication between Simulink and Arduino for Arduino MKR 1000 Wi-Fi board. Follow these six steps to complete the exercise.

    1. Choose the Pulse Generator block from the Simulink Sources library and the Digital Output block from the “Simulink Support Package” within the Arduino hardware library. Connect these blocks as shown in Figure B.43.
    A Simulink block diagram used for lightening an LED on Arduino MKR 1000 Wi-Fi board using Arduino Simulink block for digital output.
    Figure B.43: Simulink model for lighting an LED.
    1. Edit these parameters in the Pulse Generator block as shown in Figure B.44, with amplitude equal to 1, period 2 seconds, and 50% pulse duty-cycle.
    A screenshot of Simulink "Pulse Generator" configuration window used to select the pulse type and associated pulse parameters.
    Figure B.44: Pulse generation block.
    1. Change Pin number 6 in the Digital Output block for illuminating LED lights.
    2. Choose the External mode in the Simulink tool bar and type in inf for the simulation time; see Figure B.45.
    A screenshot of Simulink window toolbar used for setting up external mode of Arduino microcontroller.
    Figure B.45: External mode setup.
    1. Single-click on the icon image50.png in the Simulink tool bar to configure the model’s parameters. In the Configuration window block, configure the following items:
      • In the Hardware Implementation section, choose Arduino MKR1000 as the Hardware board, as shown in Figure B.46.
    The screenshot of "Hardware board" selection in the Simulink "Configuration" window.
    Figure B.46: Hardware configuration.
    • In the Hardware board settings, choose Serial for External mode.
    • In the Solver configuration, set up the Fixed step size as 0.1 second.
    1. Now the basic model has been created. Click the Run with IO button in “Hardware” from the tool bar to launch the model.

    If the build process completed successfully, the LED light on the Arduino MKR1000 Wi-Fi board should blink. Note that the LED light will not light if the Arduino MKR1000 Wi-Fi board is inserted into the MKR motor carrier board.


    This page titled 11.3: Filter Design and Introduction to Arduino MKR 1000 Wi-Fi was last modified on Mon, 24 Aug 2026 21:39:47 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Guoming Zhu (Co-DREAM OER) .