{"id":4750,"date":"2013-08-09T09:00:05","date_gmt":"2013-08-09T13:00:05","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4750"},"modified":"2019-02-01T09:47:28","modified_gmt":"2019-02-01T14:47:28","slug":"reading-from-sensors-on-your-mobile-phone","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/08\/09\/reading-from-sensors-on-your-mobile-phone\/","title":{"rendered":"Reading from sensors on your mobile phone"},"content":{"rendered":"<div class=\"content\"><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s picks this week are <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40876-android-sensor-support-from-matlab--r2013a--r2013b-\">Android Sensor support<\/a> and iPhone and iPad Sensor support by the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/331522\">MathWorks Mobile Sensor Connectivity Team<\/a>.<\/p><p>If you own a smart phone, you're probably holding a device with a number of sensors that is constantly collecting information from its surroundings. Many of the apps on your phone make use of these various sensors to operate. Now, you can read from your phone's sensors using MATLAB! If you have R2013a or newer and an Android phone or an iPhone\/iPad, you will want to check this out.<\/p><p>After installing a free app for your <a title=\"https:\/\/play.google.com\/store\/apps\/details?id=jp.ac.ehime_u.cite.sasaki.SensorUdp&amp;feature=nav_result (link no longer works)\">Android<\/a> or <a href=\"\">iPhone\/iPad<\/a>, you can now receive sensor data from you phone directly into your MATLAB session. It is written using <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/object-oriented-programming.html\">MATLAB Classes<\/a>, and it has a simple interface to read sensor data from your phone.<\/p><p>Establish connection with your phone:<\/p><pre class=\"codeinput\">sensor = sensorgroup(<span class=\"string\">'AndroidMobile'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">sensor = \r\nsensorgroup logging data from Android device on port 60000\r\n\r\n  Measurements: (showLatestValues)\r\n\r\n    Acceleration                        Orientation\r\n\r\n    Latitude                            Speed\r\n    Longitude\r\n    Altitude                            MagneticField\r\n<\/pre><p>Read the latest values from the sensors:<\/p><pre class=\"codeinput\">showLatestValues(sensor)\r\n<\/pre><pre class=\"codeoutput\">\r\nMeasurement              Latest Values              Units   Log Size\r\n-------------  ----------------------------------  -------  --------\r\nAcceleration         4.51       -3.30       -8.16  m\/s^2    &lt;1x3&gt;\r\nMagneticField   -3.56e-06   -2.49e-05    1.11e-05  Tesla    &lt;2x3&gt;\r\nOrientation         27.08       27.14      -19.39  degrees  &lt;2x3&gt;\r\n\r\nWaiting for: Latitude, Longitude, Altitude, and Speed.  More information.\r\n\r\n<\/pre><p>Get specific measurements:<\/p><pre class=\"codeinput\">sensor.Orientation\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n   20.6081   34.4375  -15.0781\r\n<\/pre><p>The entry also comes with a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/creating_guis\/apps-overview.html\">MATLAB app<\/a> that shows a live view of the data coming in, as well as an example of using the magnetic field information from the phone to rotate a 3D plot.<\/p><p>\r\n        <div id=\"media\">\r\n            <object id=\"csSWF\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"600\" height=\"468\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,115,0\">\r\n                <param name=\"src\" value=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/AndroidSensorAction_controller.swf\"\/>\r\n                <param name=\"bgcolor\" value=\"#1a1a1a\"\/>\r\n                <param name=\"quality\" value=\"best\"\/>\r\n                <param name=\"allowScriptAccess\" value=\"always\"\/>\r\n                <param name=\"allowFullScreen\" value=\"true\"\/>\r\n                <param name=\"scale\" value=\"showall\"\/>\r\n                <param name=\"flashVars\" value=\"autostart=false#&thumb=https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/FirstFrame.png&thumbscale=45&color=0x1A1A1A,0x1A1A1A\"\/>\r\n                <embed name=\"csSWF\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/AndroidSensorAction_controller.swf\" width=\"600\" height=\"468\" bgcolor=\"#1a1a1a\" quality=\"best\" allowScriptAccess=\"always\" allowFullScreen=\"true\" scale=\"showall\" flashVars=\"autostart=false&thumb=https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/FirstFrame.png&thumbscale=45&color=0x1A1A1A,0x1A1A1A\" pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\"><\/embed>\r\n            <\/object>\r\n        <\/div>\r\n<\/p><p>Learn more about these mobile supports from <a href=\"https:\/\/www.mathworks.com\/hardware-support\/android-sensor.html\">this page<\/a> for Android and <a href=\"https:\/\/www.mathworks.com\/hardware-support\/iphone-sensor.html\">this page<\/a> for iPhone\/iPad.<\/p><p><b>Comments<\/b><\/p><p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4750#respond\">Tell us<\/a> about your applications using your mobile devices and MATLAB or leave a comment for the MathWorks Mobile Sensor Connectivity Team.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_c2843d6bcccf4ccdb73dd41eafc5ad06() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='c2843d6bcccf4ccdb73dd41eafc5ad06 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' c2843d6bcccf4ccdb73dd41eafc5ad06';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_c2843d6bcccf4ccdb73dd41eafc5ad06()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013a<br><\/p><\/div><!--\r\nc2843d6bcccf4ccdb73dd41eafc5ad06 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s picks this week are\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40876-android-sensor-support-from-matlab--r2013a--r2013b- Android Sensor\r\n% support> and <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/40858\r\n% iPhone and iPad Sensor support> by the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/331522\r\n% MathWorks Mobile Sensor Connectivity Team>.\r\n%\r\n% If you own a smart phone, you're probably holding a device with a number\r\n% of sensors that is constantly collecting information from its\r\n% surroundings. Many of the apps on your phone make use of these various\r\n% sensors to operate. Now, you can read from your phone's sensors using\r\n% MATLAB! If you have R2013a or newer and an Android phone or an\r\n% iPhone\/iPad, you will want to check this out.\r\n%\r\n% After installing a free app for your\r\n% <https:\/\/play.google.com\/store\/apps\/details?id=jp.ac.ehime_u.cite.sasaki.SensorUdp&feature=nav_result\r\n% Android> or\r\n% <\r\n% iPhone\/iPad>, you can now receive sensor data from you phone directly\r\n% into your MATLAB session. It is written using\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/object-oriented-programming.html\r\n% MATLAB Classes>, and it has a simple interface to read sensor data from\r\n% your phone.\r\n%\r\n% Establish connection with your phone:\r\n\r\nsensor = sensorgroup('AndroidMobile')\r\n\r\n%%\r\n% Read the latest values from the sensors:\r\n\r\nshowLatestValues(sensor)\r\n\r\n%%\r\n% Get specific measurements:\r\n\r\nsensor.Orientation\r\n\r\n%%\r\n% The entry also comes with a\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/creating_guis\/apps-overview.html\r\n% MATLAB app> that shows a live view of the data coming in, as well as an\r\n% example of using the magnetic field information from the phone to rotate\r\n% a 3D plot.\r\n%\r\n% <html>\r\n%         <div id=\"media\">\r\n%             <object id=\"csSWF\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"600\" height=\"468\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=9,0,115,0\">\r\n%                 <param name=\"src\" value=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/AndroidSensorAction_controller.swf\"\/>\r\n%                 <param name=\"bgcolor\" value=\"#1a1a1a\"\/>\r\n%                 <param name=\"quality\" value=\"best\"\/>\r\n%                 <param name=\"allowScriptAccess\" value=\"always\"\/>\r\n%                 <param name=\"allowFullScreen\" value=\"true\"\/>\r\n%                 <param name=\"scale\" value=\"showall\"\/>\r\n%                 <param name=\"flashVars\" value=\"autostart=false#&thumb=https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/FirstFrame.png&thumbscale=45&color=0x1A1A1A,0x1A1A1A\"\/>\r\n%                 <embed name=\"csSWF\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/AndroidSensorAction_controller.swf\" width=\"600\" height=\"468\" bgcolor=\"#1a1a1a\" quality=\"best\" allowScriptAccess=\"always\" allowFullScreen=\"true\" scale=\"showall\" flashVars=\"autostart=false&thumb=https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_MobilePhoneSensors\/FirstFrame.png&thumbscale=45&color=0x1A1A1A,0x1A1A1A\" pluginspage=\"http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash\"><\/embed>\r\n%             <\/object>\r\n%         <\/div>\r\n% <\/html>\r\n%\r\n% Learn more about these mobile supports from\r\n% <https:\/\/www.mathworks.com\/hardware-support\/android-sensor.html this page>\r\n% for Android and\r\n% <https:\/\/www.mathworks.com\/hardware-support\/iphone-sensor.html this page>\r\n% for iPhone\/iPad.\r\n%\r\n% *Comments*\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4750#respond Tell us> about your\r\n% applications using your mobile devices and MATLAB or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/contact\/331522\r\n% comment> for the MathWorks Mobile Sensor Connectivity Team.\r\n\r\n##### SOURCE END ##### c2843d6bcccf4ccdb73dd41eafc5ad06\r\n-->","protected":false},"excerpt":{"rendered":"<p>Jiro's picks this week are Android Sensor support and iPhone and iPad Sensor support by the MathWorks Mobile Sensor Connectivity Team.If you own a smart phone, you're probably holding a device with a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/08\/09\/reading-from-sensors-on-your-mobile-phone\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4750"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4750"}],"version-history":[{"count":14,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4750\/revisions"}],"predecessor-version":[{"id":10492,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4750\/revisions\/10492"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}