Over last few months I have had a lot of fun working on Arduino projects using Simulink. Honestly, I was a bit apprehensive when I started on my first Arduino project. An engineer turned marketer, I had not worked with hardware in over a decade. I have zero background in embedded programming. But I love MATLAB and Simulink, and wanted to see how far I can go with that knowledge. In this blog post, I want to share how within few days, I was able to program an Arduino using Simulink to drive an object-tracking camera mounted on a servo.
It took 3 simple steps:
1. Program Arduino Uno using a simple Simulink model to blink an LED
2. Build a Simulink model that can track a ball using a basic webcam and library blocks
3. Program Arduino Uno using Simulink to drive the servo that has the webcam mounted on it
Here's a video of the project
and here's how I got there...
Hello World! aka Blink an LED
Here's a short video of steps involved in Programming Arduino Uno with Simulink
Hardware: Arduino Uno, 220Ω resistor, an LED, connecting wires
Software: MATLAB & Simulink R2013b installed with the Simulink support package for Arduino
Detect a ball using Simulink
The next step was to build a model in Simulink that detects a round object. I used the Blob Analysis block from Computer Vision System Toolbox to build a simple model. Using a basic webcam I tested the model in Simulink. There are several example models on the MATLAB Central File Exchange community website that you can download and tweak as you like.
Compute Servo Angle to track the ball
The blob detection model provides current coordinates of the ball in a given frame from the webcam. I wrote MATLAB code to compute the servo angle necessary to keep the ball in the center of the frame. This servo angle was then sent to the Arduino to control the servo.
What next?
Excited by my success in a short amount of time, I now intend to use Simulink models to program an Arduino-based line-following robot such as: