Wednesday, February 10, 2016

Blink an LED using Arduino and Matlab Simulink

If you are looking to make your arduino talk wiith Matlab, usually this is done by serial communication between Matlab and arduino, where we separately write program for Matlab and arduino, we pass data from and process in Matlab, but you don't need to do such things any more, Matlab developed a software for interfacing low cost hardware like arduino, Beaglebone black, Raspberry pi etc.,   You can use any of the arduino hardware with Matlab, try to use Arduino Mega or Due, the most popular Arduino boards lack of memory and process will slow down when program from simulink. to follow this tutorial you need to install arduino support package to continue this tutorial, you can check my other blog post on how to install support for arduino in Matalb. you can do many interactive project using matlab and arduino. 


here is a tutorial to show you how to program Arduino from Matlab simulink, a powerful graphical programming language which is used in industries. In this tutorial you will learn about how to blink an LED using Arduino and programming from Matlab Simulink. before starting this tutorial check out the introduction section to know about what are the needs to get started with this tutorial and how to install the software and hardware requirements.






Check the video below to know how to control an LED by using Matlab, if you are not sure about how to install the Hardware support for arduino in Matlab check the tutorial here


Steps to make the LED blink

Connect your LED to the 3rd Pin or any other pin you would like and connect your Arduino to your Laptop or PC

Start your Matlab
Click on the Simulink Library.

Once the library browser opened click on the New model from the simulink library.


after the new model window open save your new model by giving any name you like and click on the Simulink support Package for Arduino Hardware from the Simulink library Browser



Open the Common box in the library and choose Digital Output block , drag and drop the digital output block in the model window.



Double click on the Digital Output block and change the pin number to whatever pin number the LED has connected in this case I have connected my LED to the 3rd pin of Arduino Mega



after completing the above steps, got the library browser and select sources from the browser, after opening the sources blocks click the signal generator block and drag it to model window and connect the signal generator to the digital output block by pointing the arrow towards the digital output from signal generator.



Double click on the Pulse generator change the Time(t) to pulse type to sample based.



and also change the sample time to 0.01 and click OK to close the pulse generator parameters.



Change it to external connector and also the simulation time to infinite.





click the tools and select run on target and choose prepare to run. once the window opens click on the Enable hardware specification and from the Hardware board select Arduino Mega



choose the board and click ok, once you pressed ok it will move to the device details don't change any parameters leave everything as same and click ok.


click the run button to temporarily run your code on Arduino which allow us to verify the program if you are not satisfied with the result you can go and change the code until get the desired results and if the program is perfect you can permanently deploy the code by just pressing the deploy to hardware button available in the Model window.



Course on Interfacing Arduino and LabVIEW

Its been a long time I have made a video course on How to use arduino with LabVIEW , This video tutorial is more sufficient for anyone to get started with arduino and LabVIEW and start building their own projects using Arduino with LabVIEW, few years ago if anyone want's to make project using LabVIEW it's really hard for them using a low cost hardware like arduino, and also there is no plenty of resource or dedicated toolkit to work with arduino, but now the situation is different anyone can make their own projects in no time using arduino and LabVIEW, using arduino you can acquire physical world data to your LabVIEW and process all the functions with that, where you can use arduino as a data acquisition tool.



Arduino LabVIEW Linx,

To use Arduino with LabVIEW you need to have installed the toolkit called Linx in with your existing LabVIEW software to get your arduino speak with LabVIEW, you can find all the tutorial on how to install linx toolkit and what are the other requirements that you need to carry out to complete this video course on interfacing labview with arduino. LabVIEW uses serial communication to talk with arduino, you need to have Ni-Visa software to be installed with your LabVIEW, Ni-visa is responsible for connecting all the hardware to talk with LabVIEW. 

I have used a kit called Seeedstudio lotus for making this video, which is very easy to use for a new user getting started with arduino, Lotus is a arduino clone, you can use any type of arduino which supports by Linx, I recommend to anyone to start with Arduino Uno as it is more popular hardware in the Arduino family. 

You can also follow the book which also have all the tutorials given below as a step by step instruction and all the codes and necessary files that have done in this video tutorial are also given in the book, if you wish to buy it just give it a shot, but you don't need to have this book to complete this video tutorial, when you buy this book, it gives me a $1.8 which helps me to buy more hardware and experiment on new things. you can use Arduino Mega or Arduino Nano with this tutorial and start playing with LabVIEW, you can use your own custom hardware too, don't stop your experience learn always something new, add this one course to you that you something now.

click here to move to amazon to by this book

Introduction to the course in here you will get to know about what are things you needed to get started with this course, all the necessary things , in the introduction video you can find how to run your first example "LED blinking with labview and arduino" , it is really awesome to create a Graphical User Interface and play with arduino using LabVIEW, you don't need any prior experience to get yourself start for this tutorial,

For the below tutorial you need to have a Arduino board with Led to blink and a usb cable to connect to your computer, make sure you installing necessary software to make this thing happen in reality. don't stop with theory or video, get your hands on practice and learn something out of it. even if you fail to do, it is a experience that we gaining from instead of without practising.

Chapter 1: How to interface Arduino with LabVIEW and to blink an LED short and sweet video get you through start to finish and at the end you would have understand how easy is to do it, LabVIEW uses G-programming which is a drag and drop boxes and connecting it together and programming, you will become familiar with these things once get started, 



Chapter 2 How to acquire analog signal into LabVIEW from Arduino

As you might be aware that LabVIEW is mostly used for acquiring signals from external devices and process on it, there are many hardware that are available with NI , but the thing is, it is so costly and cannot afford by many people, Arduino can be replace those devices in acquiring and performing on signals in low level, we cannot compare Arduino to NI hardware those hardware are beast and workhorse.
In this video you will learn how to acquire analog signal and process on it using LabVIEW, analog signals are more useful and easy to read than digital , Sensors which gives different output based on its acting environment give analog output, when we read the signal into LabVIEW it varies from 0 to 5v based upon this level we can know the strength of the OUTPUT and we can do many things with this type of signal.

You need a Potentiometer or variable resistor to complete this tutorial, if possible check out google on how this potentiometer works and how it can vary the applied voltage when we rotating it, what is the principle behind it.



Chapter 3, How to control a PWM of an LED using Arduino and LabVIEW

In the previous video you would have learned about how to work with an LED and how to work with analog devices, in this tutorial you will know how to use the last tutorial and combined these tutorial together to work on this tutorial. PWM is the pulse width modulation , it will entire post if we start to talk about this PWM, in simple words lets control the brightness of an LED by controlling the voltage applied to the digital pin, you can use PWM to work with many realtime application most often in electronics to work with PWM we all will be introduced to control brightness of an LED at the initial stage.. 

You need the components that you used in the previous chapter to complete this tutorial 


Chapter 4, Automatic Light Controller using LDR

back in the days, you might be wonder how a light automatically turn off or on based upon the light intensity, later on you would have understand how it works and what basically makes this thing to get work, you still could see a wall clock which strike every hour and stops in the night time or its volume getting decreased based upon the intensity of lights. The reason behind all this work is a tiny little component known as LDR (light dependent resistor) in the last lessons we have controlled the LED brightness by manually turning the knob of the potentiometer, we have a force on those potentiometer to set its value, just like that this LDR being controlled by the external light, its resistance will shoot up if the light intensity is low or it may go up based on the type of resistor material and manufacturing process.

you need a LDR and LED's to make this tutorial work for you, meanwhile if you how to work with relay you can interface relay to it and control your AC lights and fans to automatically turn on and off with light as an factor..



Chapter 5, How to read digital Input

until now in all these tutorials we have only used digital pins as an output to turn on and off or control some LED's , what if you want to read a digital pin, this is a simple task in LabVIEW, we can easily know the state of a pin just by calling a block to read digital pin and selecting the pin to read.

What's the deal in it and why we should read a digital pin, we usually use this feature to know the input from other devices, we use button as a input device and attach with arduino can be useful to know how this function works, we can use these digital input to understand interrupt and also many feature can be done using this digital input button.

You need a button and a LED to complete this tutorial.

Chapter 6 How to work with accelerometer 

In this video tutorial you will know how to acquire accelerometer data and plot a graph upon it, it is really a piece of cake when you using I2C devices with linx and labview they have all the functions to make it work. Try to learn more about i2c protocol how this devices works, you can connect upto 128 i2c devices arduino., what allows this possible? who made this protocol? how fast as this device respond? what is the difference between i2c and spi? if you are getting questions like this then you are learning, google and get your feet under it to check answer for all the stupid questions that came to my mind when started with i2c.

what you need ? an adxl accelerometer and an arduino to make this work


Chapter 7, Servo motor with LabVIEW and Arduino 

it is always fun to work this little guys as they respond quickly and also eats lot of power these tiny guys have more muscle power than the ordinary motors, if you are more curious please try to make a toy car out of a tower pro 9g servo and a toy motor (plane motor without gear), you toy motor never move the car an inch, just find the reason for it? if you learn about it, things will become quite interesting later on. give it a try.

you need a servo motor and Arduino and you should connected your arduino with external power, power supplied from your computer through USB will not be sufficient enough to drive this crazy power hungry fellows.



Chapter 8, working with AC appliances 

In the earlier chapter we have already talked about relay and what you can do about it? are we? not at all but there is a hint on relay given in the previous chapter , hope you learn about it?

if you completed learning about relay and more important if you know more about AC circuit and its operation go ahead on this project. arduino and labVIEW don't have direct control over your AC appliance , this video is just like turn on and off an LED but what make possible to control a AC light or fan is the relay , he is the hero for this tutorial, make sure you learnt all that and take necessary precaution before trying this tutorial.


Check my YouTube channel for more video tutorial like this , pass on your comments and suggestions and where we can improve it, @ jayakumarmagesh@gmail.com , don't foreget to subscribe to my YouTube channel and if you like or hate this video go and bash in YouTube comment section and leave your comments. Thank you reaching this point as I am happy to help someone out there

Limitation of this video tutorial: as this tutorial is more focussed on beginners many concepts were not explored in the future you can expect videos on how to add custom command and how to add more sensor supports to these videos, and also learn about more frequency interfaced devices like DHT11, DHT22, DHT23, DHT33, with arduino and labview, there is also a support will be added to one wire and other features, if you want to use an LCD screen with Arduino and Labview you can use an I2C LCD which is supported well. 

Tuesday, December 1, 2015

Introduction to Matlab Simulink and Arduino

We can use MATLAB to communicate with an Arduino board using installing the support package for Arduino in MATLAB. If you want to program an Arduino that can  be possible by using Simulink and support package for Arduino should be installed in order to use MATLAB Simulink to program our Arduino boards. The support package wills automatically generate the code from Simulink model that then runs on the arduino board. 



check the above video to know about what is video is series is about , what all you can learn from this video series. 



check the above Video know how to install the support package for Arduino for Matlab where you will be given a details about how to start and where to start, all the information need to get install the package successful has been shown in the above video. 


Set up MATLAB and Simulink support package for Arduino

Start MATLAB
Open MATLAB and click the Add-Ons drop down menu on the top right


Start Support Package Installer
Click on Get Hardware Support Packages in the drop down menu to start the installer. Select
'Install from Internet' as the source for installing the support package





Select Arduino from a list of support packages
Click Next to see a list of support packages and select Arduino from the list for MATLAB Support
Package and Arduino Due for the Simulink Support Package.




MathWorks Account
Click next and log in to your MathWorks account. If you don't have a MathWorks account, you can
create one during the install process



Continue and Complete the Installation
Accept the license agreement on the next screen and click Next through the following screens to
finish the installation for both MATLAB and Simulink Support Package for Arduino.







Sunday, May 31, 2015

Export Temperature data to Thingspeak using ESP8266 and DHT11

Hi all , If you want to make a simple and less cost IOT (Internet Of Things)  which transfer temperature and humidity data to a website and stores your real time data for monitoring , then this post will full fill all your requirement.

All you need for this project is a esp8266 esp-12 WiFi module and a DHT11 temperature and humidity sensor, no need for arduino or any other microcontroller to support this WiFi module for this project , esp8266 esp-12 can work standalone without using a microcontroller to support it.


Step by Step instruction to make this work is explained in the video below:







How to upload nodemcu firmware and other details can be find in the link here

1) Register in Thingspeak.com and create a new channel with 2 fields namely, Temperature and humidity.

2) download the lua program here

3) connect dht11 to the gpio2 of the esp8266 WiFi module.

4) connect esp8266 to your PC

5) extract dht11.rar file that downloaded

6) Open the downloaded file in the Esplorer window

7) Copy the Write key provided from the thingspeak and paste into the dht11.lua program (refer to the video if you are not sure about this)

8) Edit your Wifi SSID and password in the Init.lua Program.

9) Firslty save the dht11.lua to the esp8266 , Secondly save the Init.lua file to the WiFi module.

10) you can check the program successfully uploaded in the esplorer window, once it connected to your Home WiFi network, you can see the IP address assigned to the WiFi module, and you can also see the current temperature and humidity in the Esplorer window.

11) check your channel in the thingspeak.com, you can see the real-time data from your WiFi moudle.





Monday, May 11, 2015

Automating CD Driver Stepper Motor Using IR Sensor





Take a look at this video you know what is project is all about.



I had a CD driver which has not been used for a very long time with me, I removed the case and opened the lens carriage, I thought of using it for a portable plotter before going for the exact idea I wanted to operate the motor automatically with IR sensors , that's how this project was started. It was so much of fun doing this, where you can easily do this project less than $10 if you have arduino with you.



I started it by removing the upper case of the CD driver, which is really easy to do, in the bottom of the driver it had some 4 screws to remove, you don't need to be a professional for doing this kind of job, anyone can do it. 




This lens carriage is the only part that required for this project, apart from this lens carriage there are also a CD Open and closer mechanism and a motor also present inside this CD driver which I can use for some other project. 


If possible remove the stepper motor from the lens carriage, which would allow us to easily solder the stepper motor, or you can also solder without removing it. 



connect the stepper motor to the L293d Motor driver , complete the circuit with the help of the above fritzing .

Arduino Program: 
// I have modified the stepper one revolution program, you can also write your own version for this, programming a stepper with arduino is really easy with the available library, If you are using this project Easy stepper driver Please note this program will not work for it, you need modification for it, please leave a comment , I can also upload the program for easy drive if you really need it.


------------------------------------------------------------------------------------------------------------------------------
#include <Stepper.h>

int motor = 1;

const int stepsPerRevolution = 180;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  int sensor1 = digitalRead(2);
  int sensor2 = digitalRead(3);
  
  if(sensor1 == HIGH && sensor2 == LOW){
    motor = 1;
  }
  
  if (sensor1 == LOW && sensor2 == HIGH){
   motor = 2;}
  
   
    if(motor ==1){
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(5);
  }
  // step one revolution in the other direction:
  else
{
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(5);}
}

--------------------------------------------------------------------------------------------------------------------------------

alternatively you can download the same program here

You can also make your own IR sensor following the video below: 


IR sensors are easily available in all the online electronics and hobbyist shops, you can also make your own IR sensor with just a dollar. 

Sunday, May 10, 2015

Temperature Indicator using LM35, Arduino and display temperature using LCD 16x2


Temperature Indicator is a simple easy to do project, which I did it in less than 10 minutes, If you want to build your own temperature display for your home, you can choose this project, or you can use this project to submit in your school too, to get some extra credit. 

What are the components Used :
1.Arduino
2.LM35 (temperate sensor) very less cost compare to any other temperature sensor
3.LCD 16x2 
4.10k Pot , breadboard and connecting wires.


You can check the above video to know How this circuit works


Arduino Program:

-----------------------------------------------------------------------------------------------------------------------------

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Tempsensor = A0;


void setup() {
  lcd.begin(16, 2);
  pinMode(5, OUTPUT);
}

void loop() {
  
  float temp = analogRead(Tempsensor);
  temp = temp * 0.48828125; // (5*1000)/1024 = 0.48828125
  delay(100);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Temperature");
  lcd.setCursor(0, 1);
  lcd.print(temp);
  lcd.print((char)223); // degree symbol for displaying temperature in arduino LCD
  lcd.print("C");
  delay(200);
}

-----------------------------------------------------------------------------------------------------------------------------


LM35 Pin diagram



Wednesday, May 6, 2015

Automatic Water level controller with Level display on LCD





previously I made an automatic water level controller , you can check this link here, Please check the link which I have given to know more about the detail of this project. This is an upgrade version to the previous one, I've added an LCD display to the project to display the water level.

Arduino Code:

/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Echo to Arduino pin 9 
 Trig to Arduino pin 8*/
 /* LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)*/

#include<LiquidCrystal.h> // include the library code for lcd
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //  
#define echopin  9 // echo pin
#define trigpin 8 // Trigger pin

int maximumRange = 50;
long duration, distance;

void setup() {
  lcd.begin(16,2);
  Serial.begin (9600);
  pinMode (trigpin, OUTPUT);
  pinMode (echopin, INPUT );
  pinMode (4, OUTPUT);
  pinMode (13,OUTPUT);
}
  
void loop ()
{
  {
    digitalWrite(trigpin,LOW);
    delayMicroseconds(2);
    
    digitalWrite(trigpin,HIGH);
    delayMicroseconds(10);
    
    duration=pulseIn (echopin,HIGH);
    
    distance= duration/58.2;
    delay (50);
    Serial.println(distance);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("water level :");
    lcd.print(distance);
    delay(100);
    
  }
  
 if (distance >= 25 ){
   digitalWrite (7,HIGH);// connect to relay(motor)
   digitalWrite (13,HIGH);
   lcd.setCursor(0,1);
   lcd.print("Motor Started");
   delay(100);
 }

 else if (distance <=5) {
   digitalWrite (7,LOW); // connect to relay(motor)
   digitalWrite (13,LOW);
   lcd.setCursor(0,1);
   lcd.print("Tank is full");
   delay(100);
   
 }

}

----------------------------------------------------------------------------------------------------------------------------

Arduino file can be downloaded from this link here