Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Thursday, 27 February 2014

How to send emails from Matlab

Hey Everyone !

In this blog i'm going to teach you how to send emails from MATLAB.

Its very Easy..Just one command will do the trick for you..
sendmail('meetleopauly@yahoo.com', 'Gmail Test', 'This is a test message.');

The syntax is as follows :
sendmail('your address', 'title', 'your message.');

But you need to do a lil bit of preference changes before you use this command.

myaddress = 'mail address';    % give the address from which you need to send the mail from
mypassword = 'password';    % give your password

setpref('Internet','E_mail',myaddress);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password',mypassword);

props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
                  'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');

Just copy the above code.Run it and use the send mail command.

Here what we have done is we have used one of the google's silent features the  portable SMTP server.You can read more about Google's SMTP server Here .

So friends try this out...Have fun :-)



Saturday, 29 September 2012

BLINKING LED WITH ARDUINO USING MATLAB



               

Arduino is a commonly used open source single-board microcontroller.And matlab is the  language of technical computing. Here i illustrate how to control a led using matlab through arduino...

STEPS:
     1.  Connect your arduino board to the PC.
     2.   Attach an Led to the PIN 2 of the arduino. 
     3. Use the following codes in arduino and matlab.

PROGRAM CODE:

Code For arduino:

//this is a simple progam that blinks the LED in pin 2 if the transmitted  char is ‘a’ else just turns on the LED.
int led = 2;
int s;
void setup()
{   Serial.begin(9600);            
    pinMode(led, OUTPUT);    
}

void loop()
{  if(Serial.available()>0)           
   { s=Serial.read();
   }
   if(s=='a')
      {while(1)
{
     digitalWrite(led, HIGH);  
     delay(1000);
      digitalWrite(led, LOW);   
      delay(1000);}}      
  else
     {
     digitalWrite(led, HIGH);  
     delay(1000);}
        
}


Code For matlab:

 >>instrhwinfo('serial')                     //check which  port is available for serial communication
ans =
     AvailableSerialPorts: {0x1 cell}
       JarFileVersion: 'Version 2.8.0'
    ObjectConstructorName: {'serial('COM6');'}
         SerialPorts: {'COM6'}

obj=serial('com6');                       //creates a serial object
>> fopen(obj)                             //opens serial object
>> fprintf(obj,'a')                       // writes char ‘a’ to the  serial port
>> fclose(obj)                              //closes the obj

OUTPUT
The led will first glow continuously,but once you run the code in matlab it will start blinking.....

REMARK:
this is a simple pgm.just try it out friends...........:-)