Skip to main content Skip to local navigation

Matlab and Arduino (Fall 2023)

Matlab and Arduino (Fall 2023)

I use Arduino-compatible hardware in two of the engineering programming classes that I teach here at York University. Rather than program the boards directly, I have the students install a little program on the Arduinos that can communicate with the programs that the students actually write on their own computers. For the first course, the students learn how to do this with Matlab and, in the second course, the students learn how to do this with Java.

Here I'll show you a few examples of how this works with Matlab. (more videos on the EECS 1011 playlist here)

LED on an Arduino

First, is the "light up an LED" example:

Light up an LED on an Arduino board using Matlab:

Read a button on an Arduino

Next, we look at how to read a button on the Arduino board:

Read a button on an Arduino using Matlab

Rotary Potentiometer on an Arduino

Next, let's use Matlab to read a rotary potentiometer on the Arduino board.

Reading an analogue sensor on an Arduino board using Matlab

Play a sound from a buzzer on the Arduino

Next we can play a sound on a buzzer connected to the arduino board.

Playing a sound from an Arduino board using Matlab (

Light intensity measurement using an Arduino and Matlab

Other analogue sensors can be monitored using Matlab. Here is a light intensity sensor being read:

Measuring light intensity on the Grove / Arduino board.

Soil Moisture sensor

Connecting a soil moisture sensor is a little more complicated. But it's doable using the right cabling:

Soil moisture sensor connection to an Arduino for reading from Matlab (

Water Pump & MOSFET Connection

The following video is longer than the others because it requires the connections of multiple cables and adapters. Here we connect an external water pump to the Grove / Arduino board via a MOSFET switch. The switch is required because digital devices like the Grove / Arduino board can't provide enough current or the current voltage to the pump directly. The switch takes the weak signal from the Grove / Arduino board and amplifies it to a level that can be used to drive the pump using the 9 volt battery.

Connecting a water pump and MOSFET switch to the Arduino board. (

Reading an Air Pressure Sensor

Reading an Air Pressure Sensor (BMP280) (

Reading an eCO2 Sensor

Reading an eCO2 sensor (

Reading a Temperature and Humidity Sensor

Reading a DHT20 Humidity and Temperature Sensor (

Making a hobby servo move

Hobby servos and Matlab.

Connecting a relay and a motor

relays, motors and matlab.

Setting this up

In order to get the above examples working we need to install Matlab and we need to install the Arduino support package.

For Windows that looks like this:

Installing Matlab on Windows (


Adding the Arduino Support Package for Matlab in Windows. (

While on macOS, we currently have to use Matlab 2022b (not the latest version of 2023a or b):

Install 2022b and the support package will work for Matlab on Apple macOS machines. (

Edit: Nov 18, 2023: adding DHT20, BMP280 and SGP-30 sensor videos.

Edit: Nov 20, 2023: servos and relays added.

a pen

James Andrew Smith is a Professional Engineer and Associate Professor in the Electrical Engineering and Computer Science Department of York University's Lassonde School, with degrees in Electrical and Mechanical Engineering from the University of Alberta and McGill University.  Previously a program director in biomedical engineering, his research background spans robotics, locomotion, human birth and engineering education. While on sabbatical in 2018-19 with his wife and kids he lived in Strasbourg, France and he taught at the INSA Strasbourg and Hochschule Karlsruhe and wrote about his personal and professional perspectives.  James is a proponent of using social media to advocate for justice, equity, diversity and inclusion as well as evidence-based applications of research in the public sphere. You can find him on Twitter. Originally from Qu├ębec City, he now lives in Toronto, Canada.