[updated in 2024]
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:
Read a button on an Arduino
Next, we look at how to read a button on the Arduino board:
Rotary Potentiometer on an Arduino
Next, let’s use Matlab to read a rotary potentiometer on the Arduino board.
Play a sound from a buzzer on the Arduino
Next we can play a sound on a buzzer connected to the arduino board.
Light intensity measurement using an Arduino and Matlab
Other analogue sensors can be monitored using Matlab. Here is a light intensity sensor being read:
Soil Moisture sensor
Connecting a soil moisture sensor is a little more complicated. But it’s doable using the right cabling:
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.
Reading an Air Pressure Sensor
Reading an eCO2 Sensor
Reading a Temperature and Humidity Sensor
Making a hobby servo move
Connecting a relay and a motor
OLED and Matlab
Github library for the OLED: https://github.com/AradhyaC.
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:
and
While on macOS, we currently have to use Matlab 2022b (not the latest version of 2023a or b):
Edit: Nov 18, 2023: adding DHT20, BMP280 and SGP-30 sensor videos.
Edit: Nov 20, 2023: servos and relays added.
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.