DIY Oscilloscope using Arduino and Matlab Simulink

 Oscilloscope are expensive, so we will show you here how to make DIY Oscilloscope using Arduino and Matlab Simulink. With this the advantages are that you can read in analog signal and measure their signal properties like amplitude, phase and even perform spectrum analysis and many others. Other alternative to DIY oscilloscope includes using free oscilloscope software available on the internet but the disadvantage of this solution is that you will be using your PC/Laptop sound card to process the signal. For engineers and for other kinds of engineering projects, it is a good thing to learn co-simulation between Arduino and Matlab and this lesson will also help fill in the gap. For example you could connect a PIR sensor with Arduino and send the signal to Simulink and perform other control algorithm in simulink.


Install Simulink Support Package for Arduino Hardware 

First of all you must have simulink support package for arduino hardware library installed in your simulink library.

simulink support package for arduino hardware

 How to install Simulink Support Package for Arduino Hardware library?

Follow these steps to install library. First click on the Get Add-Ons then Get Hardware Support Packages.

Get Hardware Support Packages

You will see hardware support packages that are available for install. Those which is labelled Installed are the ones which you have already installed.

In my case, as you can see in the figure above, Matlab Support Package for Arduino Hardware and Simulink Support Package for Arduino Hardware are already installed. If you don't have them installed, click double click on the Simulink Support Package for Arduino Hardware and then click on the Install(or Add) button in the screen that follows. 

 You might be also asked for account login. You can just create a new account with a valid email address and it be readily installed.


Hardware Setup

 For our simple purpose to verify that an analog signal can be read from Arduino and the captured signal displayed on time scope in real time by simulink, we will simple use a 10KOhm potentiometer and vary the input signal amplitude. For this connect one end of potentiometer to 5V pin and the other end to GND on the Arduino. Then connect the middle terminal of potentiometer to the Analog Input pin 0 of the Arduino. This is as shown below.

Connect the USB cable from Arduino to your PC/Laptop.


Creating & Configuring Simulink Model, Hardware Board & Time Scope


Once you have the library installed, go to Simulink Support Package for Arduino Hardware > Common, select Analog Input and add it your Simulink Model. Also add the Constant block from the . Now go to DSP toolbox library, find the DSP Time Scope and add it to your model. We will be using the DSP time scope because it features much like a real oscilloscope display to plots the signals, zoom scale, measure and view it in real time. 

After you have added these library components drawn the diagram as shown in the figure below.  

simulink model

Here we have used Arduino UNO analog pin 0. To set this up, double click on the Analog Input block and enter 0(the default is 4). Also since Arduino UNO ADC is 10 bit ADC, we have to multiply each analog sample coming Arduino hardware to correct voltage scale. For this we multiple each incoming sample with 5/1023 because this is resolution of the ADC for 5V maximum amplitude. That is sample resolution is Maximum Voltage Amplitude/2^10 = 5V/1024. But since the bit resolution counts from 0 it is 1023 and not 1024. 

Hardware Configuration

Next we have to specify which board we are using. At the top go to Hardware tab and confirm that Arduino UNO is selected as shown below.

If Arduino UNO is not selected, the just click the down arrow and double click on the Select Another Hardware Board.

The a configuration window will show up where you can search and select the desired board, which is Arduino UNO in our case. See below for this. Also, while you are here you can check out how the communication port setting looks like. In the picture shown, it is set to Automatic. In this case, simulink will automatically configure the correct COM port for you. If you run into problem with serial port communication between Arduino and Simulink you can check whether you can fix the problem by manually specifying the COM port.

Configuring Time Scope

Our final task for set up is the Time scope. Double click on the Time scope block and go to setting and then to the Display tab as shown below. In the Display tab, make sure that your range for the y-axis is set correctly. In my case I have set the Y-limit (maximum) to 5.5 and Y-limit (minimum) to -0.2 to view the 0 to 5V maximum signal coming from the Arduino hardware.

Then go to the Time tab and configure the time span to 10(sec) and choose Scroll option because it looks better.


Go back to the simulation model. On the top type in "inf" in the stop time field. Then click on the Run button.

When you run the simulation and vary the potentiometer knob, you should see the following type of waveform in the scope.

waveform display using Using Arduino with Matlab Simulink as DIY Oscilloscope

By varying the potentiometer, the Arduino is reading different input analog signal level which is the waveform shown above.

Video Demonstration of DIY Oscilloscope

Below is video demonstration showing our DIY oscilloscope using Arduino with Matlab Simulink at work.


 See next how you can use Arduino Due with Simulink to capture square wave signal.

Here we have used the Arduino ADC and serial to acquire data and send to Matlab simulink. There are many alternative to acquisition data and plot the data in real time in matlab or smulink. For example in the tutorial How to plot real time data from arduino in matlab we have used matlab code to plot signal in real time. Yet another alternative is to use the Audio Device Reader block in simulink which gives more responsive oscilloscope. See the tutorial How to use Matlab Simulink as Oscilloscope in which we have used PC audio system to create an oscilloscope.

Post a Comment

Previous Post Next Post