Arduino (www.arduino.cc) is a low-cost open-source electronics prototyping platform.
For new projects using R2014a or higher, it is recommended that you use the MATLAB Support Package for Arduino hardware which can be downloaded here from this link:
For projects based on R2013b or earlier, use this submission.
MATLAB Support for Arduino avaialble with this submission (formerly "ArduinoIO Package") allows you to communicate with an Arduino board over a serial port. It consists of a MATLAB API (really just a class definition file) on the host computer and a server sketch program that runs on the Arduino.
Together, they allow you to access Arduino analog I/O, digital I/O, operate servo motors, read encoders, and even handle dc and stepper motors using the adafruit motor shield, all from the MATLAB command line.
Simulink blocks for communicating with the Arduino are also included.
For more information about Arduino Support, see:
For more infromation about the supported provided with this submission, see:
For Simulink blocks that support code generation, see:
%-- connect to the board
a = arduino('COM9')
%-- specify pin mode
%-- digital i/o
a.digitalRead(4) % read pin 4
a.digitalWrite(13,0) % write 0 to pin 13
%-- analog i/o
a.analogRead(5) % read analog pin 5
a.analogWrite(9, 155) % write 155 to analog pin 9
%-- serial port
a.serial % get serial port
a.flush; % flushes PC's input buffer
a.roundTrip(42) % sends 42 to the arduino and back
a.servoAttach(9); % attach servo on pin #9
a.servoWrite(9,100); % rotates servo on pin #9 to 100 degrees
val=a.servoRead(9); % reads angle from servo on pin #9
a.servoDetach(9); % detach servo from pin #9
a.encoderAttach(0,3,2) % attach encoder #0 on pins 3 (pin A) and 2 (pin B)
a.encoderRead(0) % read position
a.encoderReset(0) % reset encoder 0
a.encoderStatus; % get status of all three encoders
a.encoderDebounce(0,12) % sets debounce delay to 12 (~1.2ms)
a.encoderDetach(0); % detach encoder #0
%-- adafruit motor shield (with AFMotor library)
a.motorRun(4, 'forward') % run motor forward
a.stepperStep(1, 'forward', 'double', 100); % move stepper motor
%-- close session