Matlab

Home Automation System using Matlab GUI and Arduino

Home automation system, Overview:

Home Automation System using Matlab GUI and Arduino- I have been making different types of Home automation and industrial automation projects using different types of controller boards including Arduino Uno, Arduino Nano, Arduino Mega, ESP8266, ESP32 WiFi + Bluetooth Module, Raspberry Pi, and PLC. Below is the list of some of my automation projects which I believe will really help you in making intermediate and advanced level Home automation projects.


In this tutorial, we will design a GUI “Graphical User Interface” application in Matlab for controlling different Home appliances like a fan, TV, motor, and lights. You can increase the number of appliances according to your requirement. This project is based on the Matlab and Arduino Uno. First you will need to do some settings before you can send the control commands from the Matlab GUI to the Arduino Uno board. So, if you are using the Arduino and Matlab for the first time then you should read my previous articles on the Matlab.

So, after reading the above articles and after installing the Hardware support package for the Arduino then you are good to go.



Amazon Links:

Arduino Uno

5v relay module

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Circuit diagram of Matlab home automation Project:

Home Automation system using Matlab

The circuit diagram of the Home automation project is pretty simple. As you can see the neutral wire is connected with all the devices. While the 110/220Vac phase wire is connected with the Common contact of all the relays. The relay is a mechanical switch which we will use to connect and disconnect the Live wire.

  • Connect the digital pin 1 of the Arduino with the signal pin of the relay module and connect the normally open of the relay module with the fan.
  • Connect the digital pin 2 of the Arduino with the signal pin of the relay module 2 and connect the normally open of the relay module with the light.
  • Connect the digital pin 3 of the Arduino with the signal pin of the relay module 3 and connect the normally open of the relay module with the TV.
  • Connect the vcc of all three relay module with the 5V and connect the ground of the relay module with the ground of the Arduino.

You can also use a 12V relay module for which you will need 12Vdc power supply.

Note: Be very careful while working on such high voltage system because it can be really dangerous. Don’t forget to wear protective gloves.


Matlab GUI Design for Home Automation:

In order to make the Matlab GUI application, we will write guide in the command window in the MATLAB.

Home Automation system using Matlab

When we will press enter the GUI platform will open.

First of all we will insert a panel by clicking on the panel icon:

Home Automation system using Matlab

Then we will change the color of the panel and also change the title. In order to change the color double click on the panel, a dialog box will open. Now click on the background color and select the color.

Home Automation system using Matlab

Now will need several buttons for ON and OFF for various appliances such as:

  • FAN ON and FAN OFF
  • LIGHT ON and LIGHT OFF
  • TV ON and TV OFF
  • ALL ON and ALL OFF


When we will press the FAN ON, the fan will turn ON and when we will press on the FAN OFF the fan will turn OFF and so on.

Home Automation system using Matlab

After adding these Push Buttons, the next step is to change the tag for each button and we will also need to change the title of the button. For example, for the FAN ON, we will change the title of the pushbutton to FAN ON and tag to FANON. So, you will need to repeat this for all the buttons.

Home Automation system using Matlab

Now as our project GUI is complete now we will save the project. After saving the project. the code will automatically open.

Home Automation system using Matlab



Matlab Home Automation code:

First of all in the main function we will declare a variable which will get the value of the Arduino port. We declare the “a” variable as a global which means that it is accessible to all functions and the clear all function will clear all the previous values.

Now for each button we will write the code:

Fan button function:

When we click the fan on button the following function will be called:

Now in this function we will make digital pin 1 of the Arduino “1” which means that it will turn on the fan.

Now when we will click the off button then we will write 0 to the digital pin 1 which will make the fan turn off.


Light button function:

Similarly we have connected light to digital pin 2 of the Arduino. when we will click the light button on the lighton function will be called in which we have make the digital pin high due to which the light will be turn on.

when we will click the light off button it will make the digital pin 2 low due to which the light will be turn off.

TV button function:

Similarly for the TV button on function will make the digital pin 3 high due to which the TV will be turned on.

When we will click the tv off button the tv will be turned off.

ALL turn on and off function:

Now if we want to turn on all the appliances together we will click on the all turn on it will make all the digital pins high and all the appliances will be turned on.

Similarly, when we will click on all off, all the digital pins will be low and all the appliances will turn off.


Matlab GUI Home Automation, Complete code:



Now our project is completed and now we can click on the Run button, the MATLABE GUI will automatically get connected with the Arduino.  

Home Automation system using Matlab

Home Automation system using Matlab

Now, all you need is to press the desired buttons to turn ON or turn OFF any electrical load. If you face any problems in executing the code, then I highly recommend you should read my previous articles on the Arduino and Matlab, links I have already shared above.

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button