Skip navigation


12 Posts authored by: Anuja Apte

Madhu here for my blog post after a long vacation! For today's post, I am going to talk about a project that I had worked on as a fun learning project.


I came across this wonderful tutorial on Adafruit's website for controlling different types of motors using the V2 Motor shield. The detailed instructions make it easy to get started and I want to adapt these for the MATLAB Support Package (SP) for Arduino. With the support package, you can connect to your Arduino from a MATLAB session - to acquire data from or to send data to the Arduino. I am using the motor shield here to illustrate the use. 


Once I made all the connections as shown in the figure below, I only had a few steps to follow.



The steps -


1) Create an Arduino object in MATLAB


arduinoObject = arduino('com4', 'Due', 'Libraries', 'Adafruit\MotorShieldV2')


2) Create an addOnShield object for the V2 Motor shield


addOnShield = addon(arduinoObject, 'Adafruit\MotorShieldV2')


3) Control the servo motor from port 1


servoMotor = servo(addOnShield, 1)

for angle = 0:0.2:1 % From minimum 0 degrees to maximum 180 degrees

    writePosition(servoMotor, angle);




4) Control the stepper motor from port 1. Note that the servo port 1 is different from the Motor port 1 in Motor shield.


stepperMotor = stepper(addOnShield, 1, 200) % Example usage of stepper - stepper(shieldObject, portNum, StepsPerRevolution)

stepperMotor.RPM = 10;

move(stepperMotor, 200);


5) Control the DC motor from port 4


dcMotorObject = dcmotor(addOnShield, 4)

dcMotorObject.Speed = 0.2;



Hope this will be useful to others as well, who are attempting to understand how to use MATLAB Support package for Arduino to control motors.

Madhu here for the weekly post..


I wanted to try out something cool and inexpensive. So I bought this Buzzer online. To make this work I hooked it up to the Arduino PWM signal pins, which runs at around 500 Hz (would be ideal to produce audible tone). I love creating electrical circuits using Fritzing and created this to show the circuit that I used.

For the Simulink part -

Once I found out that Arduino has functions tone and noTone, I set up a S-function builder block in Simulink that shows the library files needed and the calls to these functions appropriately as shown below.

After this I connected a sequence to the enable and frequency inputs of the S-function builder. A total of 15 minutes of work and with the comfort of using Simulink I was able to understand how to use Arduino to control sensors using the PWM pins and also enjoy the music that I created


Anuja Apte

"Make" this Halloween

Posted by Anuja Apte Oct 24, 2014

Hey! It's Madhu Govindarajan here -

For this week’s blog post, I will share some ideas for makers who want to get creative with their Halloween celebrations. The few things that pop-up to mind when thinking about Halloween – Trick or treat, carving pumpkins and haunted house attractions.

A custom Speech to Text converting script can be implemented with ease on Raspberry pi. This can be used to identify someone saying “Trick or treat” which can control an automatic Candy dispensing machine. This way you can ensure that you don’t disappoint the trick-or-treaters even if you are out at a costume party.

For those who want to come up with ideas related to pumpkins, if controlling the light pattern on your carved pumpkin sounds dull and boring please take a look at the Fire Breathing Jack-O-Lantern from this video.


Instead of treats if you want to scare people away on Halloween, a few sensors (touch sensors, proximity sensors, motion sensors etc) can help you design your own backyard Haunted house (something similar to the one's in this video).

Hopefully you get inspired by these videos to MAKE your own safe and sound Halloween project.

I would like to introduce you to Madhu Govindarajan from MathWorks who will be writing interesting blog posts for next several weeks. Thanks Madhu!

Hi everyone! Madhu here - I thought for today’s post I will share the answer to a frequently asked question during the recent Autonomous Fighting Robots Challenge (AFRC).

Flexibility to build and expand existing solutions is one of key aspects fueling the Maker movement. I want to share how Simulink in essence supports the same thought process. For example, look at this fun video from the robotics contest where the autonomous robots were designed completely using the Simulink support package for Arduino and custom-developed blocks based on S-function builder.

Although there are several ways to bring in external C code from the open-source libraries into Simulink environment, S-function Builder provides a User Interface that helps understand and simplify the process.

Here's a link to a set of files authored by my colleague Giampiero, which contains a step-by-step tutorial to create your own Device drivers using S-function Builder. This file not only inspired the Encoder blocks (used to measure the speed of the fighting robots) and Serial communication blocks (used to control their on/off switch) but also others mentioned in the Acknowledgement section on the link. So in essence Simulink has ways to accommodate existing external libraries, hence allowing makers to feel more empowered than just using MATLAB, Simulink and the support packages.

After all, software is nothing but pencil in the hands of the creator.

I had recently talked about how you can control servo motors using an Arduino and Simulink. I stumbled upon an interesting application which builds on the same topic. The video shows how you can use an IR sensor coupled with a stepper motor to get a rotational range scanner (I would have ideally called it a Mini Radar, but for the fact that the sensor uses infrared waves instead of radio waves). The stepper motor is controlled using an Arduino UNO and an Arduino MotorShield. The Arduino is connected via USB to a PC running MATLAB with Arduino Support from MATLAB.


The stepper motor is driven in steps of 1.8 degrees using MATLAB code. At each step, the output of the IR Sensor is passed to MATLAB, where it is converted into an appropriate distance measure using pre-calibrated function. The author also provides a link to a MATLAB implementation of SLAM (Simultaneous Localization and Mapping) which can be used as starting point for creating the functions to obtain distance information.


Check out the video and its description as well for more details about the project:


I know my next project is building this device using servo motors instead and can definitely see a user interface similar to a radar monitor to view the results. Have other ideas about this contraption? Feel free to share!

This blog post is a tutorial on how you can control servo motors using an Arduino Mega 2560 board and Simulink. If you are not familiar with programming an Arduino with Simulink, I would recommend that you check out the video linked below first. I had pointed to this video in an earlier blog post which went through the steps I had taken to learn Arduino programming with Simulink.


Now that the basics are out of the way. Let us get to the servo motor control part of this tutorial. This tutorial uses the Simulink Support Package for Arduino which allows you to create and run Simulink models on an Arduino Mega 2560. The support package contains a library of blocks which can be used for interfacing with Arduino sensors, actuators and communication devices. In this tutorial, we will focus on servo motor control. In a standard servo motor, the motor shaft can be precisely set to any angle between 0 degrees and 180 degrees using a data signal. The data signal is generally a pulse width modulated waveform, whose duty cycle or the amount of time the value of the waveform is set to a 1 in a single time period of the wave determines the angle of rotation of the motor shaft. However with Simulink, you do not have to worry about pulse width modulation, which is taken care of by the underlying implementation, and you just need to specify the angle of rotation instead.


For the purpose of the tutorial, you will need the following:

  1. Arduino Mega 2560
  2. USB Cable
  3. Standard Servo Motor
  4. Breadboard wires
  5. Breadboard


As the first step, let us try to control the servo motor using a signal generated from Simulink. To achieve this, we first need to connect the servo motor appropriately to the Arduino. The servo motor will have three wires: power, ground, and signal. Connect the wires as described below:

  1. Connect the power wire (usually red) to the 5V pin.
  2. Connect the ground wire (usually black) to the ground pin.
  3. Connect the signal wire (usually orange) to digital pin 4.


The circuit assembly is shown below:


Once the hardware is set up, the next step is to create a Simulink model to control the motor. The steps for that are:

  • Create a blank Simulink model by clicking on 'New' on the MATLAB toolstrip and select Simulink Model.

new model.png

  • In the Simulink window, add the ‘Standard Servo Write’ block which is a part of the Simulink Support Package for Arduino Hardware. The path to the blocks is:
    Simulink Library Browser -> Simulink Support Package for Arduino Hardware -> Common -> Standard Servo Write


  • In the Simulink model, double click on the Standard Servo Write block and change the pin number to 4.


  • Similarly, insert the Repeating Sequence Stair block to the model, and connect the output of the Repeating Sequence Stair block to the input of the Standard Servo Write block.The Repeating Sequence Stair block can be found at the following path:

     Simulink Library Browser -> Simulink -> Sources -> Repeating Sequence Stair


  • Double click on the Repeating Sequence Stair block and set the sample time to 0.01. Change the vector of output values to the following : [1:180 179:-1:1]. The vector of output values is the input to the Standard Servo Write block and provides the angles by which the shaft of the servo motor should rotate. In this case, the shaft will rotate about 180 degrees in steps of 1 degree and then return to the original position.


  • The final model will be the same as the example model named 'arduinomega2560_servocontrol_sweep.slx' which is an example model included with the Simulink Support Package for Arduino



  • Once the model is ready you can download the code onto your Arduino by clicking on the Deploy to Hardware button on the top right corner of the Simulink Window.



This concludes the tutorial on Servo Motor Control using Simulink. However this is just a starting point for more projects with servo motors. The immediate next steps in this case would be to control the shaft position using a potentiometer or even a photocell. In both the cases, the workflow would be to capture the value of the potentiometer or photocell as an input to the Arduino, and on the basis of the value change the servo motor position accordingly.

I was browsing through YouTube today and found an interesting project video from Mohammad Alshawabkeh & Ahmad Alameer of the University of Jordan Department of Mechatronics Engineering.


They have created a robotic hand powered by an Arduino Mega and the Simulink Support Package for Arduino Hardware. The robotic contraption uses 5 servo motors and 5 flex sensors to identify the position of the fingers. Seems like a really great project. Check out the video below to see the robotic hand in action. If you have any cool projects as well share them with us. More ideas for makers to try at home.


MathWorks organized a robotics competition as a part of the recently held Paris Maker Faire scheduled on June 21st and 22nd. The competition allowed participants to get their hands on a custom built mini Mars rover and play with Simulink and MATLAB to show off their robotics skills and received a raving response from a very large number of teams.


                                                                     The Mars rover

The goal of the competition was simple: Program an autonomous Mars rover to visit a number of sites in the fastest time possible. The sites would be designated using markers on an arena. The robots would be built and provided by MathWorks so the teams could focus on the algorithms - the brainpower to drive the robots, although the robot design was released as well if participants were interested in 3D printing their own prototypes.


                              CAD Model


A month prior to the competition, the participants were provided a functioning simulation model of the robot on github that they could use to prepare for the competition (check out the models to play with them yourself!). The robot designs and list of necessary hardware are also located on github, so anyone can build the rover and program it!. The competition received about 90 registrations, with teams of varied age groups from 15 - 58. The teams had up till June 1st to tune and modify the models to come out with the quickest simulations.


                                                            Simulation model in Simulink

Approximately 45 teams submitted their simulation models, and the best 12 amongst them were invited to the Paris Maker Faire for the final showdown. Not to disappoint the other teams, each team got free stuff including 2 e-tickets for the Maker Faire and an invitation for a Saturday night private party (Losing does not sound so bad after all). Each of the 12 finalists was provided with a webcam equipped Mars rover running on an Arduino DUE and access to the arena. The robots used a Raspberry Pi to process webcam images. The located targets acquired in the images are sent to the Arduino DUE (new support in MATLAB R2014a!) via i2c.



                                                                 The Arena

On competition day, It was a fight up to the last minute as teams battled their opponents, switching between algorithms and fine tuning those parameters. Throughout the day, many teams had the chance to be at the top of the scoring list with the best time. But none of them would stay very long as their opponents would quickly redouble their efforts and find ways to pull ahead. This happened all the way to the end, when within the final minutes of the final slugout, a team named LCMG was able to do a 37.6 s run, besting team 'Rayn on Mars’ 37.9. The roar and applause of the audience was intense. The 12 finalists took home tonnes of goodies and the winners got one of the Mars rover robots!


                                                              The Venue



                                              The tension (or lack of  ) in the air


This however, is not where the story ends. For those interested in running their own competition event, MathWorks would love to help you! All design files and programs are available on github (Last minute changes and bug fixes pending). So reach out let MathWorks help you make it happen! Looking forward to the next competition.


                                                       Mars rovers: The next generation



                                                            3D Printed Trophy




It's the Independence day weekend in the United States and a time for patriotism and fireworks . My colleague, Ye Cheng wanted to show her patriotism in her own "techie" way. Her idea: Light Paintings of the US flag.

Light paintings use point sources of light to sketch shapes which are captured by a camera at a low shutter speed. Ye used 13 RGB LEDs for her paintings.

The color of the LEDs are controlled by an Arduino Mega 2560, programmed using the Simulink Arduino Support Package and a Simulink model shown below.


The model sequentially switches the colors of a first 8 LEDs at appropriate times to give the desired effect. The hardware set up required is minimal and requires setting up the LEDs in a straight line on a breadboard.  Ye plans to attach the circuit to a motor and have a persistence of vision exhibit: A USA flag painted created using 13 LEDs constantly rotating. I am definitely looking forward to getting one of those for myself!

This is the third post in the blog post series celebrating Arduino day 2014..


This post is about a low-cost mobile lab experiment kit put together by the talented folks at Minseg. This is an excellent example of the contribution Arduino has made to the field of engineering education. Experiment kits such as Minseg not only make control and mechatronics labs more engaging, but also make them accessible to a large student population. 


minSeg 3.png


The Minseg website has a number of resources including simulation models, video tutorials etc. With these resources, you can create a miniature version of a Segway using a lab experiment kit that includes an Arduino and Raspberry Pi. You can develop and simulate balancing algorithms for the robot using Simulink. Then deploy these algorithms on an actual robot to see the robot in action.


Here are a set of links to specific resources:



and yes - wish you a very happy Arduino day!

This is the second blog post in a series of posts celebrating 10 years of Arduino! This series highlights how Arduino has powered a number of innovations in the field of education and engineering.


Robotic arms are used extensively  for numerous tasks from car assembly to picking up rocks on Mars. This video illustrates how you can build your own autonomous robotic arm using Arduino Mega with Simulink. You can learn how a robotic arm can be programmed to identify an object placed in front of it, pick it up and place it elsewhere.


One of many ways Arduino is making industrial applications accessible to the Maker community:


Happy Arduino day!!!


Do you remember racing a car in a video game, bumping into your opponent, your joystick happens to vibrate and you could feel the collision? This is the science of haptics. Haptic devices provide users a sense of physical interactions with real or simulated systems. The haptic paddle was originally developed and used as a teaching tool for dynamic systems at Stanford University. 


You may be wondering how this is related to Arduino?


Arduino has been used to power the development of such an inexpensive, portable haptic device at Vanderbilt University. The Arduino-powered haptic paddle is used with Simulink to teach system dynamics in Mechanical Engineering courses. Students can apply the theoretical concepts in feedback control systems by simulating the haptic paddle in Simulink and then experiencing the forces generated in the virtual environment with the haptic paddle.


Here's a link to the university website for more details on this project. You can also download the course materials from the website here.



Filter Blog

By date: By tag: