Introduction: Control Arduino Wirelessly With MATLAB

Been seeing few DIYs on how to establish a communication between MATLAB application and Arduino that is hardwired to PC. However, I haven't encountered anything that control Arduino via MATLAB wirelessly using the ENC28J60 compatible Ethernet shield. In this ible', I'm going to show the simplest way to control Arduino using MATLAB wirelessly. 

WHAT YOU NEED?

1) Arduino - You need a controller. I used Arduino since it is supported by MATLAB. For this project however I used, Gizduino, a locally made Arduino-based controller.

2) Ethernet Shield - You need a compatible Ethernet shield for your board. I used the ENC28J60 for my board.

3) Wi-Fi Router - To connect your Arduino which would be the means to communicate to your PC wirelessly.

4) LED - Any components to indicate communication between devices. For this project I used LED.

5) Printer Cable - To connect Arduino to your PC.

6) UTP Cable - To connect your Ethernet shield to the router.

Step 1: Connect Ethernet Shield to Arduino

Carefully connect your Ethernet shield to your Arduino. Avoid bending the pins.

Step 2: Connect LED

Connect any components that could indicate communication between devices. In this 'ible I used an LED. Will try to turn LED on and off wirelessly using MATLAB. I've connected my LED's anode (long pin) to Digital I/O pin 6 of the Ethernet shield attached to the Arduino and LED's cathode (short pin) to Ethernet's GND.

Step 3: Connect Arduino to PC

Plug-in the printer cable to your Arduino and connect to PC.

Step 4: Connect Ethernet Shield to Router

Plug-in UTP to your Ethernet shield and any of the LAN ports of your router.

Step 5: Open Arduino IDE

I used Arduino 1.0 because of the Ethernet shield library compatibility. After opening Arduino 1.0, download the library and copy paste the content to the library folder of your Arduino 1.0.

Step 6: Upload Code to Arduino

Before uploading the codes to your Arduino, make sure of that you have indicated a web server address that is with in the DHCP server range. To learn the DHCP server range of your router, you may access your router by opening a browser and typing the default gateway address, 192.168.0.1. Most of the router uses this default gateway address, however, some router may use different address. To learn the address of your router you may access the command prompt, if you are a Windows user, type in ipconfig and hit on enter. Look for the default gateway address if you are connected to your router.

Step 7: Test Web Server

After uploading the code to Arduino, you may test if you can access the web server you assigned. Open a browser and type in your web server address. I used 192.168.0.15 as my address. You may click on and off and check if the LED connected to your Ethernet shield attached to the Arduino is responding. Once you have established a communication to the Ethernet shield and web server you may proceed to integrating it to MATLAB.

Step 8: Open MATLAB

Upon establishing a connection to your Arduino, Ethernet Shield and Web Sever you may open your MATLAB and begin with the integration.

ON A SIDE NOTE:

Although we will not use the MATLAB support package for Arduino, you may choose to download it for future reference.

Step 9: Click on GUIDE

After running MATLAB, click on GUIDE. This will bring you to another window asking for GUI templates, just click on blank GUI.

Step 10: Draw Two Buttons

Click on pushbutton and draw two for ON and OFF mode. You may change its properties accordingly. Once done, click on m-file and save.

Step 11: Link Push Buttons to the URL

Once done, you may place the following codes below pushbuttons 1 and 2.

For the first push button:
urlread('http://192.168.0.15/?led=on');

For the second push button:
urlread('http://192.168.0.15/?led=off');

If you come to notice, the following codes above just makes MATLAB access the web server address for the commands on and off which makes it able to control the following wirelessly. Just click on play and run a test.

Comments

author
Matlabiم (author)2016-06-04

Was very
interesting, thanks for share

متلب , انجام پروژه متلب

author
MANISHKUMARK (author)2016-05-24

is it possible to receive data on matlab sent by arduino using Ethernet shield?

author
Raphango (author)2015-08-12

Interesting! =D

author
snoop911 (author)2015-05-25

Is this similar to matlab hardware-in-the-loop (HIL) or processor-in-the-loop (PIL)?

http://www.mathworks.com/help/ecoder/ug/pil-simulation-for-ide-and-toolchain-targets.html

I've read that pid control loops can be finely tuned by having the system communicate to matlab realtime so that the actual model properties can be evaluated in matlab for better tuning. All seems like magic to me, but if you have any thoughts on it that would be great!

author
poojashish (author)2015-04-05

i have some difficulty in my project which i present here,

i made program of hand gesture recognition in matlab R2014b. in that i give input images and get output of 1,2....9. now i want to transmit this 1,2...9 to arduino mega 2560 wirelessly and real time. and i connect robotic arm with arduino. so i make programming in arduino accordingly. but pls tell me about how to transmit commands 1,2...9 from matlab to arduino without wire and as fast as possible because according to this output of matlab robot do some action.....

pls tell me its very important for me

author
poojashish (author)2015-04-05

hi nice guidence for my project work

author
poojashish (author)2015-04-05

author
JhunDaniel (author)2014-10-17

Hello, well this question is not related in this wonderful project. But i would like to ask that does the way you code in arduino is the same as you code in Gizduino.
I make a project and I've coded it in arduino, now i want to do it in gizduino, but when I run it, it would'nt work. Thanks in advance.
BTW nice project.

author
matlabgui (author)2013-03-18

hi, trying to understand code
urlread('http://192.168.0.15/?led=off');
what urlread do? led is name for port where is led diode?
i want tu use gui to communicate with arudino using ethernet communication but i cant find how to send for example how to send number to arduino, or how to accept data back from arduino...thanks in advance for any help ...

author
Analogue-Chick (author)matlabgui2013-03-19

The "urlread" command in MATLAB is similar to hyperlinking since we created web server address for each of the commands that the ethernet shield, as well as the controller understands. It only means reading the assigned web server (url) address. You can compose any web server address you want, in which case I assigned "?led=off" for off mode and "?led=on" for on mode to make things easier. If you want to send information to Arduino via MATLAB, I think you need to integrate the codes available for ENC28J60 and MATLAB support package for Arduino. I haven't figure out how to do this yet, but I'm sure about the coding it's either purely assigning every tasks to a web server or combining the pde for the ethernet shield and MATLAB support package for Arduino. I'll probably post another 'ible for this when I get my hands on an ENC28J60 unit. Just borrowed the ethernet shield from a friend when I did this 'ible.

author
rmagtibay (author)2013-03-13

nice

author
Analogue-Chick (author)rmagtibay2013-03-13

Salamat Sir! :)

author
umursengul (author)2013-03-13

Well my Ethernet Shield is on its way, and when it comes, I will definitely try this ASAP! Thanks!

author

Thanks for checking this ´ible out. Hope you get your Ethernet Shield soon. Enjoy! :)

About This Instructable

48,690views

76favorites

License:

Bio: I love internet reading. I think I have acquired more knowledge from the internet than I have and probably ever will from a standard institution ... More »
More by Analogue-Chick:Make Your Images Interesting with Galaxy OverlayControl Arduino Wirelessly with MATLABSteampunk Bonsai
Add instructable to: