Wednesday, February 10, 2016

Course on MATLAB Simulink and Arduino.

Have you ever thought of programming arduino from a powerful tool like Matlab Simulink, do you know why Simulink so powerful, many big industries and corporates are using Matlab Simulink for testing and implementing their projects, aeronautical industry to defence using for testing their prototypes isn't fun to use the same tool for our daily use hardware?



Matlab introduced support package for low cost hardware like arduino, Raspberry pi, beaglebone black and many more to include in this list, anyone from students licence holder to the professional licence holder can download this software make use for their projects. 

You may think what's so much with Simulink, as it may be like next other software tool to program an arduino, just think of a moment, have you ever played with MIT scratch??? have you felt the fun of programming just drag and dropping buttons makes arduino to run without going doing much process, If your answer is yes to the question then think for a moment!! What about combining the fun of MIT scratch and powerful programming language, yeah that's the fun you can get when you combine and make it running with Simulink. 

In this blog you will get to know from how to install required software to complete the whole bunch of tutorial, this is more sufficient to take next step using this hardware, I have created all the videos with much in depth detail on how to get started to finish up things, This video tutorial covers most of day to day life hardware stuffs we interface with Arduino. If you own an Arduino starter kit that is more sufficient to get work with this project, and your intention is to get started you own arduino Matlab projects, I can vouch that after completing this entire video course you can get your hands on the project you would like to build using Arduino and Matlab simulink. 

Lets start the course with Introduction and what are the things you need to get the things work that shows in the videos going to follow.

1. Introduction to Matlab 

You should have latest Matlab to be installed on your System, Matlab also offers a 30 day trail for anyone download the software and install it on your PC, hope you are not running an rs232 support system, we not any  more find an arduino with RS232 port too :), download Matlab R2015b which is the latest version from the Mathworks guys, they are just putting their best out to make the software more perfect every new version, I am not a Matlab affiliate market or a Marketing manager for them, their software speak for them, they don't need a 3rd person opinion for their software to do well on the market. Follow the video below to know all the things to get started. 





1.1 How to Install Arduino Support for Simulink.

In the following tutorial you will get to know on how to install the Arduino support package for Matlab and all the necessary steps have been discussed in the video, if you have any trouble downloading the software make sure you have good internet connectivity , I failed 12 times before I get the installation done due to my poor Internet connectivity which often fails, if still the problem persist turn of your Antivirus software which usually suspect application trying to connect to server mark it as risk and make problem when downloading the software. If everything goes file you are ready to go with interfacing Arduino to Matlab and uploading program to Arduino hardware.



2. How to blink an LED using Arduino and Simulink.

If you reached this stage, congratulation on installing Arduino support for Matlab and Simulink, Here the stage where we going to connect Arduino to Matlab and program it directly using Simulink, you might have used some Software before which are not capable of Programming the Hardware directly , you can't upload your Matlab code to Arduino EEPROM, you need Simulink to program it. Let's do the hello world of electronics, in case of software program we always test it with "hello world" program in this case we going to test hardware that is arduino connected to Matalb software and going to upload program from simulink. once you start to program you may find it more easier than using Arduino IDE. Just a few blocks connect together and your program is ready to upload, not only upload your code and leave you can actually verify the data on the screen, it is more useful when you are using this for project which involves many more functions, say you want to test this hardware with PID function, yes you can do it and fine tune it by getting feedback from the Arduino this allows you to do perfect programming by getting the result from the hardware.


2.1 More ways to blink it. 

You have just learnt about blinking an LED, lets focus on different methods on blink an LED, you will know what are the other ways to make things works. There are many blocks that are available in Simulink, we will try all the blocks and get to know what are different ways in achieving a task, you are not just blinking an LED with these tutorials we are using LED as verifier for our program, you can use these function to implement on any other devices, think of a device which requires these functions in realtime and make use of it. 




2.2 Control Brightness of an LED using Slider 

Back with another tutorial with LED :P, I am not crazy to use LED for all the tutorial, that's the easiest output device I can find to verify my program, as I said the previous section, we are using LED only to verify if you can replace LED with other tool , yeah go ahead and try it. This time we going to use Slider that is available in Simulink to control the brightness of an LED, 




Hey there so you have completed this tutorial too with LED :D, don't you think about something that we used a slider that is available inside the software, but the guy who did this tutorial said in the beginning that simulink can be used for permanently program this chip, what will happen if I deployed the program to Arduino Hardware? how am I gonna apply PWM function to it?? so many questions, yeah go ahead and try learn from it , and comment or send me a reply on what's happening with it, I am waiting for your reply :).

3. How to read analog signal in Matlab,

You heard it right, we going to acquire analog signal from Arduino and display the data in arduino and check how much voltage we are reeving, so what we are actually doing here, we have connected an Potentiometer to analog pin of Arduino, and when you rotate the potentiometer knob applied voltage to the potentiometer changes?, learn on how this damn potentiometer or variable resistor works if you google it by opening a tab next to this blog you can get to know about this funny POT, these are devices which can be comes in handy when you are controlling something, send a friend request by knowing him he will surely help you in the process of learning.

Hey I forgot say one thing, This tutorial too  have an LED :P, yeah we gonna control the brightness of an LED by varying this Potentiometer , so you will get to know how to use POT to acquire the analog signal and use this signal to do some useful work (yeah controlling LED again ).


after completing this tutorial you would have understand the importance of Simulink programming with Matlab, you can verify your code in realtime with Simulink support, you can fine tune your program till you achieve your results. as we seen earlier about PID ,, Now you would have understand how you can tune your PID functions, it is exactly like the one we did it here, where we can use PID blocks get the data to run, check on the monitor for error and fine tune our program it, how easily I said, I know the feel :P

4. Automatic Light Control 

In the previous tutorial you have learned how to acquire analog sensor and control an LED , we going to follow the same set of rules, the blocks are going to be same for this tutorial but , instead of Potentiometer we going to use LDR ( light dependent resistor) from name you can identify the function of this sensor, it resistance depend upon light, what happen if the resistance increase or decrease?? it will affect the output of the resistance, in the previous case we have control over the knob of the potentiometer we made to turn and turn and had control over it, the same thing this LDR is depend on LIGHT to control it , but we can allow and block the light to the sensor :P, so you need a potentiometer to make this tutorial work for you , other than potentiometer you would have know what I usually use :D, yeah that's the device you need. 




Now you know how to do that magic light, continue this tutorial and develop a real circuit to turn On and Off AC circuit, learn more about this stuff, you can easily adapt this same code to control on the hardware side instead of this lazy LED use a rugged relay he can do the rest of job for you. A relay is a electromechanical switch that's all I can say here, Google it learn learn never stop it. 

5. Temperature Monitor using LM35  Temperature sensor

In this chapter we are not using anything like LED's, happy now, yeah I know you guys would have happy after a 4 long tutorials we have eliminated the LED's from our way. what is this LM35 sensor, It is a temperature sensor , the only reason I am using this guy , He's very cheap I bought this sensor just under 50 cent. when compare to other sensor in the market this little guy is cheap and reliable, This sensor is exactly uses the same blocks we used for previous tutorials, what's the deal in it how can we use it as Temperature sensor then?? acquire analog data do some math , yeah you got it right there you will get a Temperature data more or less accurate if it's above 0 degree, this sensor can calculate from 0 to 100 degree in centigrade. it has some simple math which you can find in the data sheet, if you never know about data sheet as I always said please google it and find about this guy, you should have a data sheet for all the product you buy, which has all the details about the product and what the product are capable. connect LM35 sensor to Analog pin, drag and drop blocks in simulink, see the results on Matlab window, you can actually use filters to make the temperature sensor to work perfect, try to get hands on it. don't stop with the point that guy says in the video tutorial. 



6. Sound Sensor with Simulink 

So Here comes a tutorial with different name but going to do the same operation, as you would have noticed at this point we have been repeating the same function again and again for different sensor, the point is if the sensor works in same way as the other , we can use it same function, understand we can connect a device like analog or digital to Arduino all the device going to work as same, if you crossed this level, yeah that's the point of this tutorial just want to take you step by step by making clear on what is all about this programming? , if you understand about sensor programming will be fun, and if you understand the grammar of programming, you would know how to speak with boards. 




if you watched this tutorial , yeah I used LED again for making it clear on how to use a sound sensor and how to what is the maximum db level we are getting and how to use this to make a LED to go mad when sound goes high and low. 

7. Let's Go Digital 

Until now we have used analog function and learnt how to acquire data into Matlab from arduino, we have used different sensor like analog, sound sensor, potentiometer and a LDR, as these functions gives analog as output and we have seen how easy it is to work with analog sensor. Now we see how to interface a digital signal to arduino and read it in Matlab simulink. what output we will get when reading a Digital pin , Either a Hight or Low, this what the output of digital devices. 

Lets use a button that is connected to the digital pin of Arduino and program for it in Matlab Simulink and pick and place some blocks to the simulink environment and make the program to work, it is simple as you think, follow the video tutorial to know how to do it. In this video you will find how to acquire digital data and look up on the graph how the signal responds when we click a button, you see how the signal rises and falls, I have also connected a touch button where it's so fun to use it instead of traditional button in this tutorial, you will also learn how to Turn on and off an LED by controlling the push button. 




In the later on tutorials you will know how to use this example and convert it as real time project by replacing the button with sensors. as we have seen we can get only two state from a digital devices if we use a digital sensor it can produce only two possible conditions as output, using this we can make many applications lets check this one after another.

Project 1: Gas leakage Alarm Detector: 

In the last lesson we have seen how to work with digital pin and at the end of the tutorial we have seen how to turn on and off an led with arduino and Matlab simulink, we going to use the same function and same set of process just by changing the sensors. you will know how to interface a gas sensor to Arduino and read its input using Matlab simulink and based upon the sensor output you will process the data and do perform some conditional based decision on the program.

if  the sensor detects gas ( I used mq-07 sensor) you can use any of the LPG gas detector which can work well with this project.when the sensor detects gas it will give high or low as output signal based on your sensor model and manufacturer. when we detect output from a sensor as positive we need to turn on a buzzer. the process is very simple , check the video and witness the output and learn to do a project with this tutorial.



Project 2: Theft alarm

In this project we going to repeat the same thing, you can even skip this video and try to complete this project and later on check whether your program and the guy in the video doing the program are matches. In this project I have used a PIR sensor and a buzzer , you need a PIR sensor to complete this project.



8: How to make a DC motor to work

Motors are always fun to work with, In this tutorial we will see how to control a toy DC motor using an L293D Motor driver, if you want to know more about this, firstly learn about H-bridge and how we can control a motor using H-bridge, if you complete this tutorial then you ready to do a automatic program for a toy car with arduino, understand the function of L293D motor and apply control logic to the Motor driver from Matlab simulink and control a DC toy motor with the help of Arduino.


9. S function 

Until now we have used all the functions that is available in the simulink library, what if you want to create a new function that is not existing in the simulink, many times you may download a library for Arduino to work with new devices the same applies here for the Matlab we cannot expect library for all the functions, we need to create our own libraries, Matlab simulink has the function called S-function to create user defined library and by creating this you can use any device you want to use with Matlab simulink and arduino. you can follow this tutorial to know about all this new thing and how easy it is to do it. 




10. creating S function for 16x2 LCD to work with Arduino in Matlab Simulink. 

In this tutorial you will know how to create a S function to use 16x2 lcd with Matlab and arduino, you going to use the previous tutorial and create a function for LCD and display temperature data to the LCD screen. you going to combine the tutorials you have learnt in the previous chapters for this tutorial.



If you have reached this place, thanks for watching all the tutorials with patience, please leave your feedback for this course, have you enjoyed this course or the guy is not delivering what you expected to finish at this level, if you have any comments about this please leave your comment to the blog or you can leave the comments on YouTube videos, if you sitll want to personally bash me or want to trash me you can email me @ jayakumarmagesh@gmail.com. all the suggestionns and critics are welcome.



2 comments :

  1. Thank you so much for lcd custom function u saved my life.

    ReplyDelete
  2. Excellent work...
    Thank you very much for the effort taken to share your knowledge...

    ReplyDelete